26
26
import io .grpc .LongCounterMetricInstrument ;
27
27
import io .grpc .LongGaugeMetricInstrument ;
28
28
import io .grpc .LongHistogramMetricInstrument ;
29
+ import io .grpc .LongUpDownCounterMetricInstrument ;
29
30
import io .grpc .MetricInstrument ;
30
31
import io .grpc .MetricInstrumentRegistry ;
31
32
import io .grpc .MetricRecorder ;
@@ -82,7 +83,7 @@ public void addDoubleCounter(DoubleCounterMetricInstrument metricInstrument, dou
82
83
* Records a long counter value.
83
84
*
84
85
* @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.
86
87
* @param requiredLabelValues the required label values for the metric.
87
88
* @param optionalLabelValues the optional label values for the metric.
88
89
*/
@@ -103,6 +104,32 @@ public void addLongCounter(LongCounterMetricInstrument metricInstrument, long va
103
104
}
104
105
}
105
106
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
+
106
133
/**
107
134
* Records a double histogram value.
108
135
*
0 commit comments