Skip to content

Commit 888e9b6

Browse files
authored
[chore] generate valid profiles test data (open-telemetry#13375)
#### Description The profiles test data we currently generate isn't valid per [pdatatest.Validate](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/pdatatest/pprofiletest/validate.go#L13). This change fixes that. This goes hand in hand with open-telemetry/opentelemetry-collector-contrib#41231
1 parent 2a81bd0 commit 888e9b6

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

exporter/debugexporter/internal/otlptext/testdata/profiles/two_profiles.out

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Mapping #0
99
Has line numbers: true
1010
Has inline frames: true
1111
Location #0
12+
Mapping index: 0
13+
Address: 1
14+
Is folded: false
15+
Attributes: []
16+
Location #1
17+
Mapping index: 0
18+
Address: 2
19+
Is folded: false
20+
Attributes: []
21+
Location #2
1222
Mapping index: 3
1323
Address: 4
1424
Line #0
@@ -29,6 +39,7 @@ Link table:
2939
-> Trace ID: Str(0302030405060708090a0b0c0d0e0f10)
3040
-> Span ID: Str(1112131415161718)
3141
String table:
42+
3243
foobar
3344
ResourceProfiles #0
3445
Resource SchemaURL:
@@ -44,7 +55,7 @@ Profile #0
4455
Dropped attributes count: 1
4556
Location indices: [1]
4657
Sample #0
47-
Location length: 10
58+
Location length: 1
4859
Value: [4]
4960
Attributes:
5061
-> key: value
@@ -53,9 +64,9 @@ Profile #1
5364
Start time : 2020-02-11 20:26:12.000000321 +0000 UTC
5465
Duration : 2020-02-11 20:26:13.000000789 +0000 UTC
5566
Dropped attributes count: 0
56-
Location indices: []
67+
Location indices: [1]
5768
Sample #0
58-
Location length: 20
69+
Location length: 1
5970
Value: [9]
6071
Attributes:
6172
-> key: value

pdata/testdata/profile.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func GenerateProfiles(profilesCount int) pprofile.Profiles {
2222
ss := td.ResourceProfiles().At(0).ScopeProfiles().AppendEmpty().Profiles()
2323

2424
dic := td.ProfilesDictionary()
25+
dic.StringTable().Append("")
2526
attr := dic.AttributeTable().AppendEmpty()
2627
attr.SetKey("key")
2728
attr.Value().SetStr("value")
@@ -33,35 +34,52 @@ func GenerateProfiles(profilesCount int) pprofile.Profiles {
3334
for i := 0; i < profilesCount; i++ {
3435
switch i % 2 {
3536
case 0:
36-
fillProfileOne(ss.AppendEmpty())
37+
fillProfileOne(dic, ss.AppendEmpty())
3738
case 1:
38-
fillProfileTwo(ss.AppendEmpty())
39+
fillProfileTwo(dic, ss.AppendEmpty())
3940
}
4041
}
42+
4143
return td
4244
}
4345

44-
func fillProfileOne(profile pprofile.Profile) {
46+
func fillProfileOne(dic pprofile.ProfilesDictionary, profile pprofile.Profile) {
4547
profile.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
4648
profile.SetTime(profileStartTimestamp)
4749
profile.SetDuration(profileEndTimestamp)
4850
profile.SetDroppedAttributesCount(1)
51+
profile.PeriodType().SetAggregationTemporality(pprofile.AggregationTemporalityDelta)
52+
53+
st := profile.SampleType().AppendEmpty()
54+
st.SetAggregationTemporality(pprofile.AggregationTemporalityDelta)
55+
56+
loc := pprofile.NewLocation()
57+
loc.SetAddress(1)
58+
_ = pprofile.PutLocation(dic.LocationTable(), profile, loc)
4959

5060
sample := profile.Sample().AppendEmpty()
51-
sample.SetLocationsStartIndex(2)
52-
sample.SetLocationsLength(10)
61+
sample.SetLocationsStartIndex(0)
62+
sample.SetLocationsLength(1)
5363
sample.Value().Append(4)
5464
sample.AttributeIndices().Append(0)
5565
}
5666

57-
func fillProfileTwo(profile pprofile.Profile) {
67+
func fillProfileTwo(dic pprofile.ProfilesDictionary, profile pprofile.Profile) {
5868
profile.SetProfileID([16]byte{0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
5969
profile.SetTime(profileStartTimestamp)
6070
profile.SetDuration(profileEndTimestamp)
71+
profile.PeriodType().SetAggregationTemporality(pprofile.AggregationTemporalityDelta)
72+
73+
st := profile.SampleType().AppendEmpty()
74+
st.SetAggregationTemporality(pprofile.AggregationTemporalityDelta)
75+
76+
loc := pprofile.NewLocation()
77+
loc.SetAddress(2)
78+
_ = pprofile.PutLocation(dic.LocationTable(), profile, loc)
6179

6280
sample := profile.Sample().AppendEmpty()
63-
sample.SetLocationsStartIndex(7)
64-
sample.SetLocationsLength(20)
81+
sample.SetLocationsStartIndex(0)
82+
sample.SetLocationsLength(1)
6583
sample.Value().Append(9)
6684
sample.AttributeIndices().Append(0)
6785
}

service/internal/graph/obs_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ func TestComponentInstrumentation(t *testing.T) {
548548
"otelcol.receiver.produced.size": simpleMetric{
549549
attribute.NewSet(
550550
attribute.String(obsconsumer.ComponentOutcome, "success"),
551-
): 1104,
551+
): 1243,
552552
},
553553
},
554554
attribute.NewSet(
@@ -570,12 +570,12 @@ func TestComponentInstrumentation(t *testing.T) {
570570
"otelcol.processor.consumed.size": simpleMetric{
571571
attribute.NewSet(
572572
attribute.String(obsconsumer.ComponentOutcome, "success"),
573-
): 1104,
573+
): 1243,
574574
},
575575
"otelcol.processor.produced.size": simpleMetric{
576576
attribute.NewSet(
577577
attribute.String(obsconsumer.ComponentOutcome, "success"),
578-
): 1104,
578+
): 1243,
579579
},
580580
},
581581
attribute.NewSet(
@@ -602,17 +602,17 @@ func TestComponentInstrumentation(t *testing.T) {
602602
"otelcol.connector.consumed.size": simpleMetric{
603603
attribute.NewSet(
604604
attribute.String(obsconsumer.ComponentOutcome, "success"),
605-
): 1104,
605+
): 1243,
606606
},
607607
"otelcol.connector.produced.size": simpleMetric{
608608
attribute.NewSet(
609609
attribute.String(obsconsumer.ComponentOutcome, "success"),
610610
attribute.String("otelcol.pipeline.id", "profiles/right"),
611-
): 580,
611+
): 653,
612612
attribute.NewSet(
613613
attribute.String(obsconsumer.ComponentOutcome, "success"),
614614
attribute.String("otelcol.pipeline.id", "profiles/left"),
615-
): 524,
615+
): 590,
616616
},
617617
},
618618
attribute.NewSet(
@@ -628,7 +628,7 @@ func TestComponentInstrumentation(t *testing.T) {
628628
"otelcol.exporter.consumed.size": simpleMetric{
629629
attribute.NewSet(
630630
attribute.String(obsconsumer.ComponentOutcome, "success"),
631-
): 580,
631+
): 653,
632632
},
633633
},
634634
attribute.NewSet(
@@ -644,7 +644,7 @@ func TestComponentInstrumentation(t *testing.T) {
644644
"otelcol.exporter.consumed.size": simpleMetric{
645645
attribute.NewSet(
646646
attribute.String(obsconsumer.ComponentOutcome, "success"),
647-
): 524,
647+
): 590,
648648
},
649649
},
650650
}

0 commit comments

Comments
 (0)