Skip to content

Commit 84aacd3

Browse files
committed
wip: creating DelegatingMetricData.
1 parent f2f990c commit 84aacd3

33 files changed

+1295
-4
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.49.0-SNAPSHOT.jar against opentelemetry-sdk-metrics-1.48.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)
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<T> create(java.util.Collection<T>)
35+
GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.metrics.data.PointData
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.internal.data.ImmutableSumData<T> create(boolean, io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<T>)
52+
GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.metrics.data.PointData
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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
Comparing source compatibility of opentelemetry-sdk-testing-1.49.0-SNAPSHOT.jar against opentelemetry-sdk-testing-1.48.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 setData(io.opentelemetry.sdk.metrics.data.Data<?>)
13+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setDescription(java.lang.String)
14+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setInstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo)
15+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setName(java.lang.String)
16+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setResource(io.opentelemetry.sdk.resources.Resource)
17+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setType(io.opentelemetry.sdk.metrics.data.MetricDataType)
18+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.metrics.TestMetricData$Builder setUnit(java.lang.String)
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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+
* @since 1.28.0
39+
*/
40+
public abstract class DelegatingMetricData implements MetricData {
41+
42+
private final MetricData delegate;
43+
44+
protected DelegatingMetricData(MetricData delegate) {
45+
this.delegate = requireNonNull(delegate, "delegate");
46+
}
47+
48+
/**
49+
* Returns the resource associated with this metric data.
50+
*
51+
* @return the {@link Resource} instance.
52+
*/
53+
@Override
54+
public Resource getResource() {
55+
return delegate.getResource();
56+
}
57+
58+
/**
59+
* Returns the instrumentation library information associated with this metric data.
60+
*
61+
* @return the {@link InstrumentationScopeInfo} instance.
62+
*/
63+
@Override
64+
public InstrumentationScopeInfo getInstrumentationScopeInfo() {
65+
return delegate.getInstrumentationScopeInfo();
66+
}
67+
68+
/**
69+
* Returns the name of the metric.
70+
*
71+
* @return the name of the metric.
72+
*/
73+
@Override
74+
public String getName() {
75+
return delegate.getName();
76+
}
77+
78+
/**
79+
* Returns the description of the metric.
80+
*
81+
* @return the description of the metric.
82+
*/
83+
@Override
84+
public String getDescription() {
85+
return delegate.getDescription();
86+
}
87+
88+
/**
89+
* Returns the unit of the metric.
90+
*
91+
* @return the unit of the metric.
92+
*/
93+
@Override
94+
public String getUnit() {
95+
return delegate.getUnit();
96+
}
97+
98+
/**
99+
* Returns the type of the metric.
100+
*
101+
* @return the type of the metric.
102+
*/
103+
@Override
104+
public MetricDataType getType() {
105+
return delegate.getType();
106+
}
107+
108+
/**
109+
* Returns the data of the metric.
110+
*
111+
* @return the data of the metric.
112+
*/
113+
@Override
114+
public Data<?> getData() {
115+
return delegate.getData();
116+
}
117+
118+
/**
119+
* Returns a boolean indicating whether the delegate {@link MetricData} is equal to this {@code
120+
* MetricData}.
121+
*
122+
* @param o the object to compare to.
123+
* @return a boolean indicating whether the delegate {@link MetricData} is equal to this {@code
124+
* MetricData}.
125+
*/
126+
@Override
127+
public boolean equals(Object o) {
128+
if (o == this) {
129+
return true;
130+
}
131+
if (o instanceof MetricData) {
132+
MetricData that = (MetricData) o;
133+
return getResource().equals(that.getResource())
134+
&& getInstrumentationScopeInfo().equals(that.getInstrumentationScopeInfo())
135+
&& getName().equals(that.getName())
136+
&& getDescription().equals(that.getDescription())
137+
&& getUnit().equals(that.getUnit())
138+
&& getType().equals(that.getType())
139+
&& getData().equals(that.getData());
140+
}
141+
return false;
142+
}
143+
144+
/**
145+
* Returns a hash code value for the delegate {@link MetricData}.
146+
*
147+
* @return a hash code value for the delegate {@link MetricData}.
148+
*/
149+
@Override
150+
public int hashCode() {
151+
int code = 1;
152+
code *= 1000003;
153+
code ^= getResource().hashCode();
154+
code *= 1000003;
155+
code ^= getInstrumentationScopeInfo().hashCode();
156+
code *= 1000003;
157+
code ^= getName().hashCode();
158+
code *= 1000003;
159+
code ^= getDescription().hashCode();
160+
code *= 1000003;
161+
code ^= getUnit().hashCode();
162+
code *= 1000003;
163+
code ^= getType().hashCode();
164+
code *= 1000003;
165+
code ^= getData().hashCode();
166+
return code;
167+
}
168+
169+
/** Returns a string representation of the delegate {@link MetricData}. */
170+
@Override
171+
public String toString() {
172+
return "DelegatingMetricData{"
173+
+ "resource="
174+
+ getResource()
175+
+ ", instrumentationScopeInfo="
176+
+ getInstrumentationScopeInfo()
177+
+ ", name="
178+
+ getName()
179+
+ ", description="
180+
+ getDescription()
181+
+ ", unit="
182+
+ getUnit()
183+
+ ", type="
184+
+ getType()
185+
+ ", data="
186+
+ getData()
187+
+ "}";
188+
}
189+
}

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

Lines changed: 19 additions & 0 deletions
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,22 @@
1417
*/
1518
@Immutable
1619
public interface DoubleExemplarData extends ExemplarData {
20+
21+
/**
22+
* Construct a new exemplar.
23+
*
24+
* @param filteredAttributes The set of {@link Attributes} not already associated with the {@link
25+
* PointData}.
26+
* @param recordTimeNanos The time when the sample qas recorded in nanoseconds.
27+
* @param spanContext The associated span context.
28+
* @param value The value recorded.
29+
*/
30+
static DoubleExemplarData create(
31+
Attributes filteredAttributes, long recordTimeNanos, SpanContext spanContext, double value) {
32+
return ImmutableDoubleExemplarData.create(
33+
filteredAttributes, recordTimeNanos, spanContext, value);
34+
}
35+
1736
/** Numerical value of the measurement that was recorded. */
1837
double getValue();
1938
}

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

Lines changed: 20 additions & 0 deletions
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.sdk.metrics.internal.data.ImmutableDoublePointData;
10+
import java.util.Collections;
811
import java.util.List;
912

1013
/**
@@ -13,6 +16,23 @@
1316
* @since 1.14.0
1417
*/
1518
public interface DoublePointData extends PointData {
19+
20+
/**
21+
* Creates a {@link DoublePointData}.
22+
*
23+
* @param startEpochNanos The starting time for the period where this point was sampled. Note:
24+
* While start time is optional in OTLP, all SDKs should produce it for all their metrics, so
25+
* it is required here.
26+
* @param epochNanos The ending time for the period when this value was sampled.
27+
* @param attributes The set of attributes associated with this point.
28+
* @param value The value that was sampled.
29+
*/
30+
static DoublePointData create(
31+
long startEpochNanos, long epochNanos, Attributes attributes, double value) {
32+
return ImmutableDoublePointData.create(
33+
startEpochNanos, epochNanos, attributes, value, Collections.emptyList());
34+
}
35+
1636
/** Returns the value of the data point. */
1737
double getValue();
1838

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

Lines changed: 11 additions & 0 deletions
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,16 @@
2526
@Immutable
2627
public interface ExponentialHistogramBuckets {
2728

29+
/**
30+
* Create a ExponentialHistogramBuckets.
31+
*
32+
* @return a ExponentialHistogramBuckets.
33+
*/
34+
@SuppressWarnings("TooManyParameters")
35+
static ExponentialHistogramBuckets create(int scale, int offset, List<Long> bucketCounts) {
36+
return ImmutableExponentialHistogramBuckets.create(scale, offset, bucketCounts);
37+
}
38+
2839
/** The scale of the buckets. Must align with {@link ExponentialHistogramPointData#getScale()}. */
2940
int getScale();
3041

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

Lines changed: 7 additions & 0 deletions
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,12 @@
2425
@Immutable
2526
public interface ExponentialHistogramData extends Data<ExponentialHistogramPointData> {
2627

28+
/** Returns a new {@link ExponentialHistogramData}. */
29+
static ExponentialHistogramData create(
30+
AggregationTemporality temporality, Collection<ExponentialHistogramPointData> points) {
31+
return ImmutableExponentialHistogramData.create(temporality, points);
32+
}
33+
2734
/**
2835
* Returns the {@code AggregationTemporality} of this metric.
2936
*

0 commit comments

Comments
 (0)