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

Statements: 39.13% (9 / 23)      Branches: 0% (0 / 5)      Functions: 0% (0 / 3)      Lines: 39.13% (9 / 23)      Ignored: none     

All files » node/src/apm/statsd/ » statsd.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 55 56 57 58 59 60 61 62 63 64 65 66 671                     1 1 1 1   1                   1         1                                                             1        
import {
  ApmFactory,
  ApmFactoryInstance,
  ApmFeatures,
  CounterFactory,
  GaugeFactory,
  HistogramFactory,
  InvalidArg,
  Providers,
  TimerWrapperFactory,
} from '@btilford/ts-base-core';
import {StatsD} from 'hot-shots';
import {StatsDCounterFactory} from './counter';
import {StatsDGaugeFactory} from './gauge';
import {StatsDHistogramFactory} from './histogram';
import {StatsDOptions} from './metric';
import {StatsDTimerFactory} from './timer';
 
 
export type StatsDFeature = {
  name: ApmFeatures;
 
  options?: StatsDOptions;
}
 
 
export function registerStatsD(statsd: StatsD): void {
  Providers.register(statsd, StatsD);
}
 
 
export function createStatsDFeature(feature: StatsDFeature): [ApmFactory<any>, ApmFactoryInstance<any, any>] {
  let result: [ApmFactory<any>, ApmFactoryInstance<any, any>];
  // const proto: T = APM_ENV[feature.name].type;
  switch (feature.name) {
    case 'counter':
      result = [
        CounterFactory,
        new StatsDCounterFactory(feature.options),
      ];
      break;
    case 'histogram':
      result = [HistogramFactory, new StatsDHistogramFactory(feature.options)];
      break;
    case 'gauge':
      result = [GaugeFactory, new StatsDGaugeFactory(feature.options)];
      break;
    case 'timer':
      result = [TimerWrapperFactory, new StatsDTimerFactory(feature.options)];
      break;
    default:
      throw InvalidArg.expected(
        'name',
        feature.name,
        ['counter'],
      );
  }
  return result;
 
}
 
 
export function registerStatsDFeature(feature: StatsDFeature): void {
  const [base, impl] = createStatsDFeature(feature);
  Providers.register(impl, base);
}