Skip to content

Commit 5af32b4

Browse files
committed
otel: add LongUpDownCounterMetricInstrument
1 parent 8aabda5 commit 5af32b4

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

core/src/main/java/io/grpc/internal/MetricRecorderImpl.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.grpc.LongCounterMetricInstrument;
2727
import io.grpc.LongGaugeMetricInstrument;
2828
import io.grpc.LongHistogramMetricInstrument;
29+
import io.grpc.LongUpDownCounterMetricInstrument;
2930
import io.grpc.MetricInstrument;
3031
import io.grpc.MetricInstrumentRegistry;
3132
import io.grpc.MetricRecorder;
@@ -82,7 +83,7 @@ public void addDoubleCounter(DoubleCounterMetricInstrument metricInstrument, dou
8283
* Records a long counter value.
8384
*
8485
* @param metricInstrument the {@link LongCounterMetricInstrument} to record.
85-
* @param value the value to record.
86+
* @param value the value to record. Must be non-negative.
8687
* @param requiredLabelValues the required label values for the metric.
8788
* @param optionalLabelValues the optional label values for the metric.
8889
*/
@@ -103,6 +104,32 @@ public void addLongCounter(LongCounterMetricInstrument metricInstrument, long va
103104
}
104105
}
105106

107+
/**
108+
* Adds a long up down counter value.
109+
*
110+
* @param metricInstrument the {@link io.grpc.LongUpDownCounterMetricInstrument} to record.
111+
* @param value the value to record. May be positive, negative or zero.
112+
* @param requiredLabelValues the required label values for the metric.
113+
* @param optionalLabelValues the optional label values for the metric.
114+
*/
115+
@Override
116+
public void addLongUpDownCounter(LongUpDownCounterMetricInstrument metricInstrument, long value,
117+
List<String> requiredLabelValues,
118+
List<String> optionalLabelValues) {
119+
MetricRecorder.super.addLongUpDownCounter(metricInstrument, value, requiredLabelValues,
120+
optionalLabelValues);
121+
for (MetricSink sink : metricSinks) {
122+
int measuresSize = sink.getMeasuresSize();
123+
if (measuresSize <= metricInstrument.getIndex()) {
124+
// Measures may need updating in two cases:
125+
// 1. When the sink is initially created with an empty list of measures.
126+
// 2. When new metric instruments are registered, requiring the sink to accommodate them.
127+
sink.updateMeasures(registry.getMetricInstruments());
128+
}
129+
sink.addLongUpDownCounter(metricInstrument, value, requiredLabelValues, optionalLabelValues);
130+
}
131+
}
132+
106133
/**
107134
* Records a double histogram value.
108135
*

0 commit comments

Comments
 (0)