mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
task: add kill-switch for edge bulk metrics (#5758)
If the kill switch is enabled unleash returns 404 and a json body explaining why a 404 was given, encouraging users to upgrade to the most recent version of Edge.
This commit is contained in:
parent
795aa18bca
commit
4c574a1e50
@ -81,6 +81,7 @@ exports[`should create default config 1`] = `
|
|||||||
"disableBulkToggle": false,
|
"disableBulkToggle": false,
|
||||||
"disableMetrics": false,
|
"disableMetrics": false,
|
||||||
"disableNotifications": false,
|
"disableNotifications": false,
|
||||||
|
"edgeBulkMetricsKillSwitch": false,
|
||||||
"embedProxy": true,
|
"embedProxy": true,
|
||||||
"embedProxyFrontend": true,
|
"embedProxyFrontend": true,
|
||||||
"enableLicense": false,
|
"enableLicense": false,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import Controller from '../controller';
|
import Controller from '../controller';
|
||||||
import { IUnleashConfig, IUnleashServices } from '../../types';
|
import { IFlagResolver, IUnleashConfig, IUnleashServices } from '../../types';
|
||||||
import { Logger } from '../../logger';
|
import { Logger } from '../../logger';
|
||||||
import { NONE } from '../../types/permissions';
|
import { NONE } from '../../types/permissions';
|
||||||
import { createResponseSchema } from '../../openapi/util/create-response-schema';
|
import { createResponseSchema } from '../../openapi/util/create-response-schema';
|
||||||
@ -33,6 +33,8 @@ export default class EdgeController extends Controller {
|
|||||||
|
|
||||||
private clientInstanceService: ClientInstanceService;
|
private clientInstanceService: ClientInstanceService;
|
||||||
|
|
||||||
|
private flagResolver: IFlagResolver;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
{
|
{
|
||||||
@ -54,6 +56,7 @@ export default class EdgeController extends Controller {
|
|||||||
this.openApiService = openApiService;
|
this.openApiService = openApiService;
|
||||||
this.metricsV2 = clientMetricsServiceV2;
|
this.metricsV2 = clientMetricsServiceV2;
|
||||||
this.clientInstanceService = clientInstanceService;
|
this.clientInstanceService = clientInstanceService;
|
||||||
|
this.flagResolver = config.flagResolver;
|
||||||
|
|
||||||
this.route({
|
this.route({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
@ -115,6 +118,7 @@ export default class EdgeController extends Controller {
|
|||||||
req: IAuthRequest<void, void, BulkMetricsSchema>,
|
req: IAuthRequest<void, void, BulkMetricsSchema>,
|
||||||
res: Response<void>,
|
res: Response<void>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
if (!this.flagResolver.isEnabled('edgeBulkMetricsKillSwitch')) {
|
||||||
const { body, ip: clientIp } = req;
|
const { body, ip: clientIp } = req;
|
||||||
const { metrics, applications } = body;
|
const { metrics, applications } = body;
|
||||||
|
|
||||||
@ -122,7 +126,10 @@ export default class EdgeController extends Controller {
|
|||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
for (const app of applications) {
|
for (const app of applications) {
|
||||||
promises.push(
|
promises.push(
|
||||||
this.clientInstanceService.registerClient(app, clientIp),
|
this.clientInstanceService.registerClient(
|
||||||
|
app,
|
||||||
|
clientIp,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (metrics && metrics.length > 0) {
|
if (metrics && metrics.length > 0) {
|
||||||
@ -135,5 +142,13 @@ export default class EdgeController extends Controller {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(400).end();
|
res.status(400).end();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// @ts-expect-error Expected result here is void, but since we want to communicate extra information in our 404, we allow this to avoid type-checking
|
||||||
|
res.status(404).json({
|
||||||
|
status: 'disabled',
|
||||||
|
reason: 'disabled by killswitch',
|
||||||
|
help: 'You should upgrade Edge to the most recent version to not lose metrics',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ export type IFlagKey =
|
|||||||
| 'increaseUnleashWidth'
|
| 'increaseUnleashWidth'
|
||||||
| 'featureSearchFeedback'
|
| 'featureSearchFeedback'
|
||||||
| 'featureSearchFeedbackPosting'
|
| 'featureSearchFeedbackPosting'
|
||||||
| 'newStrategyConfigurationFeedback';
|
| 'newStrategyConfigurationFeedback'
|
||||||
|
| 'edgeBulkMetricsKillSwitch';
|
||||||
|
|
||||||
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
||||||
|
|
||||||
@ -168,6 +169,10 @@ const flags: IFlags = {
|
|||||||
process.env.UNLEASH_EXPERIMENTAL_NEW_STRATEGY_CONFIGURATION_FEEDBACK,
|
process.env.UNLEASH_EXPERIMENTAL_NEW_STRATEGY_CONFIGURATION_FEEDBACK,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
edgeBulkMetricsKillSwitch: parseEnvVarBoolean(
|
||||||
|
process.env.UNLEASH_EXPERIMENTAL_EDGE_BULK_METRICS_KILL_SWITCH,
|
||||||
|
false,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||||
|
Loading…
Reference in New Issue
Block a user