Skip to content

Commit 9cb6365

Browse files
6195: DelegatingMetricData. (#7229)
Co-authored-by: jack-berg <[email protected]>
1 parent 4e243f2 commit 9cb6365

33 files changed

+1214
-4
lines changed
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)
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.sdk.metrics.data;
7+
8+
import static java.util.Objects.requireNonNull;
9+
10+
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
11+
import io.opentelemetry.sdk.resources.Resource;
12+
13+
/**
14+
* A {@link MetricData} which delegates all methods to another {@link MetricData}. Extend this class
15+
* to modify the {@link MetricData} that will be exported, for example by creating a delegating
16+
* {@link io.opentelemetry.sdk.metrics.export.MetricExporter} which wraps {@link MetricData} with a
17+
* custom implementation.
18+
*
19+
* <p>Example usage:
20+
*
21+
* <pre>{@code
22+
* // class MetricDataWithCustomDescription extends DelegatingMetricData {
23+
* //
24+
* // private final String description;
25+
* //
26+
* // MetricDataWithCustomDescription(MetricData delegate) {
27+
* // super(delegate);
28+
* // this.description = delegate.getDescription() + " (custom)";
29+
* // }
30+
* //
31+
* // @Override
32+
* // public String getDescription() {
33+
* // return description;
34+
* // }
35+
* // }
36+
* }</pre>
37+
*/
38+
public abstract class DelegatingMetricData implements MetricData {
39+
40+
private final MetricData delegate;
41+
42+
protected DelegatingMetricData(MetricData delegate) {
43+
this.delegate = requireNonNull(delegate, "delegate");
44+
}
45+
46+
/**
47+
* Returns the resource associated with this metric data.
48+
*
49+
* @return the {@link Resource} instance.
50+
*/
51+
@Override
52+
public Resource getResource() {
53+
return delegate.getResource();
54+
}
55+
56+
/**
57+
* Returns the instrumentation library information associated with this metric data.
58+
*
59+
* @return the {@link InstrumentationScopeInfo} instance.
60+
*/
61+
@Override
62+
public InstrumentationScopeInfo getInstrumentationScopeInfo() {
63+
return delegate.getInstrumentationScopeInfo();
64+
}
65+
66+
/**
67+
* Returns the name of the metric.
68+
*
69+
* @return the name of the metric.
70+
*/
71+
@Override
72+
public String getName() {
73+
return delegate.getName();
74+
}
75+
76+
/**
77+
* Returns the description of the metric.
78+
*
79+
* @return the description of the metric.
80+
*/
81+
@Override
82+
public String getDescription() {
83+
return delegate.getDescription();
84+
}
85+
86+
/**
87+
* Returns the unit of the metric.
88+
*
89+
* @return the unit of the metric.
90+
*/
91+
@Override
92+
public String getUnit() {
93+
return delegate.getUnit();
94+
}
95+
96+
/**
97+
* Returns the type of the metric.
98+
*
99+
* @return the type of the metric.
100+
*/
101+
@Override
102+
public MetricDataType getType() {
103+
return delegate.getType();
104+
}
105+
106+
/**
107+
* Returns the data of the metric.
108+
*
109+
* @return the data of the metric.
110+
*/
111+
@Override
112+
public Data<?> getData() {
113+
return delegate.getData();
114+
}
115+
116+
/**
117+
* Returns a boolean indicating whether the delegate {@link MetricData} is equal to this {@code
118+
* MetricData}.
119+
*
120+
* @param o the object to compare to.
121+
* @return a boolean indicating whether the delegate {@link MetricData} is equal to this {@code
122+
* MetricData}.
123+
*/
124+
@Override
125+
public boolean equals(Object o) {
126+
if (o == this) {
127+
return true;
128+
}
129+
if (o instanceof MetricData) {
130+
MetricData that = (MetricData) o;
131+
return getResource().equals(that.getResource())
132+
&& getInstrumentationScopeInfo().equals(that.getInstrumentationScopeInfo())
133+
&& getName().equals(that.getName())
134+
&& getDescription().equals(that.getDescription())
135+
&& getUnit().equals(that.getUnit())
136+
&& getType().equals(that.getType())
137+
&& getData().equals(that.getData());
138+
}
139+
return false;
140+
}
141+
142+
/**
143+
* Returns a hash code value for the delegate {@link MetricData}.
144+
*
145+
* @return a hash code value for the delegate {@link MetricData}.
146+
*/
147+
@Override
148+
public int hashCode() {
149+
int code = 1;
150+
code *= 1000003;
151+
code ^= getResource().hashCode();
152+
code *= 1000003;
153+
code ^= getInstrumentationScopeInfo().hashCode();
154+
code *= 1000003;
155+
code ^= getName().hashCode();
156+
code *= 1000003;
157+
code ^= getDescription().hashCode();
158+
code *= 1000003;
159+
code ^= getUnit().hashCode();
160+
code *= 1000003;
161+
code ^= getType().hashCode();
162+
code *= 1000003;
163+
code ^= getData().hashCode();
164+
return code;
165+
}
166+
167+
/** Returns a string representation of the delegate {@link MetricData}. */
168+
@Override
169+
public String toString() {
170+
return "DelegatingMetricData{"
171+
+ "resource="
172+
+ getResource()
173+
+ ", instrumentationScopeInfo="
174+
+ getInstrumentationScopeInfo()
175+
+ ", name="
176+
+ getName()
177+
+ ", description="
178+
+ getDescription()
179+
+ ", unit="
180+
+ getUnit()
181+
+ ", type="
182+
+ getType()
183+
+ ", data="
184+
+ getData()
185+
+ "}";
186+
}
187+
}

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExemplarData.java

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.trace.SpanContext;
10+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoubleExemplarData;
811
import javax.annotation.concurrent.Immutable;
912

1013
/**
@@ -14,6 +17,13 @@
1417
*/
1518
@Immutable
1619
public interface DoubleExemplarData extends ExemplarData {
20+
21+
static DoubleExemplarData create(
22+
Attributes filteredAttributes, long recordTimeNanos, SpanContext spanContext, double value) {
23+
return ImmutableDoubleExemplarData.create(
24+
filteredAttributes, recordTimeNanos, spanContext, value);
25+
}
26+
1727
/** Numerical value of the measurement that was recorded. */
1828
double getValue();
1929
}

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoublePointData.java

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData;
810
import java.util.List;
911

1012
/**
@@ -13,6 +15,17 @@
1315
* @since 1.14.0
1416
*/
1517
public interface DoublePointData extends PointData {
18+
19+
static DoublePointData create(
20+
long startEpochNanos,
21+
long epochNanos,
22+
Attributes attributes,
23+
double value,
24+
List<DoubleExemplarData> exemplars) {
25+
return ImmutableDoublePointData.create(
26+
startEpochNanos, epochNanos, attributes, value, exemplars);
27+
}
28+
1629
/** Returns the value of the data point. */
1730
double getValue();
1831

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramBuckets;
89
import java.util.List;
910
import javax.annotation.concurrent.Immutable;
1011

@@ -25,6 +26,10 @@
2526
@Immutable
2627
public interface ExponentialHistogramBuckets {
2728

29+
static ExponentialHistogramBuckets create(int scale, int offset, List<Long> bucketCounts) {
30+
return ImmutableExponentialHistogramBuckets.create(scale, offset, bucketCounts);
31+
}
32+
2833
/** The scale of the buckets. Must align with {@link ExponentialHistogramPointData#getScale()}. */
2934
int getScale();
3035

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramData;
89
import java.util.Collection;
910
import javax.annotation.concurrent.Immutable;
1011

@@ -24,6 +25,11 @@
2425
@Immutable
2526
public interface ExponentialHistogramData extends Data<ExponentialHistogramPointData> {
2627

28+
static ExponentialHistogramData create(
29+
AggregationTemporality temporality, Collection<ExponentialHistogramPointData> points) {
30+
return ImmutableExponentialHistogramData.create(temporality, points);
31+
}
32+
2733
/**
2834
* Returns the {@code AggregationTemporality} of this metric.
2935
*

0 commit comments

Comments
 (0)