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

grpc / grpc-java / #19177

26 Apr 2024 08:47PM UTC coverage: 88.288% (+0.2%) from 88.068%
#19177

push

github

web-flow
Add MetricRecorder implementation (#11128)

* added MetricRecorderImpl and unit tests for MetricInstrumentRegistry

* updated MetricInstrumentRegistry to use array instead of ArrayList

* renamed record<>Counter APIs to add<>Counter. Added check for mismatched label values

* added lock for instruments array

31381 of 35544 relevant lines covered (88.29%)

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.Set;
21

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

28
  /**
29
   * Returns a set of names for the metrics that are currently enabled for this `MetricSink`.
30
   *
31
   * @return A set of enabled metric names.
32
   */
33
  Set<String> getEnabledMetrics();
34

35
  /**
36
   * Returns a list of label names that are considered optional for metrics collected by this
37
   * `MetricSink`.
38
   *
39
   * @return A list of optional label names.
40
   */
41
  List<String> getOptionalLabels();
42

43
  /**
44
   * Returns a list 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 A list of metric measures.
49
   */
50
  List<Object> getMetricsMeasures();
51

52
  /**
53
   * Records a value for a double-precision counter associated with specified metric instrument.
54
   *
55
   * @param metricInstrument The counter metric instrument identifies metric measure to record.
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 recordDoubleCounter(DoubleCounterMetricInstrument metricInstrument, double value,
61
      List<String> requiredLabelValues, List<String> optionalLabelValues) {
62
  }
×
63

64
  /**
65
   * Records 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 record.
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 recordLongCounter(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
  default void updateMeasures(List<MetricInstrument> instruments) {}
×
103
}
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