Skip to content

Commit 8b10209

Browse files
authored
[testbed] Allow setting path of child process Collector executable (open-telemetry#23258)
A refactor that unexported the struct unintentionally made it so the executable path could not be set. This keeps the struct unexported, but adds an option to allow setting the path. I'm open to making the struct public again if that's preferred, this just seemed like the most straightforward method. I also made agentExePath private to make it clear it's not meant to be accessed outside the package. --------- Co-authored-by: Evan Bradley <[email protected]>
1 parent 8a2ac13 commit 8b10209

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: enhancement
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: testbed
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Add `WithAgentExePath`, which allows setting the path of the Collector executable.
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [23258]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

testbed/testbed/child_process_collector.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type childProcessCollector struct {
3030
// Path to agent executable. If unset the default executable in
3131
// bin/otelcol_{{.GOOS}}_{{.GOARCH}} will be used.
3232
// Can be set for example to use the unstable executable for a specific test.
33-
AgentExePath string
33+
agentExePath string
3434

3535
// Descriptive name of the process
3636
name string
@@ -81,9 +81,24 @@ type childProcessCollector struct {
8181
ramMiBMax uint32
8282
}
8383

84-
// NewChildProcessCollector crewtes a new OtelcolRunner as a child process on the same machine executing the test.
85-
func NewChildProcessCollector() OtelcolRunner {
86-
return &childProcessCollector{}
84+
type ChildProcessOption func(*childProcessCollector)
85+
86+
// NewChildProcessCollector creates a new OtelcolRunner as a child process on the same machine executing the test.
87+
func NewChildProcessCollector(options ...ChildProcessOption) OtelcolRunner {
88+
col := &childProcessCollector{}
89+
90+
for _, option := range options {
91+
option(col)
92+
}
93+
94+
return col
95+
}
96+
97+
// WithAgentExePath sets the path of the Collector executable
98+
func WithAgentExePath(exePath string) ChildProcessOption {
99+
return func(cpc *childProcessCollector) {
100+
cpc.agentExePath = exePath
101+
}
87102
}
88103

89104
func (cp *childProcessCollector) PrepareConfig(configStr string) (configCleanup func(), err error) {
@@ -155,10 +170,10 @@ func (cp *childProcessCollector) Start(params StartParams) error {
155170
cp.doneSignal = make(chan struct{})
156171
cp.resourceSpec = params.resourceSpec
157172

158-
if cp.AgentExePath == "" {
159-
cp.AgentExePath = GlobalConfig.DefaultAgentExeRelativeFile
173+
if cp.agentExePath == "" {
174+
cp.agentExePath = GlobalConfig.DefaultAgentExeRelativeFile
160175
}
161-
exePath := expandExeFileName(cp.AgentExePath)
176+
exePath := expandExeFileName(cp.agentExePath)
162177
exePath, err := filepath.Abs(exePath)
163178
if err != nil {
164179
return err
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package testbed // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestAgentExeOption(t *testing.T) {
13+
path := "bin/otelcontribcol"
14+
col := NewChildProcessCollector(WithAgentExePath(path))
15+
16+
cpc, ok := col.(*childProcessCollector)
17+
18+
require.True(t, ok)
19+
require.Equal(t, path, cpc.agentExePath)
20+
}

0 commit comments

Comments
 (0)