Skip to content

Commit 929656d

Browse files
authored
[cmd/opampsupervisor] Fix merging lists when using local config (#39947)
1 parent a0044fb commit 929656d

File tree

5 files changed

+60
-36
lines changed

5 files changed

+60
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: cmd/opampsupervisor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix slice merging when using local configuration files
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [39947]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

cmd/opampsupervisor/e2e_test.go

+24-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"path"
2424
"path/filepath"
2525
"runtime"
26+
"strconv"
2627
"strings"
2728
"sync/atomic"
2829
"testing"
@@ -431,33 +432,38 @@ func TestSupervisorStartsCollectorWithRemoteConfigAndExecParams(t *testing.T) {
431432
require.NoError(t, err)
432433
t.Cleanup(func() { outputFile.Close() })
433434

435+
secondHealthcheckPort, err := findRandomPort()
436+
require.NoError(t, err)
437+
434438
// fill env variables passed via parameters which are used in the collector config passed via config_files param
435439
s := newSupervisor(t, "exec_config", map[string]string{
436-
"url": server.addr,
437-
"storage_dir": storageDir,
438-
"inputLogFile": inputFile.Name(),
439-
"outputLogFile": outputFile.Name(),
440+
"url": server.addr,
441+
"storage_dir": storageDir,
442+
"inputLogFile": inputFile.Name(),
443+
"outputLogFile": outputFile.Name(),
444+
"healthcheckPort": strconv.Itoa(secondHealthcheckPort),
440445
})
441446

442447
require.Nil(t, s.Start())
443448
defer s.Shutdown()
444449

445450
waitForSupervisorConnection(server.supervisorConnected, true)
446451

447-
// check health
448-
require.Eventually(t, func() bool {
449-
resp, err := http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d", healthcheckPort))
450-
if err != nil {
451-
t.Logf("Failed healthcheck: %s", err)
452-
return false
453-
}
454-
require.NoError(t, resp.Body.Close())
455-
if resp.StatusCode >= 300 || resp.StatusCode < 200 {
456-
t.Logf("Got non-2xx status code: %d", resp.StatusCode)
457-
return false
458-
}
459-
return true
460-
}, 3*time.Second, 100*time.Millisecond)
452+
for _, port := range []int{healthcheckPort, secondHealthcheckPort} {
453+
require.Eventually(t, func() bool {
454+
resp, err := http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d", port))
455+
if err != nil {
456+
t.Logf("Failed healthcheck: %s", err)
457+
return false
458+
}
459+
require.NoError(t, resp.Body.Close())
460+
if resp.StatusCode >= 300 || resp.StatusCode < 200 {
461+
t.Logf("Got non-2xx status code: %d", resp.StatusCode)
462+
return false
463+
}
464+
return true
465+
}, 3*time.Second, 100*time.Millisecond)
466+
}
461467

462468
// check that collector uses filelog receiver and file exporter from config passed via config_files param
463469
n, err := inputFile.WriteString("{\"body\":\"hello, world\"}\n")

cmd/opampsupervisor/supervisor/commander/commander.go

+3-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"path/filepath"
14+
"slices"
1415
"sync/atomic"
1516
"time"
1617

@@ -72,12 +73,9 @@ func (c *Commander) Start(ctx context.Context) error {
7273
}
7374
c.logger.Debug("Starting agent", zap.String("agent", c.cfg.Executable))
7475

75-
if err := c.buildConfigs(); err != nil {
76-
return err
77-
}
78-
c.args = append(c.args, c.cfg.Arguments...)
76+
args := slices.Concat(c.args, c.cfg.Arguments)
7977

80-
c.cmd = exec.CommandContext(ctx, c.cfg.Executable, c.args...) // #nosec G204
78+
c.cmd = exec.CommandContext(ctx, c.cfg.Executable, args...) // #nosec G204
8179
c.cmd.Env = common.EnvVarMapToEnvMapSlice(c.cfg.Env)
8280
c.cmd.SysProcAttr = sysProcAttrs()
8381

@@ -88,19 +86,6 @@ func (c *Commander) Start(ctx context.Context) error {
8886
return c.startNormal()
8987
}
9088

91-
func (c *Commander) buildConfigs() error {
92-
for _, conf := range c.cfg.ConfigFiles {
93-
fileName := filepath.Base(conf)
94-
newPath := filepath.Join(c.logsDir, fileName)
95-
if err := common.CopyFile(conf, newPath); err != nil {
96-
return fmt.Errorf("cannot copy config file '%s' to storage directory: %s", conf, err.Error())
97-
}
98-
c.args = append(c.args, "--config")
99-
c.args = append(c.args, newPath)
100-
}
101-
return nil
102-
}
103-
10489
func (c *Commander) Restart(ctx context.Context) error {
10590
c.logger.Debug("Restarting agent", zap.String("agent", c.cfg.Executable))
10691
if err := c.Stop(ctx); err != nil {

cmd/opampsupervisor/testdata/collector/simple_pipeline_env.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ exporters:
88
file:
99
path: ${OUT_FILE}
1010

11+
extensions:
12+
health_check/e2e:
13+
endpoint: "localhost:${HEALTHCHECK_PORT}"
14+
1115
service:
16+
extensions: [health_check/e2e]
1217
pipelines:
1318
logs:
1419
receivers: [filelog]

cmd/opampsupervisor/testdata/supervisor/supervisor_exec_config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ agent:
1919
env:
2020
OUT_FILE: '{{.outputLogFile}}'
2121
IN_FILE: '{{.inputLogFile}}'
22+
HEALTHCHECK_PORT: '{{.healthcheckPort}}'

0 commit comments

Comments
 (0)