Code coverage report for node/src/apm/prometheus/histogram.ts

Statements: 41.67% (5 / 12)      Branches: 0% (0 / 3)      Functions: 0% (0 / 4)      Lines: 41.67% (5 / 12)      Ignored: none     

All files » node/src/apm/prometheus/ » histogram.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 451 1 1     1                                               1                              
import {PromMetric, PromOptions} from './metric';
import {Histogram, HistogramFactory, Providers, Tags} from '@btilford/ts-base-core';
import {Histogram as Delegate, Registry} from 'prom-client';
 
 
export class PromHistogram extends PromMetric implements Histogram<number> {
  protected readonly impl: Delegate<any>;
 
 
  constructor(name: string, tags: Tags, options: PromOptions) {
    super(name, tags, options);
    this.impl = new Delegate({
      name: this.name,
      help: options.help,
      registers: options.registry || [Providers.provide(Registry)],
      aggregator: options.aggregator,
      labelNames: [...this.supportedLabels],
    });
  }
 
 
  set(value: number, tags: Tags = {}): void {
    const _tags = this.filterTags({ ...this.tags, ...tags });
    this.impl.observe(_tags, value);
  }
 
}
 
 
export class PromHistogramFactory extends HistogramFactory<number> {
  protected readonly options: PromOptions;
 
 
  constructor(options: PromOptions) {
    super();
    this.options = { ...options };
  }
 
 
  histogram(name: string, tags): Histogram<number> {
    return new PromHistogram(name, tags, this.options);
  }
 
}