Skip to content

Commit

Permalink
Updating labelOptions to be a Set
Browse files Browse the repository at this point in the history
  • Loading branch information
kev306 committed Jul 5, 2024
1 parent 2740fa2 commit 71a0562
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/clients/victoriaMetrics/promMetricCounter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import promClient, { Counter } from 'prom-client';
import { promAgent } from './promAgent';
import { generateLabelCombinations } from './metricFunctions';

export interface CounterConfig {
name: string;
help: string;
labelOptions?: Record<string, string[]>;
labelOptions?: Record<string, Set<string>>;
}

export interface PromClientCounterConfig {
Expand All @@ -29,7 +28,7 @@ export class PromMetricCounter {
if (counterConfig.labelOptions) {
const labelNames = Object.keys(counterConfig.labelOptions);
const invalidLabelNames = labelNames.filter((labelName) => {
return counterConfig.labelOptions[labelName].length === 0;
return counterConfig.labelOptions[labelName].size === 0;
});

if (invalidLabelNames.length > 0) {
Expand All @@ -44,9 +43,10 @@ export class PromMetricCounter {
}

if (counterConfig.labelOptions) {
this.labelCombinations = generateLabelCombinations(
counterConfig.labelOptions,
);
// TODO-kev: Needs to be fixed
// this.labelCombinations = generateLabelCombinations(
// counterConfig.labelOptions,
// );
}

this.counter = new promClient.Counter(promClientCounterConfig);
Expand All @@ -60,7 +60,7 @@ export class PromMetricCounter {

public inc(num: number, labels?: Record<string, string>) {
if (labels) {
// this.validateLabelCombination(labels);
this.validateLabelCombination(labels);
this.counter.inc(labels, num);
} else {
this.counter.inc(num);
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/gameMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export const gamesPlayedMetric = new PromMetricCounter({
name: 'games_played_total',
help: 'Total number of games played.',
labelOptions: {
status: ['finished', 'voided'],
status: new Set(['finished', 'voided', 'finished']),
},
});
2 changes: 1 addition & 1 deletion src/metrics/miscellaneousMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const avatarSubmissionsMetric = new PromMetricCounter({
name: `custom_avatar_submissions_total`,
help: `Total number of custom avatars submitted/rejected/approved.`,
labelOptions: {
status: ['approved', 'rejected', 'submitted'],
status: new Set(['approved', 'rejected', 'submitted']),
},
});

Expand Down

0 comments on commit 71a0562

Please sign in to comment.