Skip to content

Commit

Permalink
Release 2.19.11 (#2411)
Browse files Browse the repository at this point in the history
2.19.11 (2022-12-08)
Bug fixes

    [ #2409 ] Ensure alias is being deleted when removing a collection (alexandrebouthinon)

Enhancements

    [ #2407 ] Add pipes to alter payload parsing at protocol level (Shiranuit)


Co-authored-by: Shiranuit <[email protected]>
  • Loading branch information
alexandrebouthinon and Shiranuit authored Dec 8, 2022
1 parent d9bc9fe commit cfa0c75
Show file tree
Hide file tree
Showing 16 changed files with 10,985 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .ci/scripts/run-monkey-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ echo "Testing Kuzzle against node v$NODE_VERSION"
echo "Installing dependencies..."
npm install --unsafe-perm

if [ "$REBUILD" == "true" ];
then
docker-compose -f ./.ci/test-cluster.yml run kuzzle_node_1 npm rebuild
fi

npm run build-ts

echo "[$(date)] - Starting Kuzzle Cluster..."
Expand Down
2 changes: 1 addition & 1 deletion .ci/scripts/run-test-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm install

if [ "$REBUILD" == "true" ];
then
npm rebuild
docker-compose -f ./.ci/test-cluster.yml run kuzzle_node_1 npm rebuild
fi

npm run build-ts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow-deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# -----------------------------------------------------------------------------
doc-deploy:
name: Documentation - Deploy
if: ${{ github.event_name != 'workflow_dispatch' || inputs.doc_deploy }}
if: ${{ (github.event_name != 'workflow_dispatch' || inputs.doc_deploy) && (github.ref_name == 'master' || github.ref_name == '2-dev') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ jobs:
with:
test-set: test:functional:${{ matrix.test_set }}
node-version: ${{ matrix.node-version }}
env:
REBUILD: "true"

cluster-monkey-tests:
name: Cluster Monkey Tests
Expand All @@ -192,6 +194,8 @@ jobs:
- uses: ./.github/actions/monkey-tests
with:
node-version: ${{ matrix.node-version }}
env:
REBUILD: "true"

deploy-workflow:
name: Deployment Workflow
Expand Down
37 changes: 30 additions & 7 deletions lib/core/network/protocols/httpwsProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class HttpWsProtocol extends Protocol {
this.socketByConnectionId.delete(connection.id);
}

wsOnMessageHandler(socket, data) {
async wsOnMessageHandler(socket, data) {
if (!data || data.byteLength === 0) {
return;
}
Expand All @@ -347,12 +347,20 @@ class HttpWsProtocol extends Protocol {
}

let parsed;
const message = Buffer.from(data).toString();
let message = Buffer.from(data).toString();

debugWS("[%s] client message: %s", connection.id, message);

({ payload: message } = await global.kuzzle.pipe(
"protocol:websocket:beforeParsingPayload",
{ connection, payload: message }
));

try {
parsed = JSON.parse(message);
({ payload: parsed } = await global.kuzzle.pipe(
"protocol:websocket:afterParsingPayload",
{ connection, payload: JSON.parse(message) }
));
} catch (e) {
/*
we cannot add a "room" information since we need to extract
Expand Down Expand Up @@ -552,14 +560,25 @@ class HttpWsProtocol extends Protocol {
return;
}

this.httpUncompress(message, payload, (err, inflated) => {
let resolve;
let promise = new Promise((res) => (resolve = res));

this.httpUncompress(message, payload, async (err, inflated) => {
if (err) {
cb(err);
resolve();
return;
}

this.httpParseContent(message, inflated, cb);
const { payload: newPayload } = await global.kuzzle.pipe(
"protocol:http:beforeParsingPayload",
{ message, payload: inflated }
);
await this.httpParseContent(message, newPayload, cb);
resolve();
});

return promise;
});

// Beware: the "response" object might be invalidated at any point of time,
Expand All @@ -569,7 +588,7 @@ class HttpWsProtocol extends Protocol {
});
}

httpParseContent(message, content, cb) {
async httpParseContent(message, content, cb) {
const type = message.headers["content-type"] || "";

if (type.includes("multipart/form-data")) {
Expand Down Expand Up @@ -601,7 +620,11 @@ class HttpWsProtocol extends Protocol {
message.content = querystring.parse(content.toString());
} else {
try {
message.content = JSON.parse(content.toString());
const { payload } = await global.kuzzle.pipe(
"protocol:http:afterParsingPayload",
{ message, payload: JSON.parse(content.toString()) }
);
message.content = payload;
} catch (e) {
cb(
kerrorHTTP.get("body_parse_failed", content.toString().slice(0, 50))
Expand Down
16 changes: 16 additions & 0 deletions lib/service/storage/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,12 @@ class ElasticSearch extends Service {
try {
await this._client.indices.delete(esRequest);

if (await this._checkIfAliasExists(this._getAlias(index, collection))) {
await this._client.indices.deleteAlias({
name: this._getAlias(index, collection),
});
}

await this._createHiddenCollection(index);
} catch (e) {
throw this._esWrapper.formatESError(e);
Expand Down Expand Up @@ -2917,6 +2923,16 @@ class ElasticSearch extends Service {
return `${ALIAS_PREFIX}${this._indexPrefix}${index}${NAME_SEPARATOR}${collection}`;
}

/**
* Given an alias name, returns the associated index name.
*/
async _checkIfAliasExists(aliasName) {
const { body } = await this._client.indices.existsAlias({
name: aliasName,
});
return body;
}

/**
* Given index + collection, returns the associated indice name.
* Use this function if ES does not accept aliases in the request. Otherwise use `_getAlias`.
Expand Down
8 changes: 8 additions & 0 deletions lib/types/ClientConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { JSONObject } from "../..";

export interface ClientConnection {
id: string;
protocol: string;
ips: string[];
headers: JSONObject;
}
13 changes: 13 additions & 0 deletions lib/types/HttpMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { JSONObject } from "../..";
import { ClientConnection } from "./ClientConnection";

export interface HttpMessage {
connection: ClientConnection;
content: JSONObject;
ips: string[];
query: string;
path: string;
method: string;
headers: JSONObject;
requestId: string;
}
27 changes: 27 additions & 0 deletions lib/types/events/EventProtocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { JSONObject, PipeEventHandler } from "../../../";
import { ClientConnection } from "../ClientConnection";
import { HttpMessage } from "../HttpMessage";

export type EventHTTPBeforeParsingPayload = {
name: `protocol:http:beforeParsingPayload`;

args: [{ message: HttpMessage; payload: Buffer }];
} & PipeEventHandler;

export type EventHTTPAfterParsingPayload = {
name: `protocol:http:afterParsingPayload`;

args: [{ message: HttpMessage; payload: JSONObject }];
} & PipeEventHandler;

export type EventWebsocketBeforeParsingPayload = {
name: `protocol:websocket:beforeParsingPayload`;

args: [{ connection: ClientConnection; payload: Buffer }];
} & PipeEventHandler;

export type EventWebsocketAfterParsingPayload = {
name: `protocol:websocket:afterParsingPayload`;

args: [{ connection: ClientConnection; payload: JSONObject }];
} & PipeEventHandler;
1 change: 1 addition & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ export * from "./OpenApiDefinition";
export * from "./errors/ErrorDefinition";
export * from "./errors/ErrorDomains";
export * from "./events/EventGenericDocument";
export * from "./events/EventProtocol";
Loading

0 comments on commit cfa0c75

Please sign in to comment.