digikare / nestjs-prom

A prometheus module for nestjs
160 stars 54 forks source link

can't use histogram without the labelNames and buckets #56

Open hpsmatheus opened 3 years ago

hpsmatheus commented 3 years ago

I have the following histogram


this.usersHistogram = this.promService.getHistogram({
            name: 'users_histogram',
            help: 'Request duration',
            buckets: [0.1, 0.3, 0.5],
            labelNames: ['a1'],
        });

but if I remove the labelNames param, I get this error when starting the application

TypeError: Cannot read property 'forEach' of undefined
    at validateInput (/home/matheus/node_modules/@digikare/nestjs-prom/node_modules/prom-client/lib/histogram.js:166:9)
    at new Histogram (/home/matheus/node_modules/@digikare/nestjs-prom/node_modules/prom-client/lib/histogram.js:44:3)
    at findOrCreateMetric (/home/matheus/node_modules/@digikare/nestjs-prom/dist/common/prom.utils.js:50:20)
    at Object.findOrCreateHistogram (/home/matheus/node_modules/@digikare/nestjs-prom/dist/common/prom.utils.js:87:12)
    at PromService.getHistogram (/home/matheus/node_modules/@digikare/nestjs-prom/dist/prom.service.js:26:29)

And if I remove the buckets param, I get this error


TypeError: Cannot read property 'reduce' of undefined
    at new Histogram (/home/matheus/node_modules/@digikare/nestjs-prom/node_modules/prom-client/lib/histogram.js:51:40)
    at findOrCreateMetric (/home/matheus/node_modules/@digikare/nestjs-prom/dist/common/prom.utils.js:50:20)
    at Object.findOrCreateHistogram (/home/matheus/node_modules/@digikare/nestjs-prom/dist/common/prom.utils.js:87:12)
    at PromService.getHistogram (/home/matheus/node_modules/@digikare/nestjs-prom/dist/prom.service.js:26:29)

I'm trying to remove these params because the IHistogramMetricArguments says they are not required.

export interface IHistogramMetricArguments extends IMetricArguments {
    buckets?: number[];
}

export interface IMetricArguments {
    name: string;
    help?: string;
    labelNames?: string[];
    registry?: PromClient.Registry;
}

I'm using version 1.0.0

travtarr commented 3 years ago

I get the same issue. It seems to be that prom-client@12.0.0 introduced these breaking changes. Looking at the source ^13 might be a fix to the issue but I haven't tested it yet.

cramhead commented 3 years ago

Seem's it's still a problem in prom-client 13.1.0. If I provide a default configuration for buckets it seems to stop throwing this error.

e.g.

this.promService.getHistogram({
      name: 'graphql_total_request_time',
      help: 'The time to complete a GraphQL query.',
      labelNames: ['operationName', 'operation'],
      buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
    });