Skip to content

Commit

Permalink
disable metrics collection on retention 0
Browse files Browse the repository at this point in the history
  • Loading branch information
malteish committed Sep 24, 2024
1 parent 0dc8e6f commit 58c9e0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/delivery-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ This delivery service implementation collects these metrics:
These metrics are accumulated over the `metricsCollectionIntervalInSeconds`, which can be defined in the config file and defaults to 1 hour. They are retained for `metricsRetentionDurationInSeconds`, which defaults to 10 days.

The metrics are not sent anywhere, but can be accessed by anyone via the `/metrics` endpoint. This endpoint censors the current collection interval to prevent real-time tracking, which would reduce the privacy of the users.

In order to disable metrics collection, set `metricsRetentionDurationInSeconds` to 0.
9 changes: 8 additions & 1 deletion packages/delivery-service/src/message/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ export class MessageProcessor {
deliveryInformation,
this.db.getUsersNotificationChannels,
);
await this.db.countNotification(this.deliveryServiceProperties);
if (
this.deliveryServiceProperties
.metricsRetentionDurationInSeconds > 0
) {
await this.db.countNotification(
this.deliveryServiceProperties,
);
}
} catch (err) {
console.log(
'Unable to send Notification. There might be an error in the config.yml. Message has been received regardless',
Expand Down
10 changes: 6 additions & 4 deletions packages/delivery-service/src/rpc/methods/handleSubmitMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ export async function handleSubmitMessage(

try {
await messageProcessor.processEnvelop(envelop);
await db.countMessage(
getEnvelopSize(envelop),
deliveryServiceProperties,
);
if (deliveryServiceProperties.metricsRetentionDurationInSeconds > 0) {
await db.countMessage(
getEnvelopSize(envelop),
deliveryServiceProperties,
);
}
res.sendStatus(200);
} catch (error) {
console.error('handle submit message error');
Expand Down

0 comments on commit 58c9e0b

Please sign in to comment.