mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
chore: re-use the same client schema for proxy (#3251)
## About the changes client-metrics-schema is less strict than proxy-metrics-schema because the former allows empty `instanceId` and also supports dates as timestamps as well as date-formatted strings. Using the same schema makes sense to reduce maintainability costs and it's less error-prone if we need to modify the schema because underlying the schema they both use the same code. The reasoning is that proxy metrics should align with our client metrics. Alternatively, we have new endpoints for edge metrics that will aggregate and bucket by client. ![image](https://user-images.githubusercontent.com/455064/222738911-4c443e02-3072-4042-bfde-327da8dd46fe.png) ## Discussion points Will we ever want to evolve proxy-metrics differently than client-metrics? I'm under the assumption that the answer is no
This commit is contained in:
parent
24afbdeac1
commit
37ce81a727
@ -82,7 +82,6 @@ import {
|
||||
proxyClientSchema,
|
||||
proxyFeatureSchema,
|
||||
proxyFeaturesSchema,
|
||||
proxyMetricsSchema,
|
||||
publicSignupTokenCreateSchema,
|
||||
projectStatsSchema,
|
||||
publicSignupTokenSchema,
|
||||
@ -230,7 +229,6 @@ export const schemas = {
|
||||
proxyClientSchema,
|
||||
proxyFeatureSchema,
|
||||
proxyFeaturesSchema,
|
||||
proxyMetricsSchema,
|
||||
publicSignupTokenCreateSchema,
|
||||
publicSignupTokenSchema,
|
||||
publicSignupTokensSchema,
|
||||
|
@ -6,25 +6,15 @@ export const clientMetricsSchema = {
|
||||
type: 'object',
|
||||
required: ['appName', 'bucket'],
|
||||
properties: {
|
||||
appName: {
|
||||
type: 'string',
|
||||
},
|
||||
instanceId: {
|
||||
type: 'string',
|
||||
},
|
||||
environment: {
|
||||
type: 'string',
|
||||
},
|
||||
appName: { type: 'string' },
|
||||
instanceId: { type: 'string' },
|
||||
environment: { type: 'string' },
|
||||
bucket: {
|
||||
type: 'object',
|
||||
required: ['start', 'stop', 'toggles'],
|
||||
properties: {
|
||||
start: {
|
||||
$ref: '#/components/schemas/dateSchema',
|
||||
},
|
||||
stop: {
|
||||
$ref: '#/components/schemas/dateSchema',
|
||||
},
|
||||
start: { $ref: '#/components/schemas/dateSchema' },
|
||||
stop: { $ref: '#/components/schemas/dateSchema' },
|
||||
toggles: {
|
||||
type: 'object',
|
||||
example: {
|
||||
@ -45,14 +35,8 @@ export const clientMetricsSchema = {
|
||||
additionalProperties: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
yes: {
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
},
|
||||
no: {
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
},
|
||||
yes: { type: 'integer', minimum: 0 },
|
||||
no: { type: 'integer', minimum: 0 },
|
||||
variants: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
|
@ -66,7 +66,6 @@ export * from './feature-types-schema';
|
||||
export * from './feature-usage-schema';
|
||||
export * from './health-report-schema';
|
||||
export * from './proxy-feature-schema';
|
||||
export * from './proxy-metrics-schema';
|
||||
export * from './search-events-schema';
|
||||
export * from './set-ui-config-schema';
|
||||
export * from './client-feature-schema';
|
||||
|
@ -1,55 +0,0 @@
|
||||
import { FromSchema } from 'json-schema-to-ts';
|
||||
|
||||
export const proxyMetricsSchema = {
|
||||
$id: '#/components/schemas/proxyMetricsSchema',
|
||||
type: 'object',
|
||||
required: ['appName', 'instanceId', 'bucket'],
|
||||
properties: {
|
||||
appName: { type: 'string' },
|
||||
instanceId: { type: 'string' },
|
||||
environment: { type: 'string' },
|
||||
bucket: {
|
||||
type: 'object',
|
||||
required: ['start', 'stop', 'toggles'],
|
||||
properties: {
|
||||
start: { type: 'string', format: 'date-time' },
|
||||
stop: { type: 'string', format: 'date-time' },
|
||||
toggles: {
|
||||
type: 'object',
|
||||
example: {
|
||||
myCoolToggle: {
|
||||
yes: 25,
|
||||
no: 42,
|
||||
variants: {
|
||||
blue: 6,
|
||||
green: 15,
|
||||
red: 46,
|
||||
},
|
||||
},
|
||||
myOtherToggle: {
|
||||
yes: 0,
|
||||
no: 100,
|
||||
},
|
||||
},
|
||||
additionalProperties: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
yes: { type: 'integer', minimum: 0 },
|
||||
no: { type: 'integer', minimum: 0 },
|
||||
variants: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
components: {},
|
||||
} as const;
|
||||
|
||||
export type ProxyMetricsSchema = FromSchema<typeof proxyMetricsSchema>;
|
@ -9,13 +9,13 @@ import {
|
||||
import { Logger } from '../../logger';
|
||||
import ApiUser from '../../types/api-user';
|
||||
import {
|
||||
ClientMetricsSchema,
|
||||
createRequestSchema,
|
||||
createResponseSchema,
|
||||
emptyResponse,
|
||||
ProxyClientSchema,
|
||||
proxyFeaturesSchema,
|
||||
ProxyFeaturesSchema,
|
||||
ProxyMetricsSchema,
|
||||
} from '../../openapi';
|
||||
import { Context } from 'unleash-client';
|
||||
import { enrichContextWithIp } from '../../proxy';
|
||||
@ -95,7 +95,7 @@ export default class ProxyController extends Controller {
|
||||
this.services.openApiService.validPath({
|
||||
tags: ['Frontend API'],
|
||||
operationId: 'registerFrontendMetrics',
|
||||
requestBody: createRequestSchema('proxyMetricsSchema'),
|
||||
requestBody: createRequestSchema('clientMetricsSchema'),
|
||||
responses: { 200: emptyResponse },
|
||||
}),
|
||||
],
|
||||
@ -168,7 +168,7 @@ export default class ProxyController extends Controller {
|
||||
}
|
||||
|
||||
private async registerProxyMetrics(
|
||||
req: ApiUserRequest<unknown, unknown, ProxyMetricsSchema>,
|
||||
req: ApiUserRequest<unknown, unknown, ClientMetricsSchema>,
|
||||
res: Response,
|
||||
) {
|
||||
await this.services.proxyService.registerProxyMetrics(
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { IUnleashConfig, IUnleashServices, IUnleashStores } from '../types';
|
||||
import { Logger } from '../logger';
|
||||
import { ProxyFeatureSchema, ProxyMetricsSchema } from '../openapi';
|
||||
import { ClientMetricsSchema, ProxyFeatureSchema } from '../openapi';
|
||||
import ApiUser from '../types/api-user';
|
||||
import {
|
||||
Context,
|
||||
@ -94,7 +94,7 @@ export class ProxyService {
|
||||
|
||||
async registerProxyMetrics(
|
||||
token: ApiUser,
|
||||
metrics: ProxyMetricsSchema,
|
||||
metrics: ClientMetricsSchema,
|
||||
ip: string,
|
||||
): Promise<void> {
|
||||
ProxyService.assertExpectedTokenType(token);
|
||||
|
@ -3027,81 +3027,6 @@ Stats are divided into current and previous **windows**.
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
"proxyMetricsSchema": {
|
||||
"properties": {
|
||||
"appName": {
|
||||
"type": "string",
|
||||
},
|
||||
"bucket": {
|
||||
"properties": {
|
||||
"start": {
|
||||
"format": "date-time",
|
||||
"type": "string",
|
||||
},
|
||||
"stop": {
|
||||
"format": "date-time",
|
||||
"type": "string",
|
||||
},
|
||||
"toggles": {
|
||||
"additionalProperties": {
|
||||
"properties": {
|
||||
"no": {
|
||||
"minimum": 0,
|
||||
"type": "integer",
|
||||
},
|
||||
"variants": {
|
||||
"additionalProperties": {
|
||||
"minimum": 0,
|
||||
"type": "integer",
|
||||
},
|
||||
"type": "object",
|
||||
},
|
||||
"yes": {
|
||||
"minimum": 0,
|
||||
"type": "integer",
|
||||
},
|
||||
},
|
||||
"type": "object",
|
||||
},
|
||||
"example": {
|
||||
"myCoolToggle": {
|
||||
"no": 42,
|
||||
"variants": {
|
||||
"blue": 6,
|
||||
"green": 15,
|
||||
"red": 46,
|
||||
},
|
||||
"yes": 25,
|
||||
},
|
||||
"myOtherToggle": {
|
||||
"no": 100,
|
||||
"yes": 0,
|
||||
},
|
||||
},
|
||||
"type": "object",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"start",
|
||||
"stop",
|
||||
"toggles",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
"environment": {
|
||||
"type": "string",
|
||||
},
|
||||
"instanceId": {
|
||||
"type": "string",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"appName",
|
||||
"instanceId",
|
||||
"bucket",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
"publicSignupTokenCreateSchema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
|
Loading…
Reference in New Issue
Block a user