Skip to content

Commit

Permalink
feat: debug metrics flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed May 22, 2024
1 parent 99403e4 commit 3888fab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ exports[`should create default config 1`] = `
"celebrateUnleash": false,
"collectTrafficDataUsage": false,
"createProjectWithEnvironmentConfig": false,
"debugMetrics": false,
"demo": false,
"disableBulkToggle": false,
"disableMetrics": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export default class ClientMetricsServiceV2 {
data: ClientMetricsSchema,
clientIp: string,
): Promise<void> {
if (this.flagResolver.isEnabled('debugMetrics')) {
this.logger.debug(`Metrics received: ${JSON.stringify(data)}`);
}

const value = await clientMetricsSchema.validateAsync(data);
const toggleNames = Object.keys(value.bucket.toggles).filter(
(name) =>
Expand All @@ -149,7 +153,7 @@ export default class ClientMetricsServiceV2 {
const validatedToggleNames =
await this.filterValidToggleNames(toggleNames);

this.logger.debug(
console.log(
`Got ${toggleNames.length} (${validatedToggleNames.length} valid) metrics from ${clientIp}`,
);

Expand Down
7 changes: 6 additions & 1 deletion src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export type IFlagKey =
| 'createProjectWithEnvironmentConfig'
| 'manyStrategiesPagination'
| 'newCreateProjectUI'
| 'enableLegacyVariants';
| 'enableLegacyVariants'
| 'debugMetrics';

export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

Expand Down Expand Up @@ -299,6 +300,10 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_ENABLE_LEGACY_VARIANTS,
false,
),
debugMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_DEBUG_METRICS,
false,
),
};

export const defaultExperimentalOptions: IExperimentalOptions = {
Expand Down

0 comments on commit 3888fab

Please sign in to comment.