• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19217

09 May 2024 02:28AM UTC coverage: 88.358% (-0.01%) from 88.369%
#19217

push

github

ejona86
Add gauge metric API and Otel implementation

This is needed by gRFC A78 for xds metrics, and for RLS metrics. Since
gauges need to acquire a lock (or other synchronization) in the
callback, the callback allows batching multiple gauges together to avoid
acquiring-and-requiring such locks.

Unlike other metrics, gauges are reported on-demand to the MetricSink.
This means not all sinks will receive the same data, as the sinks will
ask for the gauges at different times.

31566 of 35725 relevant lines covered (88.36%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/../api/src/main/java/io/grpc/MetricSink.java
1
/*
2
 * Copyright 2024 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc;
18

19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22

23
/**
24
 * An internal interface representing a receiver or aggregator of gRPC metrics data.
25
 */
26
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110")
27
public interface MetricSink {
28

29
  /**
30
   * Returns a set of names for the metrics that are currently enabled or disabled.
31
   *
32
   * @return A set of enabled metric names.
33
   */
34
  Map<String, Boolean> getEnabledMetrics();
35

36
  /**
37
   * Returns a set of optional label names for metrics that the sink actually wants.
38
   *
39
   * @return A set of optional label names.
40
   */
41
  Set<String> getOptionalLabels();
42

43
  /**
44
   * Returns size of metric measures used to record metric values. These measures are created
45
   * based on registered metrics (via MetricInstrumentRegistry) and are ordered according to their
46
   * registration sequence.
47
   *
48
   * @return Size of metric measures.
49
   */
50
  int getMeasuresSize();
51

52
  /**
53
   * Adds a value for a double-precision counter associated with specified metric instrument.
54
   *
55
   * @param metricInstrument The counter metric instrument identifies metric measure to add.
56
   * @param value The value to record.
57
   * @param requiredLabelValues A list of required label values for the metric.
58
   * @param optionalLabelValues A list of additional, optional label values for the metric.
59
   */
60
  default void addDoubleCounter(DoubleCounterMetricInstrument metricInstrument, double value,
61
      List<String> requiredLabelValues, List<String> optionalLabelValues) {
62
  }
×
63

64
  /**
65
   * Adds a value for a long valued counter metric associated with specified metric instrument.
66
   *
67
   * @param metricInstrument The counter metric instrument identifies metric measure to add.
68
   * @param value The value to record.
69
   * @param requiredLabelValues A list of required label values for the metric.
70
   * @param optionalLabelValues A list of additional, optional label values for the metric.
71
   */
72
  default void addLongCounter(LongCounterMetricInstrument metricInstrument, long value,
73
      List<String> requiredLabelValues, List<String> optionalLabelValues) {
74
  }
×
75

76
  /**
77
   * Records a value for a double-precision histogram metric associated with specified metric
78
   * instrument.
79
   *
80
   * @param metricInstrument The histogram metric instrument identifies metric measure to record.
81
   * @param value The value to record.
82
   * @param requiredLabelValues A list of required label values for the metric.
83
   * @param optionalLabelValues A list of additional, optional label values for the metric.
84
   */
85
  default void recordDoubleHistogram(DoubleHistogramMetricInstrument metricInstrument, double value,
86
      List<String> requiredLabelValues, List<String> optionalLabelValues) {
87
  }
×
88

89
  /**
90
   * Records a value for a long valued histogram metric associated with specified metric
91
   * instrument.
92
   *
93
   * @param metricInstrument The histogram metric instrument identifies metric measure to record.
94
   * @param value The value to record.
95
   * @param requiredLabelValues A list of required label values for the metric.
96
   * @param optionalLabelValues A list of additional, optional label values for the metric.
97
   */
98
  default void recordLongHistogram(LongHistogramMetricInstrument metricInstrument, long value,
99
      List<String> requiredLabelValues, List<String> optionalLabelValues) {
100
  }
×
101

102
  /**
103
   * Record a long gauge value.
104
   *
105
   * @param value The value to record.
106
   * @param requiredLabelValues A list of required label values for the metric.
107
   * @param optionalLabelValues A list of additional, optional label values for the metric.
108
   */
109
  default void recordLongGauge(LongGaugeMetricInstrument metricInstrument, long value,
110
      List<String> requiredLabelValues, List<String> optionalLabelValues){
111
  }
×
112

113
  /**
114
   * Registers a callback to produce metric values for only the listed instruments. The returned
115
   * registration must be closed when no longer needed, which will remove the callback.
116
   *
117
   * @param callback The callback to call to record.
118
   * @param metricInstruments The metric instruments the callback will record against.
119
   */
120
  default Registration registerBatchCallback(Runnable callback,
121
      CallbackMetricInstrument... metricInstruments) {
122
    return () -> { };
×
123
  }
124

125
  interface Registration extends MetricRecorder.Registration {}
126

127
  void updateMeasures(List<MetricInstrument> instruments);
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc