Skip to content

Commit 679dd73

Browse files
committed
polish: restructuring TestMetricData api.
1 parent be8fb11 commit 679dd73

File tree

5 files changed

+133
-61
lines changed

5 files changed

+133
-61
lines changed
Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
Comparing source compatibility of opentelemetry-sdk-metrics-1.50.0-SNAPSHOT.jar against opentelemetry-sdk-metrics-1.49.0.jar
2-
No changes.
2+
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.DelegatingMetricData (not serializable)
3+
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
4+
+++ NEW INTERFACE: io.opentelemetry.sdk.metrics.data.MetricData
5+
+++ NEW SUPERCLASS: java.lang.Object
6+
+++ NEW METHOD: PUBLIC(+) boolean equals(java.lang.Object)
7+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.metrics.data.Data<?> getData()
8+
+++ NEW METHOD: PUBLIC(+) java.lang.String getDescription()
9+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.InstrumentationScopeInfo getInstrumentationScopeInfo()
10+
+++ NEW METHOD: PUBLIC(+) java.lang.String getName()
11+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.Resource getResource()
12+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.metrics.data.MetricDataType getType()
13+
+++ NEW METHOD: PUBLIC(+) java.lang.String getUnit()
14+
+++ NEW METHOD: PUBLIC(+) int hashCode()
15+
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
16+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.DoubleExemplarData (not serializable)
17+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
18+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.DoubleExemplarData create(io.opentelemetry.api.common.Attributes, long, io.opentelemetry.api.trace.SpanContext, double)
19+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.DoublePointData (not serializable)
20+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
21+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.DoublePointData create(long, long, io.opentelemetry.api.common.Attributes, double, java.util.List<io.opentelemetry.sdk.metrics.data.DoubleExemplarData>)
22+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets (not serializable)
23+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
24+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets create(int, int, java.util.List<java.lang.Long>)
25+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ExponentialHistogramData (not serializable)
26+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
27+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramData create(io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData>)
28+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData (not serializable)
29+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
30+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData create(int, double, long, boolean, double, boolean, double, io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets, io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets, long, long, io.opentelemetry.api.common.Attributes, java.util.List<io.opentelemetry.sdk.metrics.data.DoubleExemplarData>)
31+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.GaugeData (not serializable)
32+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
33+
GENERIC TEMPLATES: === T:io.opentelemetry.sdk.metrics.data.PointData
34+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.GaugeData<io.opentelemetry.sdk.metrics.data.DoublePointData> createDoubleGaugeData(java.util.Collection<io.opentelemetry.sdk.metrics.data.DoublePointData>)
35+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.GaugeData<io.opentelemetry.sdk.metrics.data.LongPointData> createLongGaugeData(java.util.Collection<io.opentelemetry.sdk.metrics.data.LongPointData>)
36+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.HistogramData (not serializable)
37+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
38+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.HistogramData create(io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<io.opentelemetry.sdk.metrics.data.HistogramPointData>)
39+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.HistogramPointData (not serializable)
40+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
41+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.HistogramPointData create(long, long, io.opentelemetry.api.common.Attributes, double, boolean, double, boolean, double, java.util.List<java.lang.Double>, java.util.List<java.lang.Long>)
42+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.LongExemplarData (not serializable)
43+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
44+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.LongExemplarData create(io.opentelemetry.api.common.Attributes, long, io.opentelemetry.api.trace.SpanContext, long)
45+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.LongPointData (not serializable)
46+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
47+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.LongPointData create(long, long, io.opentelemetry.api.common.Attributes, long)
48+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.SumData (not serializable)
49+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
50+
GENERIC TEMPLATES: === T:io.opentelemetry.sdk.metrics.data.PointData
51+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.SumData<io.opentelemetry.sdk.metrics.data.DoublePointData> createDoubleSumData(boolean, io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<io.opentelemetry.sdk.metrics.data.DoublePointData>)
52+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.SumData<io.opentelemetry.sdk.metrics.data.LongPointData> createLongSumData(boolean, io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<io.opentelemetry.sdk.metrics.data.LongPointData>)
53+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.SummaryData (not serializable)
54+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
55+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.SummaryData create(java.util.Collection<io.opentelemetry.sdk.metrics.data.SummaryPointData>)
56+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.SummaryPointData (not serializable)
57+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
58+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.SummaryPointData create(long, long, io.opentelemetry.api.common.Attributes, long, double, java.util.List<io.opentelemetry.sdk.metrics.data.ValueAtQuantile>)
59+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ValueAtQuantile (not serializable)
60+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
61+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ValueAtQuantile create(double, double)
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
Comparing source compatibility of opentelemetry-sdk-testing-1.50.0-SNAPSHOT.jar against opentelemetry-sdk-testing-1.49.0.jar
2-
No changes.
2+
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData (not serializable)
3+
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
4+
+++ NEW SUPERCLASS: java.lang.Object
5+
+++ NEW CONSTRUCTOR: PUBLIC(+) TestMetricData()
6+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder builder()
7+
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) STATIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder (not serializable)
8+
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
9+
+++ NEW SUPERCLASS: java.lang.Object
10+
+++ NEW CONSTRUCTOR: PUBLIC(+) TestMetricData$Builder()
11+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData build()
12+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setDescription(java.lang.String)
13+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setDoubleGaugeData(io.opentelemetry.sdk.metrics.data.GaugeData<io.opentelemetry.sdk.metrics.data.DoublePointData>)
14+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setDoubleSumData(io.opentelemetry.sdk.metrics.data.SumData<io.opentelemetry.sdk.metrics.data.DoublePointData>)
15+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setExponentialHistogramData(io.opentelemetry.sdk.metrics.data.ExponentialHistogramData)
16+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setHistogramData(io.opentelemetry.sdk.metrics.data.HistogramData)
17+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setInstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo)
18+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setLongGaugeData(io.opentelemetry.sdk.metrics.data.GaugeData<io.opentelemetry.sdk.metrics.data.LongPointData>)
19+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setLongSumData(io.opentelemetry.sdk.metrics.data.SumData<io.opentelemetry.sdk.metrics.data.LongPointData>)
20+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setName(java.lang.String)
21+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setResource(io.opentelemetry.sdk.resources.Resource)
22+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setSummaryData(io.opentelemetry.sdk.metrics.data.SummaryData)
23+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setUnit(java.lang.String)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-sdk-trace-1.49.0-SNAPSHOT.jar against opentelemetry-sdk-trace-1.49.0.jar
1+
Comparing source compatibility of opentelemetry-sdk-trace-1.50.0-SNAPSHOT.jar against opentelemetry-sdk-trace-1.49.0.jar
22
No changes.

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/data/DelegatingMetricDataTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import io.opentelemetry.api.common.Attributes;
1111
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
12+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
1213
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryData;
1314
import io.opentelemetry.sdk.resources.Resource;
1415
import io.opentelemetry.sdk.testing.metrics.TestMetricData;
@@ -108,8 +109,10 @@ void equals_differentUnit() {
108109

109110
@Test
110111
void equals_differentType() {
111-
MetricData metricData1 = createBasicMetricBuilder().setType(MetricDataType.SUMMARY).build();
112-
MetricData metricData2 = createBasicMetricBuilder().setType(MetricDataType.LONG_SUM).build();
112+
MetricData metricData1 =
113+
createBasicMetricBuilder().setHistogramData(ImmutableHistogramData.empty()).build();
114+
MetricData metricData2 =
115+
createBasicMetricBuilder().setSummaryData(ImmutableSummaryData.empty()).build();
113116
MetricData noOpWrapper1 = new NoOpDelegatingMetricData(metricData1);
114117
MetricData noOpWrapper2 = new NoOpDelegatingMetricData(metricData2);
115118

@@ -119,9 +122,9 @@ void equals_differentType() {
119122
@Test
120123
void equals_differentData() {
121124
MetricData metricData1 =
122-
createBasicMetricBuilder().setData(ImmutableSummaryData.empty()).build();
125+
createBasicMetricBuilder().setSummaryData(ImmutableSummaryData.empty()).build();
123126
MetricData metricData2 =
124-
createBasicMetricBuilder().setData(ImmutableSummaryData.empty()).build();
127+
createBasicMetricBuilder().setSummaryData(ImmutableSummaryData.empty()).build();
125128
MetricData noOpWrapper1 = new NoOpDelegatingMetricData(metricData1);
126129
MetricData noOpWrapper2 = new NoOpDelegatingMetricData(metricData2);
127130

@@ -184,8 +187,7 @@ private static TestMetricData.Builder createBasicMetricBuilder() {
184187
.setDescription("")
185188
.setUnit("1")
186189
.setName("name")
187-
.setData(ImmutableSummaryData.empty())
188-
.setType(MetricDataType.SUMMARY); // Not sure what type should be here
190+
.setSummaryData(ImmutableSummaryData.empty());
189191
}
190192

191193
private static final class NoOpDelegatingMetricData extends DelegatingMetricData {

sdk/testing/src/main/java/io/opentelemetry/sdk/testing/metrics/TestMetricData.java

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
import com.google.auto.value.AutoValue;
99
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
1010
import io.opentelemetry.sdk.metrics.data.Data;
11+
import io.opentelemetry.sdk.metrics.data.DoublePointData;
12+
import io.opentelemetry.sdk.metrics.data.ExponentialHistogramData;
13+
import io.opentelemetry.sdk.metrics.data.GaugeData;
14+
import io.opentelemetry.sdk.metrics.data.HistogramData;
15+
import io.opentelemetry.sdk.metrics.data.LongPointData;
1116
import io.opentelemetry.sdk.metrics.data.MetricData;
1217
import io.opentelemetry.sdk.metrics.data.MetricDataType;
18+
import io.opentelemetry.sdk.metrics.data.SumData;
19+
import io.opentelemetry.sdk.metrics.data.SummaryData;
1320
import io.opentelemetry.sdk.resources.Resource;
1421
import javax.annotation.concurrent.Immutable;
1522

@@ -31,70 +38,53 @@ public static Builder builder() {
3138
public abstract static class Builder {
3239
abstract TestMetricData autoBuild();
3340

34-
/**
35-
* Builds and returns a new {@link MetricData} instance from the data in {@code this}.
36-
*
37-
* @return a new {@link MetricData} instance.
38-
*/
3941
public TestMetricData build() {
4042
return autoBuild();
4143
}
4244

43-
/**
44-
* Sets the resource of the metric.
45-
*
46-
* @param resource the resource of the metric.
47-
* @return this.
48-
*/
4945
public abstract Builder setResource(Resource resource);
5046

51-
/**
52-
* Sets the name of the metric.
53-
*
54-
* @param name the name of the metric.
55-
* @return this.
56-
*/
5747
public abstract Builder setName(String name);
5848

59-
/**
60-
* Sets the description of the metric.
61-
*
62-
* @param description the description of the metric.
63-
* @return this.
64-
*/
6549
public abstract Builder setDescription(String description);
6650

67-
/**
68-
* Sets the unit of the metric.
69-
*
70-
* @param unit the unit of the metric.
71-
* @return this.
72-
*/
7351
public abstract Builder setUnit(String unit);
7452

75-
/**
76-
* Sets the type of the metric.
77-
*
78-
* @param type the type of the metric.
79-
* @return this.
80-
*/
81-
public abstract Builder setType(MetricDataType type);
82-
83-
/**
84-
* Sets the data of the metric.
85-
*
86-
* @param data the data of the metric.
87-
* @return this.
88-
*/
89-
public abstract Builder setData(Data<?> data);
90-
91-
/**
92-
* Sets the Instrumentation scope of the metric.
93-
*
94-
* @param instrumentationScopeInfo the instrumentation scope of the tracer which created this
95-
* metric.
96-
* @return this.
97-
*/
53+
// Make setType package-private to restrict direct access
54+
abstract Builder setType(MetricDataType type);
55+
56+
// Keep the generic setData method for internal use
57+
abstract Builder setData(Data<?> data);
58+
59+
// Add specific setData overloads for each metric data type
60+
public Builder setExponentialHistogramData(ExponentialHistogramData data) {
61+
return setType(MetricDataType.EXPONENTIAL_HISTOGRAM).setData(data);
62+
}
63+
64+
public Builder setHistogramData(HistogramData data) {
65+
return setType(MetricDataType.HISTOGRAM).setData(data);
66+
}
67+
68+
public Builder setLongSumData(SumData<LongPointData> data) {
69+
return setType(MetricDataType.LONG_SUM).setData(data);
70+
}
71+
72+
public Builder setDoubleSumData(SumData<DoublePointData> data) {
73+
return setType(MetricDataType.DOUBLE_SUM).setData(data);
74+
}
75+
76+
public Builder setDoubleGaugeData(GaugeData<DoublePointData> data) {
77+
return setType(MetricDataType.DOUBLE_GAUGE).setData(data);
78+
}
79+
80+
public Builder setLongGaugeData(GaugeData<LongPointData> data) {
81+
return setType(MetricDataType.LONG_GAUGE).setData(data);
82+
}
83+
84+
public Builder setSummaryData(SummaryData data) {
85+
return setType(MetricDataType.SUMMARY).setData(data);
86+
}
87+
9888
public abstract Builder setInstrumentationScopeInfo(
9989
InstrumentationScopeInfo instrumentationScopeInfo);
10090
}

0 commit comments

Comments
 (0)