Skip to content

Commit

Permalink
Use BuildInfo.Command for identifying the collector in some AWS exp…
Browse files Browse the repository at this point in the history
…orter user agents (open-telemetry#14719)

Signed-off-by: Anthony J Mirabella <[email protected]>
  • Loading branch information
Aneurysm9 authored and shalper2 committed Dec 6, 2022
1 parent 9cf4740 commit fc596c3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix_UASource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: exporters

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Use `BuildInfo.Command` for identifying the collector in some AWS exporter user agents."

# One or more tracking issues related to the change
issues: [14719]

# (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: "Some exporters were using a build-time constant definition to change the identity of the collector binary in user agent strings. These will now use the collector service's `BuildInfo.Command` value."
4 changes: 1 addition & 3 deletions exporter/awsxrayexporter/xray_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
"go.uber.org/zap"
)

var collectorDistribution = "opentelemetry-collector-contrib"

// xrayClient represents X-Ray client.
type xrayClient struct {
xRay *xray.XRay
Expand Down Expand Up @@ -73,6 +71,6 @@ func newXRay(logger *zap.Logger, awsConfig *aws.Config, buildInfo component.Buil
func newCollectorUserAgentHandler(buildInfo component.BuildInfo) request.NamedHandler {
return request.NamedHandler{
Name: "otel.collector.UserAgentHandler",
Fn: request.MakeAddToUserAgentHandler(collectorDistribution, buildInfo.Version),
Fn: request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version),
}
}
3 changes: 2 additions & 1 deletion exporter/awsxrayexporter/xray_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestUserAgent(t *testing.T) {
logger := zap.NewNop()

buildInfo := component.BuildInfo{
Command: "test-collector-contrib",
Version: "1.0",
}

Expand All @@ -43,5 +44,5 @@ func TestUserAgent(t *testing.T) {
}, nil, nil)

x.Handlers.Build.Run(req)
assert.Contains(t, req.HTTPRequest.UserAgent(), "opentelemetry-collector-contrib/1.0")
assert.Contains(t, req.HTTPRequest.UserAgent(), "test-collector-contrib/1.0")
}
6 changes: 2 additions & 4 deletions internal/aws/cwlogs/cwlog_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs/handler"
)

var collectorDistribution = "opentelemetry-collector-contrib"

const (
// this is the retry count, the total attempts will be at most retry count + 1.
defaultRetryCount = 1
Expand Down Expand Up @@ -180,9 +178,9 @@ func (client *Client) CreateStream(logGroup, streamName *string) (token string,
}

func newCollectorUserAgentHandler(buildInfo component.BuildInfo, logGroupName string) request.NamedHandler {
fn := request.MakeAddToUserAgentHandler(collectorDistribution, buildInfo.Version)
fn := request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version)
if matchContainerInsightsPattern(logGroupName) {
fn = request.MakeAddToUserAgentHandler(collectorDistribution, buildInfo.Version, "ContainerInsights")
fn = request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, "ContainerInsights")
}
return request.NamedHandler{
Name: "otel.collector.UserAgentHandler",
Expand Down
16 changes: 11 additions & 5 deletions internal/aws/cwlogs/cwlog_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,31 +448,37 @@ func TestUserAgent(t *testing.T) {
}{
{
"emptyLogGroup",
component.BuildInfo{Version: "1.0"},
component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"},
"",
"opentelemetry-collector-contrib/1.0",
},
{
"buildInfoCommandUsed",
component.BuildInfo{Command: "test-collector-contrib", Version: "1.0"},
"",
"test-collector-contrib/1.0",
},
{
"non container insights",
component.BuildInfo{Version: "1.1"},
component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.1"},
"test-group",
"opentelemetry-collector-contrib/1.1",
},
{
"container insights EKS",
component.BuildInfo{Version: "1.0"},
component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"},
"/aws/containerinsights/eks-cluster-name/performance",
"opentelemetry-collector-contrib/1.0 (ContainerInsights)",
},
{
"container insights ECS",
component.BuildInfo{Version: "1.0"},
component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"},
"/aws/ecs/containerinsights/ecs-cluster-name/performance",
"opentelemetry-collector-contrib/1.0 (ContainerInsights)",
},
{
"container insights prometheus",
component.BuildInfo{Version: "1.0"},
component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"},
"/aws/containerinsights/cluster-name/prometheus",
"opentelemetry-collector-contrib/1.0 (ContainerInsights)",
},
Expand Down

0 comments on commit fc596c3

Please sign in to comment.