Skip to content

Commit 0c1d840

Browse files
authoredApr 18, 2023
Refactor: Rename method & variables for better readability (GoogleCloudPlatform#233)
1 parent 96beabd commit 0c1d840

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed
 

‎exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
*/
4747
public final class AggregateByLabelMetricTimeSeriesBuilder implements MetricTimeSeriesBuilder {
4848

49-
public static final String LABEL_INSTRUMENTATION_LIBRARY_NAME = "instrumentation_source";
50-
public static final String LABEL_INSTRUMENTATION_LIBRARY_VERSION = "instrumentation_version";
49+
public static final String LABEL_INSTRUMENTATION_SOURCE =
50+
"instrumentation_source"; // name of the instrumentation source
51+
public static final String LABEL_INSTRUMENTATION_VERSION =
52+
"instrumentation_version"; // version of the instrumentation source
5153

5254
private final Map<String, MetricDescriptor> descriptors = new HashMap<>();
5355
private final Map<MetricWithLabels, TimeSeries.Builder> pendingTimeSeries = new HashMap<>();
@@ -61,7 +63,7 @@ public AggregateByLabelMetricTimeSeriesBuilder(String projectId, String prefix)
6163

6264
@Override
6365
public void recordPoint(MetricData metricData, LongPointData pointData) {
64-
recordPoint(
66+
recordPointInTimeSeries(
6567
metricData,
6668
pointData,
6769
Point.newBuilder()
@@ -72,7 +74,7 @@ public void recordPoint(MetricData metricData, LongPointData pointData) {
7274

7375
@Override
7476
public void recordPoint(MetricData metricData, DoublePointData pointData) {
75-
recordPoint(
77+
recordPointInTimeSeries(
7678
metricData,
7779
pointData,
7880
Point.newBuilder()
@@ -83,7 +85,7 @@ public void recordPoint(MetricData metricData, DoublePointData pointData) {
8385

8486
@Override
8587
public void recordPoint(MetricData metricData, HistogramPointData pointData) {
86-
recordPoint(
88+
recordPointInTimeSeries(
8789
metricData,
8890
pointData,
8991
Point.newBuilder()
@@ -93,7 +95,7 @@ public void recordPoint(MetricData metricData, HistogramPointData pointData) {
9395
.build());
9496
}
9597

96-
private void recordPoint(MetricData metric, PointData point, Point builtPoint) {
98+
private void recordPointInTimeSeries(MetricData metric, PointData point, Point builtPoint) {
9799
MetricDescriptor descriptor = mapMetricDescriptor(this.prefix, metric, point);
98100
if (descriptor == null) {
99101
// Unsupported type.
@@ -121,10 +123,10 @@ private Attributes attachInstrumentationLibraryLabels(
121123
Attributes attributes, InstrumentationScopeInfo instrumentationScopeInfo) {
122124
return attributes.toBuilder()
123125
.put(
124-
AttributeKey.stringKey(LABEL_INSTRUMENTATION_LIBRARY_NAME),
126+
AttributeKey.stringKey(LABEL_INSTRUMENTATION_SOURCE),
125127
instrumentationScopeInfo.getName())
126128
.put(
127-
AttributeKey.stringKey(LABEL_INSTRUMENTATION_LIBRARY_VERSION),
129+
AttributeKey.stringKey(LABEL_INSTRUMENTATION_VERSION),
128130
Objects.requireNonNullElse(instrumentationScopeInfo.getVersion(), ""))
129131
.build();
130132
}
@@ -136,6 +138,8 @@ public Collection<MetricDescriptor> getDescriptors() {
136138

137139
@Override
138140
public List<TimeSeries> getTimeSeries() {
139-
return pendingTimeSeries.values().stream().map(b -> b.build()).collect(Collectors.toList());
141+
return pendingTimeSeries.values().stream()
142+
.map(TimeSeries.Builder::build)
143+
.collect(Collectors.toList());
140144
}
141145
}

‎exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/GoogleCloudMetricExporterTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package com.google.cloud.opentelemetry.metric;
1717

18-
import static com.google.cloud.opentelemetry.metric.AggregateByLabelMetricTimeSeriesBuilder.LABEL_INSTRUMENTATION_LIBRARY_NAME;
19-
import static com.google.cloud.opentelemetry.metric.AggregateByLabelMetricTimeSeriesBuilder.LABEL_INSTRUMENTATION_LIBRARY_VERSION;
18+
import static com.google.cloud.opentelemetry.metric.AggregateByLabelMetricTimeSeriesBuilder.LABEL_INSTRUMENTATION_SOURCE;
19+
import static com.google.cloud.opentelemetry.metric.AggregateByLabelMetricTimeSeriesBuilder.LABEL_INSTRUMENTATION_VERSION;
2020
import static com.google.cloud.opentelemetry.metric.FakeData.aCloudZone;
2121
import static com.google.cloud.opentelemetry.metric.FakeData.aDoubleSummaryPoint;
2222
import static com.google.cloud.opentelemetry.metric.FakeData.aFakeCredential;
@@ -192,8 +192,8 @@ public void testExportSucceeds() {
192192
.setType(expectedDescriptor.getType())
193193
.putLabels("label1", "value1")
194194
.putLabels("label2", "false")
195-
.putLabels(LABEL_INSTRUMENTATION_LIBRARY_NAME, "instrumentName")
196-
.putLabels(LABEL_INSTRUMENTATION_LIBRARY_VERSION, "0")
195+
.putLabels(LABEL_INSTRUMENTATION_SOURCE, "instrumentName")
196+
.putLabels(LABEL_INSTRUMENTATION_VERSION, "0")
197197
.build())
198198
.addPoints(expectedPoint)
199199
.setMetricKind(expectedDescriptor.getMetricKind())

0 commit comments

Comments
 (0)