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

fix: allow clients to send metrics when using all path #176

Merged
merged 1 commit into from
May 30, 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
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
Loading