Skip to content

Commit

Permalink
task: Add an X-Unleash-Version header to register response (#5774)
Browse files Browse the repository at this point in the history
Related to our work for making Edge bulk metrics a 1st class citizen of
Unleash, this PR adds an X-Unleash-Version header to the response from
client registration.

Based on when we add the new `/api/client/metrics/bulk` endpoint, Edge
can use the response header from upstream to decide whether to post
metrics to `/edge/metrics` or `/api/client/metrics/bulk`.
  • Loading branch information
Christopher Kolstad committed Jan 5, 2024
1 parent 04814bf commit e769cea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/lib/routes/client-api/register.test.ts
Expand Up @@ -102,3 +102,19 @@ test('should allow an empty instanceId field', () => {
})
.expect(202);
});

test('Includes an X-Unleash-Version header in the response', () => {
return request
.post('/api/client/register')
.send({
appName: 'demo',
instanceId: '',
strategies: ['default'],
started: Date.now(),
interval: 10,
})
.expect(202)
.expect((res) => {
expect(res.headers['x-unleash-version']).toBeTruthy();
});
});
3 changes: 2 additions & 1 deletion src/lib/routes/client-api/register.ts
Expand Up @@ -15,6 +15,7 @@ import { createRequestSchema } from '../../openapi/util/create-request-schema';
import { ClientApplicationSchema } from '../../openapi/spec/client-application-schema';
import rateLimit from 'express-rate-limit';
import { minutesToMilliseconds } from 'date-fns';
import version from '../../util/version';

export default class RegisterController extends Controller {
logger: Logger;
Expand Down Expand Up @@ -93,6 +94,6 @@ export default class RegisterController extends Controller {
data.environment = RegisterController.resolveEnvironment(user, data);
data.project = RegisterController.extractProjectFromRequest(req);
await this.clientInstanceService.registerClient(data, clientIp);
res.status(202).end();
res.header('X-Unleash-Version', version).status(202).end();
}
}

0 comments on commit e769cea

Please sign in to comment.