Improve Live Query Monitoring (#5927)
* Improve Live Query Monitoring * typo
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
cea1988ce9
commit
3ab9dcdfd0
@@ -43,7 +43,7 @@ before_script:
|
|||||||
- greenkeeper-lockfile-update
|
- greenkeeper-lockfile-update
|
||||||
script:
|
script:
|
||||||
- npm run lint
|
- npm run lint
|
||||||
- npm run coverage
|
- npm run pretest && npm run coverage
|
||||||
after_script:
|
after_script:
|
||||||
- greenkeeper-lockfile-upload
|
- greenkeeper-lockfile-upload
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 jasmine",
|
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 jasmine",
|
||||||
"test": "npm run testonly",
|
"test": "npm run testonly",
|
||||||
"posttest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner stop",
|
"posttest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner stop",
|
||||||
"coverage": "npm run pretest && cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 nyc jasmine && npm run posttest",
|
"coverage": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 nyc jasmine",
|
||||||
"start": "node ./bin/parse-server",
|
"start": "node ./bin/parse-server",
|
||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"postinstall": "node -p 'require(\"./postinstall.js\")()'"
|
"postinstall": "node -p 'require(\"./postinstall.js\")()'"
|
||||||
|
|||||||
@@ -293,7 +293,9 @@ describe('ParseLiveQueryServer', function() {
|
|||||||
parseLiveQueryServer._validateKeys = jasmine
|
parseLiveQueryServer._validateKeys = jasmine
|
||||||
.createSpy('validateKeys')
|
.createSpy('validateKeys')
|
||||||
.and.returnValue(true);
|
.and.returnValue(true);
|
||||||
parseLiveQueryServer._handleConnect(parseWebSocket);
|
parseLiveQueryServer._handleConnect(parseWebSocket, {
|
||||||
|
sessionToken: 'token',
|
||||||
|
});
|
||||||
|
|
||||||
const clientKeys = parseLiveQueryServer.clients.keys();
|
const clientKeys = parseLiveQueryServer.clients.keys();
|
||||||
expect(parseLiveQueryServer.clients.size).toBe(1);
|
expect(parseLiveQueryServer.clients.size).toBe(1);
|
||||||
@@ -335,6 +337,7 @@ describe('ParseLiveQueryServer', function() {
|
|||||||
query: query,
|
query: query,
|
||||||
requestId: requestId,
|
requestId: requestId,
|
||||||
sessionToken: 'sessionToken',
|
sessionToken: 'sessionToken',
|
||||||
|
installationId: 'installationId',
|
||||||
};
|
};
|
||||||
parseLiveQueryServer._handleSubscribe(parseWebSocket, request);
|
parseLiveQueryServer._handleSubscribe(parseWebSocket, request);
|
||||||
|
|
||||||
@@ -357,6 +360,7 @@ describe('ParseLiveQueryServer', function() {
|
|||||||
expect(args[0]).toBe(requestId);
|
expect(args[0]).toBe(requestId);
|
||||||
expect(args[1].fields).toBe(query.fields);
|
expect(args[1].fields).toBe(query.fields);
|
||||||
expect(args[1].sessionToken).toBe(request.sessionToken);
|
expect(args[1].sessionToken).toBe(request.sessionToken);
|
||||||
|
expect(args[1].installationId).toBe(request.installationId);
|
||||||
// Make sure we send subscribe response to the client
|
// Make sure we send subscribe response to the client
|
||||||
expect(client.pushSubscribe).toHaveBeenCalledWith(requestId);
|
expect(client.pushSubscribe).toHaveBeenCalledWith(requestId);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Client {
|
|||||||
id: number;
|
id: number;
|
||||||
parseWebSocket: any;
|
parseWebSocket: any;
|
||||||
hasMasterKey: boolean;
|
hasMasterKey: boolean;
|
||||||
|
sessionToken: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
roles: Array<string>;
|
roles: Array<string>;
|
||||||
subscriptionInfos: Object;
|
subscriptionInfos: Object;
|
||||||
@@ -27,10 +28,16 @@ class Client {
|
|||||||
pushDelete: Function;
|
pushDelete: Function;
|
||||||
pushLeave: Function;
|
pushLeave: Function;
|
||||||
|
|
||||||
constructor(id: number, parseWebSocket: any, hasMasterKey: boolean) {
|
constructor(
|
||||||
|
id: number,
|
||||||
|
parseWebSocket: any,
|
||||||
|
hasMasterKey: boolean = false,
|
||||||
|
sessionToken: string
|
||||||
|
) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.parseWebSocket = parseWebSocket;
|
this.parseWebSocket = parseWebSocket;
|
||||||
this.hasMasterKey = hasMasterKey;
|
this.hasMasterKey = hasMasterKey;
|
||||||
|
this.sessionToken = sessionToken;
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.subscriptionInfos = new Map();
|
this.subscriptionInfos = new Map();
|
||||||
this.pushConnect = this._pushEvent('connected');
|
this.pushConnect = this._pushEvent('connected');
|
||||||
|
|||||||
@@ -580,15 +580,24 @@ class ParseLiveQueryServer {
|
|||||||
}
|
}
|
||||||
const hasMasterKey = this._hasMasterKey(request, this.keyPairs);
|
const hasMasterKey = this._hasMasterKey(request, this.keyPairs);
|
||||||
const clientId = uuid();
|
const clientId = uuid();
|
||||||
const client = new Client(clientId, parseWebsocket, hasMasterKey);
|
const client = new Client(
|
||||||
|
clientId,
|
||||||
|
parseWebsocket,
|
||||||
|
hasMasterKey,
|
||||||
|
request.sessionToken
|
||||||
|
);
|
||||||
parseWebsocket.clientId = clientId;
|
parseWebsocket.clientId = clientId;
|
||||||
this.clients.set(parseWebsocket.clientId, client);
|
this.clients.set(parseWebsocket.clientId, client);
|
||||||
logger.info(`Create new client: ${parseWebsocket.clientId}`);
|
logger.info(`Create new client: ${parseWebsocket.clientId}`);
|
||||||
client.pushConnect();
|
client.pushConnect();
|
||||||
runLiveQueryEventHandlers({
|
runLiveQueryEventHandlers({
|
||||||
|
client,
|
||||||
event: 'connect',
|
event: 'connect',
|
||||||
clients: this.clients.size,
|
clients: this.clients.size,
|
||||||
subscriptions: this.subscriptions.size,
|
subscriptions: this.subscriptions.size,
|
||||||
|
sessionToken: request.sessionToken,
|
||||||
|
useMasterKey: client.hasMasterKey,
|
||||||
|
installationId: request.installationId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,13 +672,16 @@ class ParseLiveQueryServer {
|
|||||||
const subscriptionInfo = {
|
const subscriptionInfo = {
|
||||||
subscription: subscription,
|
subscription: subscription,
|
||||||
};
|
};
|
||||||
// Add selected fields and sessionToken for this subscription if necessary
|
// Add selected fields, sessionToken and installationId for this subscription if necessary
|
||||||
if (request.query.fields) {
|
if (request.query.fields) {
|
||||||
subscriptionInfo.fields = request.query.fields;
|
subscriptionInfo.fields = request.query.fields;
|
||||||
}
|
}
|
||||||
if (request.sessionToken) {
|
if (request.sessionToken) {
|
||||||
subscriptionInfo.sessionToken = request.sessionToken;
|
subscriptionInfo.sessionToken = request.sessionToken;
|
||||||
}
|
}
|
||||||
|
if (request.installationId) {
|
||||||
|
subscriptionInfo.installationId = request.installationId;
|
||||||
|
}
|
||||||
client.addSubscriptionInfo(request.requestId, subscriptionInfo);
|
client.addSubscriptionInfo(request.requestId, subscriptionInfo);
|
||||||
|
|
||||||
// Add clientId to subscription
|
// Add clientId to subscription
|
||||||
@@ -685,9 +697,13 @@ class ParseLiveQueryServer {
|
|||||||
);
|
);
|
||||||
logger.verbose('Current client number: %d', this.clients.size);
|
logger.verbose('Current client number: %d', this.clients.size);
|
||||||
runLiveQueryEventHandlers({
|
runLiveQueryEventHandlers({
|
||||||
|
client,
|
||||||
event: 'subscribe',
|
event: 'subscribe',
|
||||||
clients: this.clients.size,
|
clients: this.clients.size,
|
||||||
subscriptions: this.subscriptions.size,
|
subscriptions: this.subscriptions.size,
|
||||||
|
sessionToken: request.sessionToken,
|
||||||
|
useMasterKey: client.hasMasterKey,
|
||||||
|
installationId: request.installationId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,9 +779,13 @@ class ParseLiveQueryServer {
|
|||||||
this.subscriptions.delete(className);
|
this.subscriptions.delete(className);
|
||||||
}
|
}
|
||||||
runLiveQueryEventHandlers({
|
runLiveQueryEventHandlers({
|
||||||
|
client,
|
||||||
event: 'unsubscribe',
|
event: 'unsubscribe',
|
||||||
clients: this.clients.size,
|
clients: this.clients.size,
|
||||||
subscriptions: this.subscriptions.size,
|
subscriptions: this.subscriptions.size,
|
||||||
|
sessionToken: subscriptionInfo.sessionToken,
|
||||||
|
useMasterKey: client.hasMasterKey,
|
||||||
|
installationId: subscriptionInfo.installationId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!notifyClient) {
|
if (!notifyClient) {
|
||||||
|
|||||||
Reference in New Issue
Block a user