Skip to content

Commit 59b8c06

Browse files
committed
[chore][pprofiles] Fix pprofile DurationNano to be a TypeUint64
Complementary change to open-telemetry/opentelemetry-collector#14188. Signed-off-by: Florian Lehner <[email protected]>
1 parent 3cfc0c1 commit 59b8c06

File tree

11 files changed

+51
-25
lines changed

11 files changed

+51
-25
lines changed

.chloggen/collector-14188.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component:
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: fix pprofile DurationNano to be a TypeUint64
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: []
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user,api]

exporter/coralogixexporter/profiles_client_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"go.opentelemetry.io/collector/config/configopaque"
2121
"go.opentelemetry.io/collector/config/configtls"
2222
"go.opentelemetry.io/collector/exporter/exportertest"
23-
"go.opentelemetry.io/collector/pdata/pcommon"
2423
"go.opentelemetry.io/collector/pdata/pprofile"
2524
"go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp"
2625
"go.uber.org/zap"
@@ -305,7 +304,7 @@ func BenchmarkProfilesExporter_PushProfiles(b *testing.B) {
305304
var id [16]byte
306305
binary.LittleEndian.PutUint64(id[:8], uint64(j))
307306
profile.SetProfileID(id)
308-
profile.SetDuration(1000000000) // 1 second in nanoseconds
307+
profile.SetDurationNano(1000000000) // 1 second in nanoseconds
309308
}
310309
_ = exp.pushProfiles(b.Context(), profiles)
311310
}
@@ -428,7 +427,7 @@ func TestProfilesExporter_PushProfiles_Performance(t *testing.T) {
428427
var id [16]byte
429428
binary.LittleEndian.PutUint64(id[:8], uint64(i))
430429
profile.SetProfileID(id)
431-
profile.SetDuration(pcommon.NewTimestampFromTime(time.Now().Add(time.Second)))
430+
profile.SetDurationNano(1000000000)
432431
}
433432

434433
start := time.Now()
@@ -458,7 +457,7 @@ func TestProfilesExporter_PushProfiles_Performance(t *testing.T) {
458457
var id [16]byte
459458
binary.LittleEndian.PutUint64(id[:8], uint64(i))
460459
profile.SetProfileID(id)
461-
profile.SetDuration(pcommon.NewTimestampFromTime(time.Now().Add(time.Second)))
460+
profile.SetDurationNano(1000000000)
462461
}
463462

464463
start := time.Now()
@@ -503,7 +502,7 @@ func TestProfilesExporter_PushProfiles_Performance(t *testing.T) {
503502
var id [16]byte
504503
binary.LittleEndian.PutUint64(id[:8], uint64(i))
505504
profile.SetProfileID(id)
506-
profile.SetDuration(pcommon.NewTimestampFromTime(time.Now().Add(time.Second)))
505+
profile.SetDurationNano(1000000000)
507506
}
508507

509508
start := time.Now()
@@ -559,7 +558,7 @@ func TestProfilesExporter_RateLimitErrorCountReset(t *testing.T) {
559558
var id [16]byte
560559
binary.LittleEndian.PutUint64(id[:8], uint64(1))
561560
profile.SetProfileID(id)
562-
profile.SetDuration(pcommon.NewTimestampFromTime(time.Now().Add(time.Second)))
561+
profile.SetDurationNano(1000000000)
563562

564563
err = exp.pushProfiles(t.Context(), profiles)
565564
assert.Error(t, err)
@@ -613,7 +612,7 @@ func TestProfilesExporter_RateLimitCounterResetOnSuccess(t *testing.T) {
613612
var id [16]byte
614613
binary.LittleEndian.PutUint64(id[:8], uint64(1))
615614
profile.SetProfileID(id)
616-
profile.SetDuration(pcommon.NewTimestampFromTime(time.Now().Add(time.Second)))
615+
profile.SetDurationNano(1000000000)
617616
return profiles
618617
}
619618

exporter/fileexporter/encoding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func generateProfiles() pprofile.Profiles {
9999
rp.Resource().Attributes().PutStr("resource", "R1")
100100
p := rp.ScopeProfiles().AppendEmpty().Profiles().AppendEmpty()
101101
p.SetProfileID(pprofile.NewProfileIDEmpty())
102-
p.SetDuration(pcommon.Timestamp(1 * time.Second / time.Nanosecond))
102+
p.SetDurationNano(1000000000)
103103
return profiles
104104
}
105105

extension/encoding/otlpencodingextension/extension_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func generateProfiles() pprofile.Profiles {
202202
im := ilm.Profiles().AppendEmpty()
203203
im.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04})
204204
im.SetTime(pcommon.NewTimestampFromTime(now))
205-
im.SetDuration(pcommon.NewTimestampFromTime(time.Now()))
205+
im.SetDurationNano(1)
206206
}
207207
return pd
208208
}

pkg/ottl/contexts/internal/ctxprofile/profile.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ func accessTime[K Context]() ottl.StandardGetSetter[K] {
115115
func accessDurationUnixNano[K Context]() ottl.StandardGetSetter[K] {
116116
return ottl.StandardGetSetter[K]{
117117
Getter: func(_ context.Context, tCtx K) (any, error) {
118-
return tCtx.GetProfile().Duration().AsTime().UnixNano(), nil
118+
return tCtx.GetProfile().DurationNano(), nil
119119
},
120120
Setter: func(_ context.Context, tCtx K, val any) error {
121121
if t, ok := val.(int64); ok {
122-
tCtx.GetProfile().SetDuration(pcommon.NewTimestampFromTime(time.Unix(0, t)))
122+
tCtx.GetProfile().SetDurationNano(uint64(t))
123123
}
124124
return nil
125125
},
@@ -129,11 +129,11 @@ func accessDurationUnixNano[K Context]() ottl.StandardGetSetter[K] {
129129
func accessDuration[K Context]() ottl.StandardGetSetter[K] {
130130
return ottl.StandardGetSetter[K]{
131131
Getter: func(_ context.Context, tCtx K) (any, error) {
132-
return tCtx.GetProfile().Duration().AsTime(), nil
132+
return tCtx.GetProfile().DurationNano(), nil
133133
},
134134
Setter: func(_ context.Context, tCtx K, val any) error {
135135
if t, ok := val.(time.Time); ok {
136-
tCtx.GetProfile().SetDuration(pcommon.NewTimestampFromTime(t))
136+
tCtx.GetProfile().SetDurationNano(uint64(t.Nanosecond()))
137137
}
138138
return nil
139139
},

pkg/pdatatest/pprofiletest/options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (ignoreProfileTimestampValues) maskProfileTimestampValues(profiles pprofile
129129
for k := 0; k < lrs.Len(); k++ {
130130
lr := lrs.At(k)
131131
lr.SetTime(pcommon.NewTimestampFromTime(time.Time{}))
132-
lr.SetDuration(pcommon.NewTimestampFromTime(time.Time{}))
132+
lr.SetDurationNano(1)
133133
}
134134
}
135135
}
@@ -191,8 +191,8 @@ func sortProfileSlices(ls pprofile.Profiles) {
191191
if a.Time() != b.Time() {
192192
return a.Time() < b.Time()
193193
}
194-
if a.Duration() != b.Duration() {
195-
return a.Duration() < b.Duration()
194+
if a.DurationNano() != b.DurationNano() {
195+
return a.DurationNano() < b.DurationNano()
196196
}
197197
as := a.ProfileID()
198198
bs := b.ProfileID()

pkg/pdatatest/pprofiletest/profiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ func CompareProfile(expectedDic, actualDic pprofile.ProfilesDictionary, expected
263263
errs = multierr.Append(errs, fmt.Errorf("keepFrames does not match expected '%s', actual '%s'", expected.OriginalPayload().AsRaw(), actual.OriginalPayload().AsRaw()))
264264
}
265265

266-
if expected.Duration() != actual.Duration() {
267-
errs = multierr.Append(errs, fmt.Errorf("duration doesn't match expected: %d, actual: %d", expected.Duration(), actual.Duration()))
266+
if expected.DurationNano() != actual.DurationNano() {
267+
errs = multierr.Append(errs, fmt.Errorf("duration doesn't match expected: %d, actual: %d", expected.DurationNano(), actual.DurationNano()))
268268
}
269269

270270
if expected.Period() != actual.Period() {

pkg/pdatatest/pprofiletest/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Profile struct {
6767
SampleType ValueTypes
6868
Sample []Sample
6969
TimeNanos pcommon.Timestamp
70-
DurationNanos pcommon.Timestamp
70+
DurationNanos uint64
7171
PeriodType ValueType
7272
Period int64
7373
DefaultSampleType ValueType
@@ -99,7 +99,7 @@ func (p *Profile) Transform(dic pprofile.ProfilesDictionary, psp pprofile.ScopeP
9999
sa.Transform(dic, pp)
100100
}
101101
pp.SetTime(p.TimeNanos)
102-
pp.SetDuration(p.DurationNanos)
102+
pp.SetDurationNano(p.DurationNanos)
103103
p.PeriodType.CopyTo(dic, pp.PeriodType())
104104
pp.SetPeriod(p.Period)
105105
p.DefaultSampleType.Transform(dic, pp)

pkg/pdatatest/pprofiletest/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func validateSample(dic pprofile.ProfilesDictionary, pp pprofile.Profile, sample
103103
}
104104

105105
startTime := uint64(pp.Time().AsTime().UnixNano())
106-
endTime := startTime + uint64(pp.Duration().AsTime().UnixNano())
106+
endTime := startTime + pp.DurationNano()
107107
for i := range sample.TimestampsUnixNano().Len() {
108108
ts := sample.TimestampsUnixNano().At(i)
109109
if ts < startTime || ts >= endTime {

pkg/pdatatest/pprofiletest/validate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func Test_validateSample(t *testing.T) {
348348
profile: func() pprofile.Profile {
349349
pp := pprofile.NewProfile()
350350
pp.SetTime(1)
351-
pp.SetDuration(1)
351+
pp.SetDurationNano(1)
352352
return pp
353353
}(),
354354
sample: func() pprofile.Sample {
@@ -364,7 +364,7 @@ func Test_validateSample(t *testing.T) {
364364
profile: func() pprofile.Profile {
365365
pp := pprofile.NewProfile()
366366
pp.SetTime(1)
367-
pp.SetDuration(1)
367+
pp.SetDurationNano(1)
368368
return pp
369369
}(),
370370
sample: func() pprofile.Sample {
@@ -380,7 +380,7 @@ func Test_validateSample(t *testing.T) {
380380
profile: func() pprofile.Profile {
381381
pp := pprofile.NewProfile()
382382
pp.SetTime(1)
383-
pp.SetDuration(1)
383+
pp.SetDurationNano(1)
384384
return pp
385385
}(),
386386
sample: func() pprofile.Sample {

0 commit comments

Comments
 (0)