-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[debugexporter] Add support for profiles signal (#11494)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR adds Profiles support to the `debugexporter` component. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #11155. <!--Describe what testing was performed and which tests were added.--> #### Testing Added tests to all modified modules: - `exporter/debugexporter/exporter_test.go` - `exporter/debugexporter/factory_test.go` - `exporter/debugexporter/internal/normal/profiles_test.go`
- Loading branch information
1 parent
57e59d1
commit cb19e1d
Showing
11 changed files
with
222 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add profiles support to debug exporter | ||
|
||
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package normal // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/normal" | ||
|
||
import ( | ||
"bytes" | ||
"strconv" | ||
"strings" | ||
|
||
"go.opentelemetry.io/collector/pdata/pprofile" | ||
) | ||
|
||
type normalProfilesMarshaler struct{} | ||
|
||
// Ensure normalProfilesMarshaller implements interface pprofile.Marshaler | ||
var _ pprofile.Marshaler = normalProfilesMarshaler{} | ||
|
||
// NewNormalProfilesMarshaler returns a pprofile.Marshaler for normal verbosity. It writes one line of text per log record | ||
func NewNormalProfilesMarshaler() pprofile.Marshaler { | ||
return normalProfilesMarshaler{} | ||
} | ||
|
||
func (normalProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, error) { | ||
var buffer bytes.Buffer | ||
for i := 0; i < pd.ResourceProfiles().Len(); i++ { | ||
resourceProfiles := pd.ResourceProfiles().At(i) | ||
for j := 0; j < resourceProfiles.ScopeProfiles().Len(); j++ { | ||
scopeProfiles := resourceProfiles.ScopeProfiles().At(j) | ||
for k := 0; k < scopeProfiles.Profiles().Len(); k++ { | ||
profile := scopeProfiles.Profiles().At(k) | ||
|
||
buffer.WriteString(profile.ProfileID().String()) | ||
|
||
buffer.WriteString(" samples=") | ||
buffer.WriteString(strconv.Itoa(profile.Profile().Sample().Len())) | ||
|
||
if profile.Attributes().Len() > 0 { | ||
profileAttributes := writeAttributes(profile.Attributes()) | ||
buffer.WriteString(" ") | ||
buffer.WriteString(strings.Join(profileAttributes, " ")) | ||
} | ||
|
||
buffer.WriteString("\n") | ||
} | ||
} | ||
} | ||
return buffer.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package normal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"go.opentelemetry.io/collector/pdata/pprofile" | ||
) | ||
|
||
func TestMarshalProfiles(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input pprofile.Profiles | ||
expected string | ||
}{ | ||
{ | ||
name: "empty profile", | ||
input: pprofile.NewProfiles(), | ||
expected: "", | ||
}, | ||
{ | ||
name: "one profile", | ||
input: func() pprofile.Profiles { | ||
profiles := pprofile.NewProfiles() | ||
profile := profiles.ResourceProfiles().AppendEmpty().ScopeProfiles().AppendEmpty().Profiles().AppendEmpty() | ||
profile.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}) | ||
profile.Profile().Sample().AppendEmpty() | ||
profile.Profile().Sample().AppendEmpty() | ||
profile.Attributes().PutStr("key1", "value1") | ||
return profiles | ||
}(), | ||
expected: `0102030405060708090a0b0c0d0e0f10 samples=2 key1=value1 | ||
`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
output, err := NewNormalProfilesMarshaler().MarshalProfiles(tt.input) | ||
require.NoError(t, err) | ||
assert.Equal(t, tt.expected, string(output)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters