1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00

feat: add histogram to impact metrics (#10728)

This commit is contained in:
Mateusz Kwasniewski 2025-10-03 10:13:12 +02:00 committed by GitHub
parent adada932b9
commit 3ef2a7f93b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,8 +3,10 @@ import type { FromSchema } from 'json-schema-to-ts';
export const impactMetricsSchema = { export const impactMetricsSchema = {
$id: '#/components/schemas/impactMetricsSchema', $id: '#/components/schemas/impactMetricsSchema',
type: 'object', type: 'object',
required: ['name', 'help', 'type', 'samples'],
description: 'Used for reporting impact metrics from SDKs', description: 'Used for reporting impact metrics from SDKs',
oneOf: [
{
required: ['name', 'help', 'type', 'samples'],
properties: { properties: {
name: { name: {
type: 'string', type: 'string',
@ -24,13 +26,13 @@ export const impactMetricsSchema = {
example: 'counter', example: 'counter',
}, },
samples: { samples: {
description: 'Samples of the metric', description: 'Samples of the numeric metric',
type: 'array', type: 'array',
items: { items: {
type: 'object', type: 'object',
required: ['value'], required: ['value'],
description: description:
'A sample of a metric with a value and optional labels', 'A sample of a numeric metric with a value and optional labels',
properties: { properties: {
value: { value: {
type: 'number', type: 'number',
@ -38,10 +40,14 @@ export const impactMetricsSchema = {
example: 10, example: 10,
}, },
labels: { labels: {
description: 'Optional labels for the metric sample', description:
'Optional labels for the metric sample',
type: 'object', type: 'object',
additionalProperties: { additionalProperties: {
type: 'string', oneOf: [
{ type: 'string' },
{ type: 'number' },
],
}, },
example: { example: {
application: 'my-app', application: 'my-app',
@ -52,6 +58,95 @@ export const impactMetricsSchema = {
}, },
}, },
}, },
},
{
required: ['name', 'help', 'type', 'samples'],
properties: {
name: {
type: 'string',
description: 'Name of the impact metric',
example: 'my-histogram',
},
help: {
description:
'Human-readable description of what the metric measures',
type: 'string',
example: 'Measures request duration',
},
type: {
description: 'Type of the metric',
type: 'string',
enum: ['histogram'],
example: 'histogram',
},
samples: {
description: 'Samples of the histogram metric',
type: 'array',
items: {
type: 'object',
required: ['count', 'sum', 'buckets'],
description:
'A sample of a histogram metric with count, sum, buckets and optional labels',
properties: {
count: {
type: 'number',
description: 'Total count of observations',
example: 100,
},
sum: {
type: 'number',
description: 'Sum of all observed values',
example: 1500,
},
buckets: {
type: 'array',
description: 'Histogram buckets',
items: {
type: 'object',
required: ['le', 'count'],
properties: {
le: {
oneOf: [
{ type: 'number' },
{
type: 'string',
enum: ['+Inf'],
},
],
description:
'Upper bound of the bucket',
example: 0.5,
},
count: {
type: 'number',
description:
'Count of observations in this bucket',
example: 30,
},
},
},
},
labels: {
description:
'Optional labels for the metric sample',
type: 'object',
additionalProperties: {
oneOf: [
{ type: 'string' },
{ type: 'number' },
],
},
example: {
application: 'my-app',
environment: 'production',
},
},
},
},
},
},
},
],
components: { components: {
schemas: {}, schemas: {},
}, },