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);
}
|