Skip to content

Commit

Permalink
[testbed] Allow setting path of child process Collector executable (o…
Browse files Browse the repository at this point in the history
…pen-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]>
  • Loading branch information
evan-bradley and evan-bradley committed Jun 9, 2023
1 parent 8a2ac13 commit 8b10209
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .chloggen/testbed-configurable-executable.yaml
Original file line number Diff line number Diff line change
@@ -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:
29 changes: 22 additions & 7 deletions testbed/testbed/child_process_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions testbed/testbed/child_process_collector_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 8b10209

Please sign in to comment.