Skip to content

Commit d37d19e

Browse files
fix: always re-add config values provided with --config after internal config values (#164)
### Description After switching to the otelcol's internal `--config` flag, the bundled config files provided by the `observe-agent` now are processed _after_ any configuration provided with `--config`. This makes it so the bundled config values cannot be overwritten via the `--config` flag (only via the `otel_config_overrides` option). This fix makes the flag take precedence again. Ex: ``` $ cat ./hc_test.yaml extensions: health_check: endpoint: 0.0.0.0:13137 ``` Current 2.0.0: ``` $ observe-agent start --config ./hc_test.yaml # ... 2025-02-10T11:10:54.862-0600 info healthcheckextension/healthcheckextension.go:32 Starting health_check extension {"kind": "extension", "name": "health_check", "config": {"Endpoint":"localhost:13133","TLSSetting":null,"CORS":null,"Auth":null,"MaxRequestBodySize":0,"IncludeMetadata":false,"ResponseHeaders":null,"CompressionAlgorithms":null,"ReadTimeout":0,"ReadHeaderTimeout":0,"WriteTimeout":0,"IdleTimeout":0,"Path":"/status","ResponseBody":null,"CheckCollectorPipeline":{"Enabled":false,"Interval":"5m","ExporterFailureThreshold":5}}} ``` ^ note the `"Endpoint":"localhost:13133"` After this fix: ``` $ ./observe-agent start --config ./hc_test.yaml # ... 2025-02-10T11:11:41.227-0600 info healthcheckextension/healthcheckextension.go:32 Starting health_check extension {"kind": "extension", "name": "health_check", "config": {"Endpoint":"0.0.0.0:13137","TLSSetting":null,"CORS":null,"Auth":null,"MaxRequestBodySize":0,"IncludeMetadata":false,"ResponseHeaders":null,"CompressionAlgorithms":null,"ReadTimeout":0,"ReadHeaderTimeout":0,"WriteTimeout":0,"IdleTimeout":0,"Path":"/status","ResponseBody":null,"CheckCollectorPipeline":{"Enabled":false,"Interval":"5m","ExporterFailureThreshold":5}}} ``` ^ note the `"Endpoint":"0.0.0.0:13137"` ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --------- Co-authored-by: obs-gh-nikhildua <[email protected]>
1 parent 97abd25 commit d37d19e

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

integration/modules/create_ec2/locals.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ locals {
8989

9090
WINDOWS_SERVER_2016_BASE = {
9191
ami_instance_type = "t3.small"
92-
ami_id = "ami-02884c2ff86636807"
92+
ami_id = "ami-02e77d98d01fe65cd"
9393
ami_description = "Microsoft Windows Server 2016 with Desktop Experience Locale English AMI provided by Amazon"
9494
default_user = "Administrator"
9595
sleep = 120
@@ -102,7 +102,7 @@ locals {
102102

103103
WINDOWS_SERVER_2019_BASE = {
104104
ami_instance_type = "t3.small"
105-
ami_id = "ami-08f810c9fec974bb3"
105+
ami_id = "ami-0965ccda58d4f713f"
106106
ami_description = "Microsoft Windows Server 2019 with Desktop Experience Locale English AMI provided by Amazon"
107107
default_user = "Administrator"
108108
sleep = 120
@@ -115,7 +115,7 @@ locals {
115115

116116
WINDOWS_SERVER_2022_BASE = {
117117
ami_instance_type = "t3.small"
118-
ami_id = "ami-00bedb8509ebcc120"
118+
ami_id = "ami-055a418b44c502d59"
119119
ami_description = "Microsoft Windows Server 2022 Full Locale English AMI provided by Amazon"
120120
default_user = "Administrator"
121121
sleep = 120

internal/commands/start/start.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package start
66
import (
77
"context"
88
"os"
9+
"strings"
910

1011
logger "github.com/observeinc/observe-agent/internal/commands/util"
1112
"github.com/observeinc/observe-agent/internal/connections"
@@ -55,15 +56,34 @@ collector on the current host.`
5556
// Modify the run function so we can pass in our packaged config files.
5657
originalRunE := otleCmd.RunE
5758
otleCmd.RunE = func(cmd *cobra.Command, args []string) error {
58-
configFilePaths, cleanup, err := SetupAndGetConfigFiles(DefaultLoggerCtx())
59+
observeAgentConfigs, cleanup, err := SetupAndGetConfigFiles(DefaultLoggerCtx())
5960
if cleanup != nil {
6061
defer cleanup()
6162
}
6263
if err != nil {
6364
return err
6465
}
6566
configFlag := otleCmd.Flags().Lookup("config")
66-
for _, path := range configFilePaths {
67+
// The otelcol config flag has a lot of functionality that we want to utilize, but the flag isn't exposed to
68+
// the library's callers in the code. Our workaround is to use the original otelcol command as our `start`
69+
// command and add our bundled config files to the config flag.
70+
//
71+
// However, we want any overrides that users provide via `--config` to take precedence, so we need to add our
72+
// config values _before_ any current values. Since we can only append to the end of the flag, we add our
73+
// bundled configs, then *re-add* the original config values.
74+
originalConfigStr := configFlag.Value.String()
75+
// This string is formatted as "[path1, path2, ...]"
76+
// see: https://github.com/open-telemetry/opentelemetry-collector/blob/v0.118.0/otelcol/flags.go#L28-L30
77+
// Trim the surrounding brackets, then split on ", "
78+
var originalConfigs []string
79+
if len(originalConfigStr) > 2 {
80+
originalConfigStr = originalConfigStr[1 : len(originalConfigStr)-1]
81+
originalConfigs = strings.Split(originalConfigStr, ", ")
82+
}
83+
for _, path := range observeAgentConfigs {
84+
configFlag.Value.Set(path)
85+
}
86+
for _, path := range originalConfigs {
6787
configFlag.Value.Set(path)
6888
}
6989
return originalRunE(cmd, args)

0 commit comments

Comments
 (0)