Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore]: Add Profiles Marshaler to otlptext #11161

Merged
merged 22 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
454d067
[chore]: Add Profiles Marshaler to otlptext
julianocosta89 Sep 12, 2024
8a013d0
Remove changelog
julianocosta89 Sep 13, 2024
4b989c1
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 13, 2024
58e21a0
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 17, 2024
4a95b4f
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 19, 2024
fb1b938
Make log more complete
julianocosta89 Sep 20, 2024
3a32085
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 20, 2024
bfd7dd1
Move extended profile creation to its own function
julianocosta89 Sep 20, 2024
c376666
Move extended profile to otlptext
julianocosta89 Sep 20, 2024
f252965
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 20, 2024
ce6c462
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 23, 2024
86bab47
Create the attribute table with sorted keys
julianocosta89 Sep 23, 2024
d83cdc7
gofmt
julianocosta89 Sep 23, 2024
9ccbfdc
lint
julianocosta89 Sep 23, 2024
09187b3
Simplify attribute table
julianocosta89 Sep 23, 2024
d2509e3
lint
julianocosta89 Sep 23, 2024
d34a191
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 24, 2024
832f3d5
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 25, 2024
0974204
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 26, 2024
5dcc273
Merge branch 'main' into profiles-marshaler
julianocosta89 Sep 26, 2024
b86479c
Merge branch 'main' into profiles-marshaler
julianocosta89 Oct 2, 2024
3393f24
Merge branch 'main' into profiles-marshaler
julianocosta89 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/julianocosta89_debugexporter-profiles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: debugexporter
julianocosta89 marked this conversation as resolved.
Show resolved Hide resolved

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Implement text marshaler for profiles

# One or more tracking issues or pull requests related to the change
issues: [11155]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
43 changes: 43 additions & 0 deletions exporter/internal/otlptext/profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otlptext // import "go.opentelemetry.io/collector/exporter/internal/otlptext"

import "go.opentelemetry.io/collector/pdata/pprofile"

// NewTextProfilesMarshaler returns a pprofile.Marshaler to encode to OTLP text bytes.
func NewTextProfilesMarshaler() pprofile.Marshaler {
return textProfilesMarshaler{}
}

type textProfilesMarshaler struct{}

// MarshalProfiles pprofile.Profiles to OTLP text.
func (textProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, error) {
buf := dataBuffer{}
rps := pd.ResourceProfiles()
for i := 0; i < rps.Len(); i++ {
buf.logEntry("ResourceProfiles #%d", i)
rp := rps.At(i)
buf.logEntry("Resource SchemaURL: %s", rp.SchemaUrl())
buf.logAttributes("Resource attributes", rp.Resource().Attributes())
ilps := rp.ScopeProfiles()
for j := 0; j < ilps.Len(); j++ {
buf.logEntry("ScopeProfiles #%d", j)
ilp := ilps.At(j)
buf.logEntry("ScopeProfiles SchemaURL: %s", ilp.SchemaUrl())
buf.logInstrumentationScope(ilp.Scope())
profiles := ilp.Profiles()
for k := 0; k < profiles.Len(); k++ {
buf.logEntry("Profile #%d", k)
profile := profiles.At(k)
buf.logAttr("Profile ID", profile.ProfileID())
buf.logAttr("Start time", profile.StartTime().String())
buf.logAttr("End time", profile.EndTime().String())
buf.logAttributes("Attributes", profile.Attributes())
julianocosta89 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

return buf.buf.Bytes(), nil
}
46 changes: 46 additions & 0 deletions exporter/internal/otlptext/profiles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otlptext

import (
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pdata/testdata"
)

func TestProfilesText(t *testing.T) {
tests := []struct {
name string
in pprofile.Profiles
out string
}{
{
name: "empty_profiles",
in: pprofile.NewProfiles(),
out: "empty.out",
},
{
name: "two_profiles",
in: testdata.GenerateProfiles(2),
out: "two_profiles.out",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewTextProfilesMarshaler().MarshalProfiles(tt.in)
assert.NoError(t, err)
out, err := os.ReadFile(filepath.Join("testdata", "profiles", tt.out))
require.NoError(t, err)
expected := strings.ReplaceAll(string(out), "\r", "")
assert.Equal(t, expected, string(got))
})
}
}
Empty file.
15 changes: 15 additions & 0 deletions exporter/internal/otlptext/testdata/profiles/two_profiles.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ResourceProfiles #0
Resource SchemaURL:
Resource attributes:
-> resource-attr: Str(resource-attr-val-1)
ScopeProfiles #0
ScopeProfiles SchemaURL:
InstrumentationScope
Profile #0
Profile ID : 0102030405060708090a0b0c0d0e0f10
Start time : 2020-02-11 20:26:12.000000321 +0000 UTC
End time : 2020-02-11 20:26:13.000000789 +0000 UTC
Profile #1
Profile ID : 0202030405060708090a0b0c0d0e0f10
Start time : 2020-02-11 20:26:12.000000321 +0000 UTC
End time : 2020-02-11 20:26:13.000000789 +0000 UTC
Loading