mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
feat: ingest new impact metrics (#10169)
Accepts the new impact metrics into the singleton registry and then does nothing with them. If the relevant flag is off, the metrics are stripped from the existing metrics data format and dropped on the floor
This commit is contained in:
parent
e466e72e0d
commit
40c7c25db9
@ -27,6 +27,7 @@ import { CLIENT_METRICS } from '../../../events/index.js';
|
||||
import type { CustomMetricsSchema } from '../../../openapi/spec/custom-metrics-schema.js';
|
||||
import type { StoredCustomMetric } from '../custom/custom-metrics-store.js';
|
||||
import type { CustomMetricsService } from '../custom/custom-metrics-service.js';
|
||||
import type { MetricsTranslator } from '../impact/metrics-translator.js';
|
||||
|
||||
export default class ClientMetricsController extends Controller {
|
||||
logger: Logger;
|
||||
@ -39,6 +40,8 @@ export default class ClientMetricsController extends Controller {
|
||||
|
||||
customMetricsService: CustomMetricsService;
|
||||
|
||||
metricsTranslator: MetricsTranslator;
|
||||
|
||||
flagResolver: IFlagResolver;
|
||||
|
||||
constructor(
|
||||
@ -55,6 +58,7 @@ export default class ClientMetricsController extends Controller {
|
||||
| 'customMetricsService'
|
||||
>,
|
||||
config: IUnleashConfig,
|
||||
metricsTranslator: MetricsTranslator,
|
||||
) {
|
||||
super(config);
|
||||
const { getLogger } = config;
|
||||
@ -65,6 +69,7 @@ export default class ClientMetricsController extends Controller {
|
||||
this.metricsV2 = clientMetricsServiceV2;
|
||||
this.customMetricsService = customMetricsService;
|
||||
this.flagResolver = config.flagResolver;
|
||||
this.metricsTranslator = metricsTranslator;
|
||||
|
||||
this.route({
|
||||
method: 'post',
|
||||
@ -150,16 +155,25 @@ export default class ClientMetricsController extends Controller {
|
||||
} else {
|
||||
try {
|
||||
const { body: data, ip: clientIp, user } = req;
|
||||
data.environment = this.metricsV2.resolveMetricsEnvironment(
|
||||
user,
|
||||
data,
|
||||
);
|
||||
const { impactMetrics, ...metricsData } = data;
|
||||
metricsData.environment =
|
||||
this.metricsV2.resolveMetricsEnvironment(user, metricsData);
|
||||
await this.clientInstanceService.registerInstance(
|
||||
data,
|
||||
metricsData,
|
||||
clientIp,
|
||||
);
|
||||
|
||||
await this.metricsV2.registerClientMetrics(data, clientIp);
|
||||
await this.metricsV2.registerClientMetrics(
|
||||
metricsData,
|
||||
clientIp,
|
||||
);
|
||||
if (
|
||||
this.flagResolver.isEnabled('impactMetrics') &&
|
||||
impactMetrics
|
||||
) {
|
||||
this.metricsTranslator.translateMetrics(impactMetrics);
|
||||
}
|
||||
|
||||
res.getHeaderNames().forEach((header) =>
|
||||
res.removeHeader(header),
|
||||
);
|
||||
|
@ -4,13 +4,20 @@ import MetricsController from '../../features/metrics/instance/metrics.js';
|
||||
import RegisterController from '../../features/metrics/instance/register.js';
|
||||
import type { IUnleashConfig } from '../../types/index.js';
|
||||
import type { IUnleashServices } from '../../services/index.js';
|
||||
import { impactRegister } from '../../features/metrics/impact/impact-register.js';
|
||||
import { MetricsTranslator } from '../../features/metrics/impact/metrics-translator.js';
|
||||
|
||||
export default class ClientApi extends Controller {
|
||||
constructor(config: IUnleashConfig, services: IUnleashServices) {
|
||||
super(config);
|
||||
|
||||
const metricsTranslator = new MetricsTranslator(impactRegister);
|
||||
|
||||
this.use('/features', new FeatureController(services, config).router);
|
||||
this.use('/metrics', new MetricsController(services, config).router);
|
||||
this.use(
|
||||
'/metrics',
|
||||
new MetricsController(services, config, metricsTranslator).router,
|
||||
);
|
||||
this.use('/register', new RegisterController(services, config).router);
|
||||
}
|
||||
}
|
||||
|
@ -292,6 +292,10 @@ const flags: IFlags = {
|
||||
process.env.UNLEASH_EXPERIMENTAL_IMPROVED_JSON_DIFF,
|
||||
false,
|
||||
),
|
||||
impactMetrics: parseEnvVarBoolean(
|
||||
process.env.UNLEASH_EXPERIMENTAL_IMPACT_METRICS,
|
||||
false,
|
||||
),
|
||||
};
|
||||
|
||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||
|
Loading…
Reference in New Issue
Block a user