Skip to content

Commit

Permalink
refactor: batch observer to be independent from metric types (open-te…
Browse files Browse the repository at this point in the history
…lemetry#1709)

* refactor: batch observer to be independent from metric types

- BatchObservers do not have to be created with names
- BatchObservers do not have instruments for their own

* fixup: nodejs v8 compatibilities

* fixup: replace all batch observer metric occurrences with batch observer
  • Loading branch information
legendecas authored and dyladan committed Feb 18, 2021
1 parent ecf6eb7 commit 74fb1e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
13 changes: 5 additions & 8 deletions api/src/metrics/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
Counter,
ValueRecorder,
ValueObserver,
BatchObserver,
BatchMetricOptions,
BatchObserverOptions,
UpDownCounter,
SumObserver,
UpDownSumObserver,
Expand Down Expand Up @@ -108,15 +107,13 @@ export interface Meter {
): UpDownSumObserver;

/**
* Creates a new `BatchObserver` metric, can be used to update many metrics
* Creates a new `BatchObserver`, can be used to update many metrics
* at the same time and when operations needs to be async
* @param name the name of the metric.
* @param callback the batch observer callback
* @param [options] the metric batch options.
* @param [options] the batch observer options.
*/
createBatchObserver(
name: string,
callback: (batchObserverResult: BatchObserverResult) => void,
options?: BatchMetricOptions
): BatchObserver;
options?: BatchObserverOptions
): void;
}
10 changes: 6 additions & 4 deletions api/src/metrics/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ export interface MetricOptions {
boundaries?: number[];
}

export interface BatchMetricOptions extends MetricOptions {
export interface BatchObserverOptions {
/**
* Indicates how long the batch metric should wait to update before cancel
*/
maxTimeoutUpdateMS?: number;

/**
* User provided logger.
*/
logger?: Logger;
}

/** The Type of value. It describes how the data is reported. */
Expand Down Expand Up @@ -166,9 +171,6 @@ export type UpDownSumObserver = BaseObserver;
/** Base interface for the SumObserver metrics. */
export type SumObserver = BaseObserver;

/** Base interface for the Batch Observer metrics. */
export type BatchObserver = Metric;

/**
* key-value pairs passed by the user.
*/
Expand Down
12 changes: 4 additions & 8 deletions api/src/metrics/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
Counter,
ValueRecorder,
ValueObserver,
BatchObserver,
UpDownCounter,
BaseObserver,
UpDownSumObserver,
Expand Down Expand Up @@ -119,10 +118,9 @@ export class NoopMeter implements Meter {
* @param callback the batch observer callback
*/
createBatchObserver(
_name: string,
_callback: (batchObserverResult: BatchObserverResult) => void
): BatchObserver {
return NOOP_BATCH_OBSERVER_METRIC;
): NoopBatchObserver {
return NOOP_BATCH_OBSERVER;
}
}

Expand Down Expand Up @@ -187,9 +185,7 @@ export class NoopBaseObserverMetric
}
}

export class NoopBatchObserverMetric
extends NoopMetric<void>
implements BatchObserver {}
export class NoopBatchObserver {}

export class NoopBoundCounter implements BoundCounter {
add(_value: number): void {
Expand Down Expand Up @@ -229,4 +225,4 @@ export const NOOP_SUM_OBSERVER_METRIC = new NoopBaseObserverMetric(
NOOP_BOUND_BASE_OBSERVER
);

export const NOOP_BATCH_OBSERVER_METRIC = new NoopBatchObserverMetric();
export const NOOP_BATCH_OBSERVER = new NoopBatchObserver();

0 comments on commit 74fb1e8

Please sign in to comment.