Skip to content

Commit

Permalink
remove Gauge instrument (#791)
Browse files Browse the repository at this point in the history
* remove Gauge instrument
  • Loading branch information
mayurkale22 authored Feb 19, 2020
1 parent 218b290 commit 6616bb1
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 611 deletions.
21 changes: 2 additions & 19 deletions examples/prometheus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,23 @@ const exporter = new PrometheusExporter(

meter.addExporter(exporter);

// Monotonic counters and gauges can only be increased.
// Monotonic counters can only be increased.
const monotonicCounter = meter.createCounter('monotonic_counter', {
monotonic: true,
labelKeys: ['pid'],
description: 'Example of a monotonic counter',
});
const monotonicGauge = meter.createGauge('monotonic_gauge', {
monotonic: true,
labelKeys: ['pid'],
description: 'Example of a monotonic gauge',
});

// Non-monotonic counters and gauges can be increased or decreased.
// Non-monotonic counters can be increased or decreased.
const nonMonotonicCounter = meter.createCounter('non_monotonic_counter', {
monotonic: false,
labelKeys: ['pid'],
description: 'Example of a non-monotonic counter',
});
const nonMonotonicGauge = meter.createGauge('non_monotonic_gauge', {
monotonic: false,
labelKeys: ['pid'],
description: 'Example of a non-monotonic gauge',
});

let currentMonotonicGaugeValue = 0;
setInterval(() => {
const labels = meter.labels({ pid: process.pid });

currentMonotonicGaugeValue += Math.random();

monotonicCounter.bind(labels).add(1);
nonMonotonicCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1);
monotonicGauge.bind(labels).set(currentMonotonicGaugeValue);
nonMonotonicGauge
.bind(labels)
.set(Math.random() > 0.5 ? Math.random() * 10 : -Math.random() * 10);
}, 1000);
9 changes: 0 additions & 9 deletions packages/opentelemetry-api/src/metrics/BoundInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export interface BoundCounter {
add(value: number): void;
}

/** An Instrument for Gauge Metric. */
export interface BoundGauge {
/**
* Sets the given value. Values can be negative.
* @param value the new value.
*/
set(value: number): void;
}

/** Measure to report instantaneous measurement of a value. */
export interface BoundMeasure {
/**
Expand Down
16 changes: 3 additions & 13 deletions packages/opentelemetry-api/src/metrics/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/

import { Metric, MetricOptions, Labels, LabelSet } from './Metric';
import { BoundCounter, BoundGauge, BoundMeasure } from './BoundInstrument';
import { BoundCounter, BoundMeasure } from './BoundInstrument';

/**
* An interface to allow the recording metrics.
*
* {@link Metric}s are used for recording pre-defined aggregation (`Gauge` and
* `Counter`), or raw values (`Measure`) in which the aggregation and labels
* {@link Metric}s are used for recording pre-defined aggregation (`Counter`),
* or raw values (`Measure`) in which the aggregation and labels
* for the exported metric are deferred.
*/
export interface Meter {
Expand All @@ -41,16 +41,6 @@ export interface Meter {
*/
createCounter(name: string, options?: MetricOptions): Metric<BoundCounter>;

/**
* Creates a new `gauge` metric. Generally, this kind of metric should be used
* when the metric cannot be expressed as a sum or because the measurement
* interval is arbitrary. Use this kind of metric when the measurement is not
* a quantity, and the sum and event count are not of interest.
* @param name the name of the metric.
* @param [options] the metric options.
*/
createGauge(name: string, options?: MetricOptions): Metric<BoundGauge>;

/**
* Provide a pre-computed re-useable LabelSet by
* converting the unordered labels into a canonicalized
Expand Down
28 changes: 1 addition & 27 deletions packages/opentelemetry-api/src/metrics/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Meter } from './Meter';
import { MetricOptions, Metric, Labels, LabelSet, MetricUtils } from './Metric';
import { BoundMeasure, BoundCounter, BoundGauge } from './BoundInstrument';
import { BoundMeasure, BoundCounter } from './BoundInstrument';
import { DistributedContext } from '../distributed_context/DistributedContext';
import { SpanContext } from '../trace/span_context';

Expand Down Expand Up @@ -45,15 +45,6 @@ export class NoopMeter implements Meter {
return NOOP_COUNTER_METRIC;
}

/**
* Returns a constant gauge metric.
* @param name the name of the metric.
* @param [options] the metric options.
*/
createGauge(name: string, options?: MetricOptions): Metric<BoundGauge> {
return NOOP_GAUGE_METRIC;
}

labels(labels: Labels): LabelSet {
return NOOP_LABEL_SET;
}
Expand Down Expand Up @@ -111,13 +102,6 @@ export class NoopCounterMetric extends NoopMetric<BoundCounter>
}
}

export class NoopGaugeMetric extends NoopMetric<BoundGauge>
implements Pick<MetricUtils, 'set'> {
set(value: number, labelSet: LabelSet) {
this.bind(labelSet).set(value);
}
}

export class NoopMeasureMetric extends NoopMetric<BoundMeasure>
implements Pick<MetricUtils, 'record'> {
record(
Expand All @@ -142,12 +126,6 @@ export class NoopBoundCounter implements BoundCounter {
}
}

export class NoopBoundGauge implements BoundGauge {
set(value: number): void {
return;
}
}

export class NoopBoundMeasure implements BoundMeasure {
record(
value: number,
Expand All @@ -159,10 +137,6 @@ export class NoopBoundMeasure implements BoundMeasure {
}

export const NOOP_METER = new NoopMeter();

export const NOOP_BOUND_GAUGE = new NoopBoundGauge();
export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_BOUND_GAUGE);

export const NOOP_BOUND_COUNTER = new NoopBoundCounter();
export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_BOUND_COUNTER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import {
Labels,
NoopMeterProvider,
NOOP_BOUND_COUNTER,
NOOP_BOUND_GAUGE,
NOOP_BOUND_MEASURE,
NOOP_COUNTER_METRIC,
NOOP_GAUGE_METRIC,
NOOP_MEASURE_METRIC,
} from '../../src';

Expand Down Expand Up @@ -64,14 +62,6 @@ describe('NoopMeter', () => {
assert.strictEqual(measure.getDefaultBound(), NOOP_BOUND_MEASURE);
assert.strictEqual(measure.bind(labelSet), NOOP_BOUND_MEASURE);

const gauge = meter.createGauge('some-name');
gauge.getDefaultBound().set(1);

// ensure the correct noop const is returned
assert.strictEqual(gauge, NOOP_GAUGE_METRIC);
assert.strictEqual(gauge.getDefaultBound(), NOOP_BOUND_GAUGE);
assert.strictEqual(gauge.bind(labelSet), NOOP_BOUND_GAUGE);

const options = {
component: 'tests',
description: 'the testing package',
Expand All @@ -81,7 +71,5 @@ describe('NoopMeter', () => {
assert.strictEqual(measureWithOptions, NOOP_MEASURE_METRIC);
const counterWithOptions = meter.createCounter('some-name', options);
assert.strictEqual(counterWithOptions, NOOP_COUNTER_METRIC);
const gaugeWithOptions = meter.createGauge('some-name', options);
assert.strictEqual(gaugeWithOptions, NOOP_GAUGE_METRIC);
});
});
5 changes: 0 additions & 5 deletions packages/opentelemetry-exporter-prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ boundCounter.add(10);

// .. some other work

// Create and record Gauge
const gauge = meter.createGauge('metric_name1');
gauge.set(10, meter.labels({ [key1]: 'value1' }));
```

## Viewing your metrics

With the above you should now be able to navigate to the Prometheus UI at: http://localhost:9464/metrics
Expand Down
6 changes: 0 additions & 6 deletions packages/opentelemetry-exporter-prometheus/src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
MetricExporter,
MetricRecord,
MetricDescriptor,
LastValue,
MetricKind,
Sum,
} from '@opentelemetry/metrics';
Expand Down Expand Up @@ -140,11 +139,6 @@ export class PrometheusExporter implements MetricExporter {
this._getLabelValues(labelKeys, record.labels),
value as Sum
);
} else {
metric.set(
this._getLabelValues(labelKeys, record.labels),
(value as LastValue).value
);
}
}

Expand Down
Loading

0 comments on commit 6616bb1

Please sign in to comment.