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

Statements: 35.71% (5 / 14)      Branches: 0% (0 / 4)      Functions: 0% (0 / 6)      Lines: 35.71% (5 / 14)      Ignored: none     

All files » node/src/apm/prometheus/ » counter.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 45 46 47 481 1 1   1                                                           1                          
import {CounterFactory, Providers, Counter, Tags, NotImplementedError} from '@btilford/ts-base-core';
import {PromMetric, PromOptions} from './metric';
import {Counter as Delegate, Registry} from 'prom-client';
 
export class PromCounter extends PromMetric implements Counter<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],
    });
  }
 
  decrement(val: number, tags?: Tags): void {
    throw NotImplementedError.methodNotImplemented('decrement', PromCounter, 'Decrement is not supported in Prometheus!')
  }
 
  increment(val: number, tags: Tags = {}): void {
    const _tags = this.filterTags({ ...this.tags, ...tags });
    this.impl.inc(_tags, val);
  }
 
  reset(): void {
    this.impl.reset();
  }
 
}
 
 
export class PromCounterFactory extends CounterFactory<number> {
  protected readonly options: PromOptions;
 
  constructor(options: PromOptions) {
    super();
    this.options = { ...options };
  }
 
  counter(name: string, tags = {}): PromCounter {
    return new PromCounter(name, tags, this.options);
  }
 
}