Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics docs and disabling #1186

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/delivery-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ npm
```
npm start
```

## Configuration

### Metrics collection

This delivery service implementation collects these metrics:

- number of messages received
- number of notifications sent
- total size of messages received

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.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ describe('setMetrics', () => {
mockDeliveryServiceProperties.metricsRetentionDurationInSeconds,
);
});

it('should not collect metrics when retention interval is 0', async () => {
const messageSizeBytes = 100;
const countMessageFunction = countMessage(mockRedis);

const propertiesWithZeroRetention = {
...mockDeliveryServiceProperties,
metricsRetentionDurationInSeconds: 0,
};

await countMessageFunction(
messageSizeBytes,
propertiesWithZeroRetention,
);

expect(mockRedis.incrBy).not.toHaveBeenCalled();
expect(mockRedis.expire).not.toHaveBeenCalled();
});
});

describe('countNotification', () => {
Expand All @@ -76,5 +94,19 @@ describe('setMetrics', () => {
mockDeliveryServiceProperties.metricsRetentionDurationInSeconds,
);
});

it('should not collect metrics when retention interval is 0', async () => {
const countNotificationFunction = countNotification(mockRedis);

const propertiesWithZeroRetention = {
...mockDeliveryServiceProperties,
metricsRetentionDurationInSeconds: 0,
};

await countNotificationFunction(propertiesWithZeroRetention);

expect(mockRedis.incrBy).not.toHaveBeenCalled();
expect(mockRedis.expire).not.toHaveBeenCalled();
});
});
});
10 changes: 10 additions & 0 deletions packages/delivery-service/src/persistence/metrics/setMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export function countMessage(redis: Redis) {
messageSizeBytes: number,
deliveryServiceProperties: DeliveryServiceProperties,
) => {
if (deliveryServiceProperties.metricsRetentionDurationInSeconds <= 0) {
// Metrics are disabled
return;
}

const timestamp = getCurrentIntervalTimestamp(
deliveryServiceProperties.metricsCollectionIntervalInSeconds,
);
Expand Down Expand Up @@ -43,6 +48,11 @@ export function countMessage(redis: Redis) {

export function countNotification(redis: Redis) {
return async (deliveryServiceProperties: DeliveryServiceProperties) => {
if (deliveryServiceProperties.metricsRetentionDurationInSeconds <= 0) {
// Metrics are disabled
return;
}

const timestamp = getCurrentIntervalTimestamp(
deliveryServiceProperties.metricsCollectionIntervalInSeconds,
);
Expand Down
Loading