Skip to content

Commit

Permalink
fix: allow instance ID to be empty for metrics (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
olav committed Apr 1, 2022
1 parent be21a2a commit cf06b56
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/lib/routes/client-api/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ test('should set lastSeen on toggle', async () => {
.post('/api/client/metrics')
.send({
appName: 'demo',
instanceId: '1',
bucket: {
start: Date.now(),
stop: Date.now(),
Expand Down
13 changes: 13 additions & 0 deletions src/lib/routes/client-api/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,16 @@ test('should require strategies field', () => {
})
.expect(400);
});

test('should allow an empty instanceId field', () => {
expect.assertions(0);
return request
.post('/api/client/register')
.send({
appName: 'demo',
strategies: ['default'],
started: Date.now(),
interval: 10,
})
.expect(202);
});
5 changes: 3 additions & 2 deletions src/lib/services/client-metrics/instance-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { clientRegisterSchema } from './schema';
import { minutesToMilliseconds, secondsToMilliseconds } from 'date-fns';
import { IClientMetricsStoreV2 } from '../../types/stores/client-metrics-store-v2';
import { clientMetricsSchema } from './schema';
import { PartialSome } from '../../types/partial';

export default class ClientInstanceService {
apps = {};
Expand Down Expand Up @@ -90,7 +91,7 @@ export default class ClientInstanceService {
}

public async registerInstance(
data: IClientApp,
data: PartialSome<IClientApp, 'instanceId'>,
clientIp: string,
): Promise<void> {
const value = await clientMetricsSchema.validateAsync(data);
Expand All @@ -103,7 +104,7 @@ export default class ClientInstanceService {
}

public async registerClient(
data: IClientApp,
data: PartialSome<IClientApp, 'instanceId'>,
clientIp: string,
): Promise<void> {
const value = await clientRegisterSchema.validateAsync(data);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/services/client-metrics/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const clientMetricsSchema = joi
.keys({
environment: joi.string().optional(),
appName: joi.string().required(),
instanceId: joi.string().required(),
instanceId: joi.string().default('default'),
bucket: joi
.object()
.required()
Expand Down Expand Up @@ -48,7 +48,7 @@ export const clientRegisterSchema = joi
.options({ stripUnknown: true })
.keys({
appName: joi.string().required(),
instanceId: joi.string().required(),
instanceId: joi.string().default('default'),
sdkVersion: joi.string().optional(),
strategies: joi
.array()
Expand Down

0 comments on commit cf06b56

Please sign in to comment.