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

Statements: 42.11% (8 / 19)      Branches: 0% (0 / 5)      Functions: 0% (0 / 2)      Lines: 42.11% (8 / 19)      Ignored: none     

All files » node/src/apm/prometheus/ » prometheus.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 48 49 50 51 52 53 54 551               1 1 1 1   1                           1       1                                              
import {
  CounterFactory,
  GaugeFactory,
  HistogramFactory,
  InvalidArg,
  Providers,
  TimerWrapperFactory
} from '@btilford/ts-base-core';
import {PromCounterFactory} from './counter';
import {PromHistogramFactory} from './histogram';
import {PromGaugeFactory} from './gauge';
import {PromTimerWrapperFactory} from './timer';
import {PromOptions} from './metric';
import {Registry} from 'prom-client';
 
 
export type PromFeature = {
  name: 'counter'
    | 'histogram'
    | 'gauge'
    | 'timer';
 
  enabled: boolean;
  options: PromOptions;
  prefix?: string;
}
 
export function registerRootRegistry(registry: Registry): void {
  Providers.register(registry, Registry);
}
 
export function registerPrometheusFeature(feature: PromFeature): void {
 
  switch (feature.name) {
    case 'counter':
      Providers.register(new PromCounterFactory(feature.options), CounterFactory);
      break;
    case 'histogram':
      Providers.register(new PromHistogramFactory(feature.options), HistogramFactory);
      break;
    case 'gauge':
      Providers.register(new PromGaugeFactory(feature.options), GaugeFactory);
      break;
    case 'timer':
      Providers.register(new PromTimerWrapperFactory(feature.options), TimerWrapperFactory);
      break;
    default:
      throw InvalidArg.expected(
        'name',
        feature.name,
        ['counter', 'timer', 'histogram', 'gauge']
      );
  }
}