diff --git a/.chloggen/testbed-configurable-executable.yaml b/.chloggen/testbed-configurable-executable.yaml new file mode 100755 index 000000000000..1a938cdc6f3e --- /dev/null +++ b/.chloggen/testbed-configurable-executable.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# 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: testbed + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add `WithAgentExePath`, which allows setting the path of the Collector executable. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [23258] + +# (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: diff --git a/testbed/testbed/child_process_collector.go b/testbed/testbed/child_process_collector.go index 90b4c39f6bb0..cfed36685cbb 100644 --- a/testbed/testbed/child_process_collector.go +++ b/testbed/testbed/child_process_collector.go @@ -30,7 +30,7 @@ type childProcessCollector struct { // Path to agent executable. If unset the default executable in // bin/otelcol_{{.GOOS}}_{{.GOARCH}} will be used. // Can be set for example to use the unstable executable for a specific test. - AgentExePath string + agentExePath string // Descriptive name of the process name string @@ -81,9 +81,24 @@ type childProcessCollector struct { ramMiBMax uint32 } -// NewChildProcessCollector crewtes a new OtelcolRunner as a child process on the same machine executing the test. -func NewChildProcessCollector() OtelcolRunner { - return &childProcessCollector{} +type ChildProcessOption func(*childProcessCollector) + +// NewChildProcessCollector creates a new OtelcolRunner as a child process on the same machine executing the test. +func NewChildProcessCollector(options ...ChildProcessOption) OtelcolRunner { + col := &childProcessCollector{} + + for _, option := range options { + option(col) + } + + return col +} + +// WithAgentExePath sets the path of the Collector executable +func WithAgentExePath(exePath string) ChildProcessOption { + return func(cpc *childProcessCollector) { + cpc.agentExePath = exePath + } } func (cp *childProcessCollector) PrepareConfig(configStr string) (configCleanup func(), err error) { @@ -155,10 +170,10 @@ func (cp *childProcessCollector) Start(params StartParams) error { cp.doneSignal = make(chan struct{}) cp.resourceSpec = params.resourceSpec - if cp.AgentExePath == "" { - cp.AgentExePath = GlobalConfig.DefaultAgentExeRelativeFile + if cp.agentExePath == "" { + cp.agentExePath = GlobalConfig.DefaultAgentExeRelativeFile } - exePath := expandExeFileName(cp.AgentExePath) + exePath := expandExeFileName(cp.agentExePath) exePath, err := filepath.Abs(exePath) if err != nil { return err diff --git a/testbed/testbed/child_process_collector_test.go b/testbed/testbed/child_process_collector_test.go new file mode 100644 index 000000000000..24a58f1bcbf1 --- /dev/null +++ b/testbed/testbed/child_process_collector_test.go @@ -0,0 +1,20 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package testbed // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed" + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestAgentExeOption(t *testing.T) { + path := "bin/otelcontribcol" + col := NewChildProcessCollector(WithAgentExePath(path)) + + cpc, ok := col.(*childProcessCollector) + + require.True(t, ok) + require.Equal(t, path, cpc.agentExePath) +}