Skip to content

Commit 8276c2b

Browse files
committed
profiles: refactor to separate sdk and exporter
1 parent 67bb561 commit 8276c2b

41 files changed

Lines changed: 482 additions & 541 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfilesRequestMarshaler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.opentelemetry.proto.collector.profiles.v1development.internal.ExportProfilesServiceRequest;
1616
import io.opentelemetry.sdk.profiles.data.ProfileData;
1717
import io.opentelemetry.sdk.profiles.data.ProfilesDictionaryData;
18-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfilesDictionaryData;
1918
import java.io.IOException;
2019
import java.util.Collection;
2120
import java.util.Collections;
@@ -29,7 +28,7 @@
2928
public final class ProfilesRequestMarshaler extends MarshalerWithSize {
3029

3130
private static final ProfilesDictionaryData EMPTY_DICTIONARY_DATA =
32-
ImmutableProfilesDictionaryData.create(
31+
ProfilesDictionaryData.create(
3332
Collections.emptyList(),
3433
Collections.emptyList(),
3534
Collections.emptyList(),

exporters/otlp/profiles/src/test/java/io/opentelemetry/exporter/otlp/profiles/FakeTelemetryUtil.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
1010
import io.opentelemetry.sdk.profiles.data.ProfileData;
1111
import io.opentelemetry.sdk.profiles.data.ProfilesDictionaryData;
12-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfileData;
13-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfilesDictionaryData;
14-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableValueTypeData;
12+
import io.opentelemetry.sdk.profiles.data.ValueTypeData;
1513
import io.opentelemetry.sdk.resources.Resource;
1614
import java.nio.ByteBuffer;
1715
import java.util.Collections;
@@ -20,7 +18,7 @@
2018
class FakeTelemetryUtil {
2119

2220
private static final ProfilesDictionaryData EMPTY_PROFILE_DICTIONARY_DATA =
23-
ImmutableProfilesDictionaryData.create(
21+
ProfilesDictionaryData.create(
2422
Collections.emptyList(),
2523
Collections.emptyList(),
2624
Collections.emptyList(),
@@ -40,15 +38,15 @@ private FakeTelemetryUtil() {}
4038
/** Generate a fake {@link ProfileData}. */
4139
static ProfileData generateFakeProfileData() {
4240
String profileId = "0123456789abcdef0123456789abcdef";
43-
return ImmutableProfileData.create(
41+
return ProfileData.create(
4442
Resource.create(Attributes.empty()),
4543
SCOPE_INFO,
4644
EMPTY_PROFILE_DICTIONARY_DATA,
47-
ImmutableValueTypeData.create(1, 2),
45+
ValueTypeData.create(1, 2),
4846
Collections.emptyList(),
4947
5L,
5048
6L,
51-
ImmutableValueTypeData.create(1, 2),
49+
ValueTypeData.create(1, 2),
5250
7L,
5351
profileId,
5452
8,

exporters/otlp/profiles/src/test/java/io/opentelemetry/exporter/otlp/profiles/ProfilesRequestMarshalerTest.java

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,10 @@
3636
import io.opentelemetry.sdk.profiles.data.LocationData;
3737
import io.opentelemetry.sdk.profiles.data.MappingData;
3838
import io.opentelemetry.sdk.profiles.data.ProfileData;
39+
import io.opentelemetry.sdk.profiles.data.ProfilesDictionaryData;
3940
import io.opentelemetry.sdk.profiles.data.SampleData;
4041
import io.opentelemetry.sdk.profiles.data.StackData;
4142
import io.opentelemetry.sdk.profiles.data.ValueTypeData;
42-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableFunctionData;
43-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableKeyValueAndUnitData;
44-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLineData;
45-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLinkData;
46-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLocationData;
47-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableMappingData;
48-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfileData;
49-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfilesDictionaryData;
50-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableSampleData;
51-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableStackData;
52-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableValueTypeData;
5343
import io.opentelemetry.sdk.resources.Resource;
5444
import java.io.ByteArrayOutputStream;
5545
import java.io.IOException;
@@ -66,7 +56,7 @@ public class ProfilesRequestMarshalerTest {
6656

6757
@Test
6858
void compareFunctionMarshaling() {
69-
FunctionData input = ImmutableFunctionData.create(1, 2, 3, 4);
59+
FunctionData input = FunctionData.create(1, 2, 3, 4);
7060
Function builderResult =
7161
Function.newBuilder()
7262
.setNameStrindex(1)
@@ -83,8 +73,8 @@ void compareFunctionMarshaling() {
8373
@Test
8474
void compareRepeatedFunctionMarshaling() {
8575
List<FunctionData> inputs = new ArrayList<>();
86-
inputs.add(ImmutableFunctionData.create(1, 2, 3, 4));
87-
inputs.add(ImmutableFunctionData.create(5, 6, 7, 8));
76+
inputs.add(FunctionData.create(1, 2, 3, 4));
77+
inputs.add(FunctionData.create(5, 6, 7, 8));
8878

8979
List<Function> builderResults = new ArrayList<>();
9080
builderResults.add(
@@ -112,7 +102,7 @@ void compareRepeatedFunctionMarshaling() {
112102

113103
@Test
114104
void compareLineMarshaling() {
115-
LineData input = ImmutableLineData.create(1, 2, 3);
105+
LineData input = LineData.create(1, 2, 3);
116106
Line builderResult = Line.newBuilder().setFunctionIndex(1).setLine(2).setColumn(3).build();
117107

118108
Line roundTripResult = parse(Line.getDefaultInstance(), LineMarshaler.create(input));
@@ -122,8 +112,8 @@ void compareLineMarshaling() {
122112
@Test
123113
void compareRepeatedLineMarshaling() {
124114
List<LineData> inputs = new ArrayList<>();
125-
inputs.add(ImmutableLineData.create(1, 2, 3));
126-
inputs.add(ImmutableLineData.create(4, 5, 6));
115+
inputs.add(LineData.create(1, 2, 3));
116+
inputs.add(LineData.create(4, 5, 6));
127117

128118
List<Line> builderResults = new ArrayList<>();
129119
builderResults.add(Line.newBuilder().setFunctionIndex(1).setLine(2).setColumn(3).build());
@@ -139,7 +129,7 @@ void compareRepeatedLineMarshaling() {
139129

140130
@Test
141131
void compareKeyValueAndUnitMarshaling() {
142-
KeyValueAndUnitData input = ImmutableKeyValueAndUnitData.create(1, Value.of("foo"), 3);
132+
KeyValueAndUnitData input = KeyValueAndUnitData.create(1, Value.of("foo"), 3);
143133
KeyValueAndUnit builderResult =
144134
KeyValueAndUnit.newBuilder()
145135
.setKeyStrindex(1)
@@ -155,8 +145,8 @@ void compareKeyValueAndUnitMarshaling() {
155145
@Test
156146
void compareRepeatedKeyValueAndUnitMarshaling() {
157147
List<KeyValueAndUnitData> inputs = new ArrayList<>();
158-
inputs.add(ImmutableKeyValueAndUnitData.create(1, Value.of("foo"), 3));
159-
inputs.add(ImmutableKeyValueAndUnitData.create(4, Value.of("bar"), 6));
148+
inputs.add(KeyValueAndUnitData.create(1, Value.of("foo"), 3));
149+
inputs.add(KeyValueAndUnitData.create(4, Value.of("bar"), 6));
160150

161151
List<KeyValueAndUnit> builderResults = new ArrayList<>();
162152
builderResults.add(
@@ -184,7 +174,7 @@ void compareRepeatedKeyValueAndUnitMarshaling() {
184174
void compareLinkMarshaling() {
185175
String traceId = "0123456789abcdef0123456789abcdef";
186176
String spanId = "fedcba9876543210";
187-
LinkData input = ImmutableLinkData.create(traceId, spanId);
177+
LinkData input = LinkData.create(traceId, spanId);
188178
Link builderResult =
189179
Link.newBuilder()
190180
.setTraceId(ByteString.fromHex(traceId))
@@ -198,8 +188,8 @@ void compareLinkMarshaling() {
198188
@Test
199189
void compareRepeatedLinkMarshaling() {
200190
List<LinkData> inputs = new ArrayList<>();
201-
inputs.add(ImmutableLinkData.create("0123456789abcdef0123456789abcdef", "fedcba9876543210"));
202-
inputs.add(ImmutableLinkData.create("123456789abcdef0123456789abcdef0", "edcba9876543210f"));
191+
inputs.add(LinkData.create("0123456789abcdef0123456789abcdef", "fedcba9876543210"));
192+
inputs.add(LinkData.create("123456789abcdef0123456789abcdef0", "edcba9876543210f"));
203193

204194
List<Link> builderResults = new ArrayList<>();
205195
builderResults.add(
@@ -223,7 +213,7 @@ void compareRepeatedLinkMarshaling() {
223213

224214
@Test
225215
void compareLocationMarshaling() {
226-
LocationData input = ImmutableLocationData.create(1, 2, Collections.emptyList(), listOf(4, 5));
216+
LocationData input = LocationData.create(1, 2, Collections.emptyList(), listOf(4, 5));
227217
Location builderResult =
228218
Location.newBuilder()
229219
.setMappingIndex(1)
@@ -239,8 +229,8 @@ void compareLocationMarshaling() {
239229
@Test
240230
void compareRepeatedLocationMarshaling() {
241231
List<LocationData> inputs = new ArrayList<>();
242-
inputs.add(ImmutableLocationData.create(1, 2, Collections.emptyList(), listOf(3, 4)));
243-
inputs.add(ImmutableLocationData.create(5, 6, Collections.emptyList(), listOf(7, 8)));
232+
inputs.add(LocationData.create(1, 2, Collections.emptyList(), listOf(3, 4)));
233+
inputs.add(LocationData.create(5, 6, Collections.emptyList(), listOf(7, 8)));
244234

245235
List<Location> builderResults = new ArrayList<>();
246236
builderResults.add(
@@ -266,7 +256,7 @@ void compareRepeatedLocationMarshaling() {
266256

267257
@Test
268258
void compareMappingMarshaling() {
269-
MappingData input = ImmutableMappingData.create(1, 2, 3, 4, listOf(5, 6));
259+
MappingData input = MappingData.create(1, 2, 3, 4, listOf(5, 6));
270260
Mapping builderResult =
271261
Mapping.newBuilder()
272262
.setMemoryStart(1)
@@ -283,8 +273,8 @@ void compareMappingMarshaling() {
283273
@Test
284274
void compareRepeatedMappingMarshaling() {
285275
List<MappingData> inputs = new ArrayList<>();
286-
inputs.add(ImmutableMappingData.create(1, 2, 3, 4, listOf(5, 6)));
287-
inputs.add(ImmutableMappingData.create(7, 8, 9, 10, listOf(11, 12)));
276+
inputs.add(MappingData.create(1, 2, 3, 4, listOf(5, 6)));
277+
inputs.add(MappingData.create(7, 8, 9, 10, listOf(11, 12)));
288278

289279
List<Mapping> builderResults = new ArrayList<>();
290280
builderResults.add(
@@ -314,7 +304,7 @@ void compareRepeatedMappingMarshaling() {
314304

315305
@Test
316306
void compareStackMarshaling() {
317-
StackData input = ImmutableStackData.create(listOf(1, 2));
307+
StackData input = StackData.create(listOf(1, 2));
318308
Stack builderResult = Stack.newBuilder().addAllLocationIndices(listOf(1, 2)).build();
319309

320310
Stack roundTripResult = parse(Stack.getDefaultInstance(), StackMarshaler.create(input));
@@ -324,8 +314,8 @@ void compareStackMarshaling() {
324314
@Test
325315
void compareRepeatedStackMarshaling() {
326316
List<StackData> inputs = new ArrayList<>();
327-
inputs.add(ImmutableStackData.create(listOf(1, 2)));
328-
inputs.add(ImmutableStackData.create(listOf(3, 4)));
317+
inputs.add(StackData.create(listOf(1, 2)));
318+
inputs.add(StackData.create(listOf(3, 4)));
329319

330320
List<Stack> builderResults = new ArrayList<>();
331321
builderResults.add(Stack.newBuilder().addAllLocationIndices(listOf(1, 2)).build());
@@ -344,22 +334,22 @@ void compareResourceProfilesMarshaling() {
344334

345335
String profileId = "0123456789abcdef0123456789abcdef";
346336
ProfileData profileContainerData =
347-
ImmutableProfileData.create(
337+
ProfileData.create(
348338
Resource.create(Attributes.empty()),
349339
InstrumentationScopeInfo.create("testscope"),
350-
ImmutableProfilesDictionaryData.create(
340+
ProfilesDictionaryData.create(
351341
Collections.emptyList(),
352342
Collections.emptyList(),
353343
Collections.emptyList(),
354344
Collections.emptyList(),
355345
Collections.emptyList(),
356346
Collections.emptyList(),
357347
Collections.emptyList()),
358-
ImmutableValueTypeData.create(1, 2),
348+
ValueTypeData.create(1, 2),
359349
Collections.emptyList(),
360350
5L,
361351
6L,
362-
ImmutableValueTypeData.create(1, 2),
352+
ValueTypeData.create(1, 2),
363353
7L,
364354
profileId,
365355
8,
@@ -401,8 +391,7 @@ void compareResourceProfilesMarshaling() {
401391

402392
@Test
403393
void compareSampleMarshaling() {
404-
SampleData input =
405-
ImmutableSampleData.create(1, listOf(2, 3), 4, listOf(5L, 6L), listOf(7L, 8L));
394+
SampleData input = SampleData.create(1, listOf(2, 3), 4, listOf(5L, 6L), listOf(7L, 8L));
406395
Sample builderResult =
407396
Sample.newBuilder()
408397
.setStackIndex(1)
@@ -419,9 +408,8 @@ void compareSampleMarshaling() {
419408
@Test
420409
void compareRepeatedSampleMarshaling() {
421410
List<SampleData> inputs = new ArrayList<>();
422-
inputs.add(ImmutableSampleData.create(1, listOf(2, 3), 4, listOf(5L, 6L), listOf(7L, 8L)));
423-
inputs.add(
424-
ImmutableSampleData.create(11, listOf(12, 13), 14, listOf(15L, 16L), listOf(17L, 18L)));
411+
inputs.add(SampleData.create(1, listOf(2, 3), 4, listOf(5L, 6L), listOf(7L, 8L)));
412+
inputs.add(SampleData.create(11, listOf(12, 13), 14, listOf(15L, 16L), listOf(17L, 18L)));
425413

426414
List<Sample> builderResults = new ArrayList<>();
427415
builderResults.add(
@@ -451,7 +439,7 @@ void compareRepeatedSampleMarshaling() {
451439

452440
@Test
453441
void compareValueTypeMarshaling() {
454-
ValueTypeData input = ImmutableValueTypeData.create(1, 2);
442+
ValueTypeData input = ValueTypeData.create(1, 2);
455443
ValueType builderResult = ValueType.newBuilder().setTypeStrindex(1).setUnitStrindex(2).build();
456444

457445
ValueType roundTripResult =
@@ -462,8 +450,8 @@ void compareValueTypeMarshaling() {
462450
@Test
463451
void compareRepeatedValueTypeMarshaling() {
464452
List<ValueTypeData> inputs = new ArrayList<>();
465-
inputs.add(ImmutableValueTypeData.create(1, 2));
466-
inputs.add(ImmutableValueTypeData.create(3, 4));
453+
inputs.add(ValueTypeData.create(1, 2));
454+
inputs.add(ValueTypeData.create(3, 4));
467455

468456
List<ValueType> builderResults = new ArrayList<>();
469457
builderResults.add(ValueType.newBuilder().setTypeStrindex(1).setUnitStrindex(2).build());

opentelemetry-jfr-profiles-shim/src/main/java/io/opentelemetry/sdk/profiles/jfr/JfrExportExample.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
1313
import io.opentelemetry.sdk.profiles.ProfileExporter;
1414
import io.opentelemetry.sdk.profiles.data.ProfileData;
15-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfileData;
16-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableValueTypeData;
15+
import io.opentelemetry.sdk.profiles.data.ValueTypeData;
1716
import io.opentelemetry.sdk.resources.Resource;
1817
import java.io.IOException;
1918
import java.nio.ByteBuffer;
@@ -77,15 +76,15 @@ public static ProfileData convertJfrFile(Path jfrFilePath) throws IOException {
7776
.setSchemaUrl("http://url")
7877
.build();
7978

80-
return ImmutableProfileData.create(
79+
return ProfileData.create(
8180
Resource.create(Attributes.empty()),
8281
scopeInfo,
8382
converter.getProfilesDictionaryCompositor().getProfileDictionaryData(),
84-
ImmutableValueTypeData.create(0, 0),
83+
ValueTypeData.create(0, 0),
8584
converter.getSamples(),
8685
0,
8786
0,
88-
ImmutableValueTypeData.create(0, 0),
87+
ValueTypeData.create(0, 0),
8988
0,
9089
profileId,
9190
0,

opentelemetry-jfr-profiles-shim/src/main/java/io/opentelemetry/sdk/profiles/jfr/JfrLocationDataCompositor.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
import io.opentelemetry.sdk.profiles.data.LineData;
1111
import io.opentelemetry.sdk.profiles.data.LocationData;
1212
import io.opentelemetry.sdk.profiles.data.StackData;
13-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableFunctionData;
14-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLineData;
15-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLocationData;
16-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableStackData;
1713
import java.util.Collections;
1814
import java.util.List;
1915
import jdk.jfr.consumer.RecordedFrame;
@@ -52,7 +48,7 @@ public int putIfAbsent(List<RecordedFrame> frameList) {
5248

5349
List<Integer> locationIndices = frameList.stream().map(this::frameToLocation).toList();
5450

55-
StackData stackData = ImmutableStackData.create(locationIndices);
51+
StackData stackData = StackData.create(locationIndices);
5652
int stackIndex = profilesDictionaryCompositor.putIfAbsent(stackData);
5753
return stackIndex;
5854
}
@@ -72,14 +68,14 @@ protected int frameToLocation(RecordedFrame frame) {
7268
String name = nameFrom(frame);
7369
int nameStringIndex = profilesDictionaryCompositor.putIfAbsent(name);
7470

75-
FunctionData functionData = ImmutableFunctionData.create(nameStringIndex, 0, 0, 0);
71+
FunctionData functionData = FunctionData.create(nameStringIndex, 0, 0, 0);
7672
int functionIndex = profilesDictionaryCompositor.putIfAbsent(functionData);
7773

7874
int lineNumber = frame.getLineNumber() != -1 ? frame.getLineNumber() : 0;
79-
LineData lineData = ImmutableLineData.create(functionIndex, lineNumber, 0);
75+
LineData lineData = LineData.create(functionIndex, lineNumber, 0);
8076

8177
LocationData locationData =
82-
ImmutableLocationData.create(0, 0, List.of(lineData), Collections.emptyList());
78+
LocationData.create(0, 0, List.of(lineData), Collections.emptyList());
8379

8480
int locationIndex = profilesDictionaryCompositor.putIfAbsent(locationData);
8581
return locationIndex;

opentelemetry-sdk-profiles/src/main/java/io/opentelemetry/sdk/profiles/ProfilesDictionaryCompositor.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
import io.opentelemetry.sdk.profiles.data.MappingData;
1414
import io.opentelemetry.sdk.profiles.data.ProfilesDictionaryData;
1515
import io.opentelemetry.sdk.profiles.data.StackData;
16-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableFunctionData;
17-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableKeyValueAndUnitData;
18-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLinkData;
19-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableLocationData;
20-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableMappingData;
21-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableProfilesDictionaryData;
22-
import io.opentelemetry.sdk.profiles.internal.data.ImmutableStackData;
2316
import java.util.Collections;
2417

2518
/**
@@ -57,14 +50,14 @@ public ProfilesDictionaryCompositor() {
5750
// They could be public static constants on this class or the corresponding Immutable*Data
5851
// classes if other use cases require them.
5952

60-
mappingTable.putIfAbsent(ImmutableMappingData.create(0, 0, 0, 0, Collections.emptyList()));
53+
mappingTable.putIfAbsent(MappingData.create(0, 0, 0, 0, Collections.emptyList()));
6154
locationTable.putIfAbsent(
62-
ImmutableLocationData.create(0, 0, Collections.emptyList(), Collections.emptyList()));
63-
functionTable.putIfAbsent(ImmutableFunctionData.create(0, 0, 0, 0));
64-
linkTable.putIfAbsent(ImmutableLinkData.create("", ""));
55+
LocationData.create(0, 0, Collections.emptyList(), Collections.emptyList()));
56+
functionTable.putIfAbsent(FunctionData.create(0, 0, 0, 0));
57+
linkTable.putIfAbsent(LinkData.create("", ""));
6558
stringTable.putIfAbsent("");
66-
attributeTable.putIfAbsent(ImmutableKeyValueAndUnitData.create(0, Value.of(""), 0));
67-
stackTable.putIfAbsent(ImmutableStackData.create(Collections.emptyList()));
59+
attributeTable.putIfAbsent(KeyValueAndUnitData.create(0, Value.of(""), 0));
60+
stackTable.putIfAbsent(StackData.create(Collections.emptyList()));
6861
}
6962

7063
/**
@@ -76,7 +69,7 @@ public ProfilesDictionaryCompositor() {
7669
* @return a ProfileDictionaryData with the contents of the tables.
7770
*/
7871
public ProfilesDictionaryData getProfileDictionaryData() {
79-
return ImmutableProfilesDictionaryData.create(
72+
return ProfilesDictionaryData.create(
8073
mappingTable.getTable(),
8174
locationTable.getTable(),
8275
functionTable.getTable(),

0 commit comments

Comments
 (0)