From 627958d30f01a8124c6f25c76efb16befd815d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 1 Feb 2023 20:50:17 +0100 Subject: [PATCH] feat/enable_batch_metrics_for_all (#3027) Batch Metrics as a capability developed to support the frontend API to handle more metrics from SDKs without overloading the DB to much. It has been running in Unleash Cloud for months and has proven to work quite nice. This PR simply removes the flag to make the capability GA, also for self-hosted users. --- .../__snapshots__/create-config.test.ts.snap | 2 -- .../client-metrics/metrics-service-v2.ts | 17 +++++------------ src/lib/types/experimental.ts | 4 ---- src/server-dev.ts | 1 - src/test/config/test-config.ts | 1 - 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index 97bd4c7fcc..f5135eccb2 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -69,7 +69,6 @@ exports[`should create default config 1`] = ` "flags": { "ENABLE_DARK_MODE_SUPPORT": false, "anonymiseEventLog": false, - "batchMetrics": false, "caseInsensitiveInOperators": false, "crOnVariants": false, "embedProxy": true, @@ -91,7 +90,6 @@ exports[`should create default config 1`] = ` "experiments": { "ENABLE_DARK_MODE_SUPPORT": false, "anonymiseEventLog": false, - "batchMetrics": false, "caseInsensitiveInOperators": false, "crOnVariants": false, "embedProxy": true, diff --git a/src/lib/services/client-metrics/metrics-service-v2.ts b/src/lib/services/client-metrics/metrics-service-v2.ts index c315f7da80..33c304fa5f 100644 --- a/src/lib/services/client-metrics/metrics-service-v2.ts +++ b/src/lib/services/client-metrics/metrics-service-v2.ts @@ -95,18 +95,11 @@ export default class ClientMetricsServiceV2 { no: value.bucket.toggles[name].no, })); - if (this.config.flagResolver.isEnabled('batchMetrics')) { - this.unsavedMetrics = collapseHourlyMetrics([ - ...this.unsavedMetrics, - ...clientMetrics, - ]); - this.lastSeenService.updateLastSeen(clientMetrics); - } else { - if (toggleNames.length > 0) { - await this.featureToggleStore.setLastSeen(toggleNames); - } - await this.clientMetricsStoreV2.batchInsertMetrics(clientMetrics); - } + this.unsavedMetrics = collapseHourlyMetrics([ + ...this.unsavedMetrics, + ...clientMetrics, + ]); + this.lastSeenService.updateLastSeen(clientMetrics); this.config.eventBus.emit(CLIENT_METRICS, value); } diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index d80fc6140b..6f537164a3 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -22,10 +22,6 @@ const flags = { process.env.UNLEASH_EXPERIMENTAL_EMBED_PROXY_FRONTEND, true, ), - batchMetrics: parseEnvVarBoolean( - process.env.UNLEASH_EXPERIMENTAL_BATCH_METRICS, - false, - ), responseTimeWithAppName: parseEnvVarBoolean( process.env.UNLEASH_EXPERIMENTAL_RESPONSE_TIME_WITH_APP_NAME, false, diff --git a/src/server-dev.ts b/src/server-dev.ts index b9b6ca07af..cbd33a5e78 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -36,7 +36,6 @@ process.nextTick(async () => { flags: { embedProxy: true, embedProxyFrontend: true, - batchMetrics: true, anonymiseEventLog: false, responseTimeWithAppName: true, variantsPerEnvironment: true, diff --git a/src/test/config/test-config.ts b/src/test/config/test-config.ts index 2884ed63bb..26f0112f15 100644 --- a/src/test/config/test-config.ts +++ b/src/test/config/test-config.ts @@ -26,7 +26,6 @@ export function createTestConfig(config?: IUnleashOptions): IUnleashConfig { flags: { embedProxy: true, embedProxyFrontend: true, - batchMetrics: true, variantsPerEnvironment: true, }, },