From 39d4ba307a4b7f0639428c03a156180282dc1931 Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 3 Dec 2020 00:40:42 +0100 Subject: [PATCH] Metrics updates (#1700) * feat: renaming batcher to processor, fixing aggregators, adding missing metrics in api * chore: fixing metrics in exporter collector, updated tests, fixing observer result * chore: refactoring tests for rest of collectors * chore: fixing monotonic sum observer, updated test to cover that scenario correctly --- api/src/metrics/Meter.ts | 26 ++++++++++++++++++++++++++ api/src/metrics/NoopMeter.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/api/src/metrics/Meter.ts b/api/src/metrics/Meter.ts index eb570a48027..1f8e63c803a 100644 --- a/api/src/metrics/Meter.ts +++ b/api/src/metrics/Meter.ts @@ -23,6 +23,8 @@ import { BatchObserver, BatchMetricOptions, UpDownCounter, + SumObserver, + UpDownSumObserver, } from './Metric'; import { ObserverResult } from './ObserverResult'; @@ -81,6 +83,30 @@ export interface Meter { callback?: (observerResult: ObserverResult) => void ): ValueObserver; + /** + * Creates a new `SumObserver` metric. + * @param name the name of the metric. + * @param [options] the metric options. + * @param [callback] the observer callback + */ + createSumObserver( + name: string, + options?: MetricOptions, + callback?: (observerResult: ObserverResult) => void + ): SumObserver; + + /** + * Creates a new `UpDownSumObserver` metric. + * @param name the name of the metric. + * @param [options] the metric options. + * @param [callback] the observer callback + */ + createUpDownSumObserver( + name: string, + options?: MetricOptions, + callback?: (observerResult: ObserverResult) => void + ): UpDownSumObserver; + /** * Creates a new `BatchObserver` metric, can be used to update many metrics * at the same time and when operations needs to be async diff --git a/api/src/metrics/NoopMeter.ts b/api/src/metrics/NoopMeter.ts index d59d658b1e3..06eabc197d0 100644 --- a/api/src/metrics/NoopMeter.ts +++ b/api/src/metrics/NoopMeter.ts @@ -26,6 +26,7 @@ import { BatchObserver, UpDownCounter, BaseObserver, + UpDownSumObserver, } from './Metric'; import { BoundValueRecorder, @@ -84,6 +85,34 @@ export class NoopMeter implements Meter { return NOOP_VALUE_OBSERVER_METRIC; } + /** + * Returns constant noop sum observer. + * @param name the name of the metric. + * @param [options] the metric options. + * @param [callback] the sum observer callback + */ + createSumObserver( + _name: string, + _options?: MetricOptions, + _callback?: (observerResult: ObserverResult) => void + ): ValueObserver { + return NOOP_SUM_OBSERVER_METRIC; + } + + /** + * Returns constant noop up down sum observer. + * @param name the name of the metric. + * @param [options] the metric options. + * @param [callback] the up down sum observer callback + */ + createUpDownSumObserver( + _name: string, + _options?: MetricOptions, + _callback?: (observerResult: ObserverResult) => void + ): UpDownSumObserver { + return NOOP_UP_DOWN_SUM_OBSERVER_METRIC; + } + /** * Returns constant noop batch observer. * @param name the name of the metric.