Skip to content

Commit

Permalink
[extension/opamp] Add os.description as non-identifying agent attri…
Browse files Browse the repository at this point in the history
…bute (#35816)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->

The opamp extension now reports additional information about the host
machine's operating system, specifically the version. It does so by
reporting the semantic convention `os.description`(defined
[here](https://opentelemetry.io/docs/specs/semconv/attributes-registry/os/))
as a non-identifying attribute in the agent description message.

**Link to tracking Issue:** <Issue number if applicable> Closes #35555

**Testing:** <Describe what testing was performed and which tests were
added.> Unit tests updated.
Verified `os.description` attribute shows up with values like 'macOS
15.0' and 'Ubuntu 20.04.6 LTS'
  • Loading branch information
dpaasman00 authored Oct 22, 2024
1 parent 58a77db commit e788e31
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .chloggen/opampextension-add-os-desc-semconv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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. filelogreceiver)
component: opampextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Report OS description semantic convention (`os.description`) as a part of non-identifying agent description.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35555]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: []
3 changes: 2 additions & 1 deletion cmd/opampsupervisor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) {
},
}

require.Equal(t, expectedDescription, ad.AgentDescription)
require.Subset(t, ad.AgentDescription.IdentifyingAttributes, expectedDescription.IdentifyingAttributes)
require.Subset(t, ad.AgentDescription.NonIdentifyingAttributes, expectedDescription.NonIdentifyingAttributes)

time.Sleep(250 * time.Millisecond)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/opampextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/text v0.17.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)
Expand Down
23 changes: 23 additions & 0 deletions extension/opampextension/opamp_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/open-telemetry/opamp-go/client"
"github.com/open-telemetry/opamp-go/client/types"
"github.com/open-telemetry/opamp-go/protobufs"
"github.com/shirou/gopsutil/v4/host"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componentstatus"
"go.opentelemetry.io/collector/confmap"
Expand All @@ -27,6 +28,8 @@ import (
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/yaml.v3"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages"
Expand Down Expand Up @@ -278,6 +281,7 @@ func (o *opampAgent) createAgentDescription() error {
if err != nil {
return err
}
description := getOSDescription(o.logger)

ident := []*protobufs.KeyValue{
stringKeyValue(semconv.AttributeServiceInstanceID, o.instanceID.String()),
Expand All @@ -291,6 +295,7 @@ func (o *opampAgent) createAgentDescription() error {
nonIdentifyingAttributeMap[semconv.AttributeOSType] = runtime.GOOS
nonIdentifyingAttributeMap[semconv.AttributeHostArch] = runtime.GOARCH
nonIdentifyingAttributeMap[semconv.AttributeHostName] = hostname
nonIdentifyingAttributeMap[semconv.AttributeOSDescription] = description

for k, v := range o.cfg.AgentDescription.NonIdentifyingAttributes {
nonIdentifyingAttributeMap[k] = v
Expand Down Expand Up @@ -367,3 +372,21 @@ func (o *opampAgent) setHealth(ch *protobufs.ComponentHealth) {
}
}
}

func getOSDescription(logger *zap.Logger) string {
info, err := host.Info()
if err != nil {
logger.Error("failed getting host info", zap.Error(err))
return runtime.GOOS
}
switch runtime.GOOS {
case "darwin":
return "macOS " + info.PlatformVersion
case "linux":
return cases.Title(language.English).String(info.Platform) + " " + info.PlatformVersion
case "windows":
return info.Platform + " " + info.PlatformVersion
default:
return runtime.GOOS
}
}
5 changes: 5 additions & 0 deletions extension/opampextension/opamp_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/extension/extensiontest"
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
"go.uber.org/zap"
)

func TestNewOpampAgent(t *testing.T) {
Expand Down Expand Up @@ -53,6 +54,7 @@ func TestNewOpampAgentAttributes(t *testing.T) {
func TestCreateAgentDescription(t *testing.T) {
hostname, err := os.Hostname()
require.NoError(t, err)
description := getOSDescription(zap.NewNop())

serviceName := "otelcol-distrot"
serviceVersion := "distro.0"
Expand All @@ -76,6 +78,7 @@ func TestCreateAgentDescription(t *testing.T) {
NonIdentifyingAttributes: []*protobufs.KeyValue{
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
stringKeyValue(semconv.AttributeHostName, hostname),
stringKeyValue(semconv.AttributeOSDescription, description),
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
},
},
Expand All @@ -99,6 +102,7 @@ func TestCreateAgentDescription(t *testing.T) {
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
stringKeyValue(semconv.AttributeHostName, hostname),
stringKeyValue(semconv.AttributeK8SPodName, "my-very-cool-pod"),
stringKeyValue(semconv.AttributeOSDescription, description),
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
},
},
Expand All @@ -119,6 +123,7 @@ func TestCreateAgentDescription(t *testing.T) {
NonIdentifyingAttributes: []*protobufs.KeyValue{
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
stringKeyValue(semconv.AttributeHostName, "override-host"),
stringKeyValue(semconv.AttributeOSDescription, description),
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
},
},
Expand Down

0 comments on commit e788e31

Please sign in to comment.