Skip to content

Commit

Permalink
fix: allow clients to send metrics when using all path
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarconr committed May 29, 2024
1 parent 923fd49 commit b034735
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/test/__snapshots__/openapi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,79 @@ If you don't provide the \`toggles\` property, then this operation functions exa
],
},
},
"/proxy/all/client/metrics": Object {
"post": Object {
"description": "This endpoint lets you register usage metrics with Unleash. Accepts either one of the proxy's configured \`serverSideTokens\` or one of its \`clientKeys\` for authorization.",
"requestBody": Object {
"content": Object {
"application/json": Object {
"schema": Object {
"$ref": "#/components/schemas/registerMetricsSchema",
},
},
},
},
"responses": Object {
"200": Object {
"content": Object {
"text/plain": Object {
"schema": Object {
"example": "ok",
"type": "string",
},
},
},
"description": "The request was successful.",
},
"400": Object {
"content": Object {
"application/json": Object {
"schema": Object {
"example": Object {
"error": "Request validation failed",
"validation": Array [
Object {
"dataPath": ".body",
"keyword": "required",
"message": "should have required property 'appName'",
"params": Object {
"missingProperty": "appName",
},
"schemaPath": "#/components/schemas/registerMetricsSchema/required",
},
],
},
"properties": Object {
"error": Object {
"type": "string",
},
"validation": Object {
"items": Object {
"type": "object",
},
"type": "array",
},
},
"required": Array [
"error",
],
"type": "object",
},
},
},
"description": "The provided request data is invalid.",
},
"401": Object {
"description": "Authorization information is missing or invalid.",
},
},
"summary": "Send usage metrics to Unleash.",
"tags": Array [
"Operational",
"Server-side client",
],
},
},
"/proxy/client/features": Object {
"get": Object {
"description": "Returns the toggle configuration from the proxy's internal Unleash SDK. Use this to bootstrap other proxies and server-side SDKs. Requires you to provide one of the proxy's configured \`serverSideTokens\` for authorization.",
Expand Down
24 changes: 24 additions & 0 deletions src/test/unleash-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,30 @@ test('Should register metrics', () => {
.expect(200);
});

test('Should register metrics an /all path as well', () => {
const toggles = [
{
name: 'test',
enabled: true,
impressionData: true,
},
];
const client = new MockClient(toggles);

const proxySecrets = ['sdf'];
const app = createApp(
{ unleashUrl, unleashApiToken, proxySecrets },
client,
);
client.emit('ready');

return request(app)
.post('/proxy/all/client/metrics')
.send(metrics)
.set('Authorization', 'sdf')
.expect(200);
});

test('Should require metrics to have correct format', () => {
const client = new MockClient();

Expand Down
13 changes: 13 additions & 0 deletions src/unleash-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ If you don't provide the \`toggles\` property, then this operation functions exa
this.getAllTogglesPOST.bind(this),
);

router.post(
'/all/client/metrics',
openApiService.validPath({
requestBody: registerMetricsRequest,
responses: standardResponses(200, 400, 401),
description:
"This endpoint lets you register usage metrics with Unleash. Accepts either one of the proxy's configured `serverSideTokens` or one of its `clientKeys` for authorization.",
summary: 'Send usage metrics to Unleash.',
tags: ['Operational', 'Server-side client'],
}),
this.registerMetrics.bind(this),
);

router.post(
'',
openApiService.validPath({
Expand Down

0 comments on commit b034735

Please sign in to comment.