Skip to content

Commit 6616bb1

Browse files
authored
remove Gauge instrument (open-telemetry#791)
* remove Gauge instrument
1 parent 218b290 commit 6616bb1

File tree

18 files changed

+45
-611
lines changed

18 files changed

+45
-611
lines changed

examples/prometheus/index.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,23 @@ const exporter = new PrometheusExporter(
1616

1717
meter.addExporter(exporter);
1818

19-
// Monotonic counters and gauges can only be increased.
19+
// Monotonic counters can only be increased.
2020
const monotonicCounter = meter.createCounter('monotonic_counter', {
2121
monotonic: true,
2222
labelKeys: ['pid'],
2323
description: 'Example of a monotonic counter',
2424
});
25-
const monotonicGauge = meter.createGauge('monotonic_gauge', {
26-
monotonic: true,
27-
labelKeys: ['pid'],
28-
description: 'Example of a monotonic gauge',
29-
});
3025

31-
// Non-monotonic counters and gauges can be increased or decreased.
26+
// Non-monotonic counters can be increased or decreased.
3227
const nonMonotonicCounter = meter.createCounter('non_monotonic_counter', {
3328
monotonic: false,
3429
labelKeys: ['pid'],
3530
description: 'Example of a non-monotonic counter',
3631
});
37-
const nonMonotonicGauge = meter.createGauge('non_monotonic_gauge', {
38-
monotonic: false,
39-
labelKeys: ['pid'],
40-
description: 'Example of a non-monotonic gauge',
41-
});
4232

43-
let currentMonotonicGaugeValue = 0;
4433
setInterval(() => {
4534
const labels = meter.labels({ pid: process.pid });
4635

47-
currentMonotonicGaugeValue += Math.random();
48-
4936
monotonicCounter.bind(labels).add(1);
5037
nonMonotonicCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1);
51-
monotonicGauge.bind(labels).set(currentMonotonicGaugeValue);
52-
nonMonotonicGauge
53-
.bind(labels)
54-
.set(Math.random() > 0.5 ? Math.random() * 10 : -Math.random() * 10);
5538
}, 1000);

packages/opentelemetry-api/src/metrics/BoundInstrument.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ export interface BoundCounter {
2626
add(value: number): void;
2727
}
2828

29-
/** An Instrument for Gauge Metric. */
30-
export interface BoundGauge {
31-
/**
32-
* Sets the given value. Values can be negative.
33-
* @param value the new value.
34-
*/
35-
set(value: number): void;
36-
}
37-
3829
/** Measure to report instantaneous measurement of a value. */
3930
export interface BoundMeasure {
4031
/**

packages/opentelemetry-api/src/metrics/Meter.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616

1717
import { Metric, MetricOptions, Labels, LabelSet } from './Metric';
18-
import { BoundCounter, BoundGauge, BoundMeasure } from './BoundInstrument';
18+
import { BoundCounter, BoundMeasure } from './BoundInstrument';
1919

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

44-
/**
45-
* Creates a new `gauge` metric. Generally, this kind of metric should be used
46-
* when the metric cannot be expressed as a sum or because the measurement
47-
* interval is arbitrary. Use this kind of metric when the measurement is not
48-
* a quantity, and the sum and event count are not of interest.
49-
* @param name the name of the metric.
50-
* @param [options] the metric options.
51-
*/
52-
createGauge(name: string, options?: MetricOptions): Metric<BoundGauge>;
53-
5444
/**
5545
* Provide a pre-computed re-useable LabelSet by
5646
* converting the unordered labels into a canonicalized

packages/opentelemetry-api/src/metrics/NoopMeter.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { Meter } from './Meter';
1818
import { MetricOptions, Metric, Labels, LabelSet, MetricUtils } from './Metric';
19-
import { BoundMeasure, BoundCounter, BoundGauge } from './BoundInstrument';
19+
import { BoundMeasure, BoundCounter } from './BoundInstrument';
2020
import { DistributedContext } from '../distributed_context/DistributedContext';
2121
import { SpanContext } from '../trace/span_context';
2222

@@ -45,15 +45,6 @@ export class NoopMeter implements Meter {
4545
return NOOP_COUNTER_METRIC;
4646
}
4747

48-
/**
49-
* Returns a constant gauge metric.
50-
* @param name the name of the metric.
51-
* @param [options] the metric options.
52-
*/
53-
createGauge(name: string, options?: MetricOptions): Metric<BoundGauge> {
54-
return NOOP_GAUGE_METRIC;
55-
}
56-
5748
labels(labels: Labels): LabelSet {
5849
return NOOP_LABEL_SET;
5950
}
@@ -111,13 +102,6 @@ export class NoopCounterMetric extends NoopMetric<BoundCounter>
111102
}
112103
}
113104

114-
export class NoopGaugeMetric extends NoopMetric<BoundGauge>
115-
implements Pick<MetricUtils, 'set'> {
116-
set(value: number, labelSet: LabelSet) {
117-
this.bind(labelSet).set(value);
118-
}
119-
}
120-
121105
export class NoopMeasureMetric extends NoopMetric<BoundMeasure>
122106
implements Pick<MetricUtils, 'record'> {
123107
record(
@@ -142,12 +126,6 @@ export class NoopBoundCounter implements BoundCounter {
142126
}
143127
}
144128

145-
export class NoopBoundGauge implements BoundGauge {
146-
set(value: number): void {
147-
return;
148-
}
149-
}
150-
151129
export class NoopBoundMeasure implements BoundMeasure {
152130
record(
153131
value: number,
@@ -159,10 +137,6 @@ export class NoopBoundMeasure implements BoundMeasure {
159137
}
160138

161139
export const NOOP_METER = new NoopMeter();
162-
163-
export const NOOP_BOUND_GAUGE = new NoopBoundGauge();
164-
export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_BOUND_GAUGE);
165-
166140
export const NOOP_BOUND_COUNTER = new NoopBoundCounter();
167141
export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_BOUND_COUNTER);
168142

packages/opentelemetry-api/test/noop-implementations/noop-meter.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import {
1919
Labels,
2020
NoopMeterProvider,
2121
NOOP_BOUND_COUNTER,
22-
NOOP_BOUND_GAUGE,
2322
NOOP_BOUND_MEASURE,
2423
NOOP_COUNTER_METRIC,
25-
NOOP_GAUGE_METRIC,
2624
NOOP_MEASURE_METRIC,
2725
} from '../../src';
2826

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

67-
const gauge = meter.createGauge('some-name');
68-
gauge.getDefaultBound().set(1);
69-
70-
// ensure the correct noop const is returned
71-
assert.strictEqual(gauge, NOOP_GAUGE_METRIC);
72-
assert.strictEqual(gauge.getDefaultBound(), NOOP_BOUND_GAUGE);
73-
assert.strictEqual(gauge.bind(labelSet), NOOP_BOUND_GAUGE);
74-
7565
const options = {
7666
component: 'tests',
7767
description: 'the testing package',
@@ -81,7 +71,5 @@ describe('NoopMeter', () => {
8171
assert.strictEqual(measureWithOptions, NOOP_MEASURE_METRIC);
8272
const counterWithOptions = meter.createCounter('some-name', options);
8373
assert.strictEqual(counterWithOptions, NOOP_COUNTER_METRIC);
84-
const gaugeWithOptions = meter.createGauge('some-name', options);
85-
assert.strictEqual(gaugeWithOptions, NOOP_GAUGE_METRIC);
8674
});
8775
});

packages/opentelemetry-exporter-prometheus/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ boundCounter.add(10);
4343

4444
// .. some other work
4545

46-
// Create and record Gauge
47-
const gauge = meter.createGauge('metric_name1');
48-
gauge.set(10, meter.labels({ [key1]: 'value1' }));
49-
```
50-
5146
## Viewing your metrics
5247

5348
With the above you should now be able to navigate to the Prometheus UI at: http://localhost:9464/metrics

packages/opentelemetry-exporter-prometheus/src/prometheus.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
MetricExporter,
2121
MetricRecord,
2222
MetricDescriptor,
23-
LastValue,
2423
MetricKind,
2524
Sum,
2625
} from '@opentelemetry/metrics';
@@ -140,11 +139,6 @@ export class PrometheusExporter implements MetricExporter {
140139
this._getLabelValues(labelKeys, record.labels),
141140
value as Sum
142141
);
143-
} else {
144-
metric.set(
145-
this._getLabelValues(labelKeys, record.labels),
146-
(value as LastValue).value
147-
);
148142
}
149143
}
150144

0 commit comments

Comments
 (0)