Skip to content

Commit d60fe68

Browse files
authored
Merge branch 'main' into update-upstream-dep
2 parents b897996 + 4c3c4a4 commit d60fe68

File tree

5 files changed

+13
-489
lines changed

5 files changed

+13
-489
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
### 🛑 Breaking changes 🛑
6+
7+
- (Splunk) Don't expand environment variables starting with $$ in configuration files. This behavior was introduced
8+
in v0.42.0 to support a bug causing double expansion. $$ is treated as an escape sequence representing a literal
9+
$ character ([#5134](https://github.com/signalfx/splunk-otel-collector/pull/5134))
10+
511
### 💡 Enhancements 💡
612

713
- (Splunk) Update bundled OpenJDK to [11.0.24_8](https://github.com/adoptium/temurin11-binaries/releases/tag/jdk-11.0.24%2B8) ([#5113](https://github.com/signalfx/splunk-otel-collector/pull/5113))

internal/configsource/source.go

+2-51
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ package configsource
1717
import (
1818
"context"
1919
"fmt"
20-
"log"
2120
"net/url"
2221
"os"
23-
"strconv"
2422
"strings"
2523

2624
"github.com/knadh/koanf/maps"
@@ -42,22 +40,13 @@ const (
4240
// typeAndNameSeparator is the separator that is used between type and name in type/name
4341
// composite keys.
4442
typeAndNameSeparator = '/'
45-
// dollarDollarCompatEnvVar is a temporary env var to disable backward compatibility (true by default)
46-
dollarDollarCompatEnvVar = "SPLUNK_DOUBLE_DOLLAR_CONFIG_SOURCE_COMPATIBLE"
4743
)
4844

4945
// private error types to help with testability
5046
type (
5147
errUnknownConfigSource struct{ error }
5248
)
5349

54-
var ddBackwardCompatible = func() bool {
55-
if v, err := strconv.ParseBool(strings.ToLower(os.Getenv(dollarDollarCompatEnvVar))); err == nil {
56-
return v
57-
}
58-
return true
59-
}()
60-
6150
type ConfigSource interface {
6251
// Retrieve goes to the configuration source and retrieves the selected data which
6352
// contains the value to be injected in the configuration and the corresponding watcher that
@@ -346,56 +335,18 @@ func resolveStringValue(ctx context.Context, configSources map[string]ConfigSour
346335
w := 0 // number of bytes consumed on this pass
347336

348337
switch {
349-
case s[j+1] == expandPrefixChar:
350-
// temporary backward compatibility to support updated $${config_source:value} functionality
351-
// in provided configs from 0.37.0 until 0.42.0
352-
bwCompatibilityRequired := false
353-
354-
var expanded, sourceName string
355-
var ww int
356-
if ddBackwardCompatible && len(s[j+1:]) > 2 {
357-
if s[j+2] == '{' {
358-
if expanded, ww, sourceName = getBracketedExpandableContent(s, j+2); sourceName != "" {
359-
bwCompatibilityRequired = true
360-
}
361-
} else {
362-
if expanded, ww, sourceName = getBareExpandableContent(s, j+2); sourceName != "" {
363-
if len(expanded) > (len(sourceName) + 1) {
364-
if !strings.Contains(expanded[len(sourceName)+1:], "$") {
365-
bwCompatibilityRequired = true
366-
}
367-
}
368-
}
369-
}
370-
}
371-
372-
if bwCompatibilityRequired {
373-
log.Printf(
374-
`Deprecated config source directive %q has been replaced with %q. Please update your config as necessary as this will be removed in future release. To disable this replacement set the SPLUNK_DOUBLE_DOLLAR_CONFIG_SOURCE_COMPATIBLE environment variable to "false" before restarting the Collector.`,
375-
s[j:j+2+ww], s[j+1:j+2+ww],
376-
)
377-
expandableContent = expanded
378-
w = ww + 1
379-
cfgSrcName = sourceName
380-
} else {
381-
// Escaping the prefix so $$ becomes a single $ without attempting
382-
// to treat the string after it as a config source or env var.
383-
expandableContent = string(expandPrefixChar)
384-
w = 1 // consumed a single char
385-
}
386-
387338
case s[j+1] == '{':
388339
expandableContent, w, cfgSrcName = getBracketedExpandableContent(s, j+1)
389-
390340
default:
341+
// TODO: To be deprecated removed to align with the upstream behavior
391342
expandableContent, w, cfgSrcName = getBareExpandableContent(s, j+1)
392-
393343
}
394344

395345
// At this point expandableContent contains a string to be expanded, evaluate and expand it.
396346
switch {
397347
case cfgSrcName == "":
398348
// Not a config source, expand as os.ExpandEnv
349+
// TODO: Align with confmap.strictlyTypedInput feature gate
399350
buf = osExpandEnv(buf, expandableContent, w)
400351

401352
default:

internal/configsource/testdata/envvar_cfgsrc_mix_expected.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ envvar_legacy_05: /test
1010
cfgsrc_suffix: prefix-42
1111
cfgsrc_middle: prefix-42-suffix
1212
cfgsrc_in_str: integer 42 injected as string
13-
cfgsrc_workaround_suffix: prefix-42
14-
cfgsrc_braces_workaround_suffix: prefix-42
15-
cfgsrc_braces_workaround_middle: prefix-42-suffix
16-
cfgsrc_braces_workaround_in_str: integer 42 injected as string
13+
cfgsrc_workaround_suffix: prefix-$tstcfgsrc:int_key
14+
cfgsrc_braces_workaround_suffix: prefix-${ tstcfgsrc:int_key }
15+
cfgsrc_braces_workaround_middle: prefix-${tstcfgsrc:int_key}-suffix
16+
cfgsrc_braces_workaround_in_str: integer ${ tstcfgsrc:int_key} injected as string
1717
cfgsrc_params0:
1818
p0: true
1919
p1: envvar_value

tests/general/envvar_expansion_test.go

+1-18
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,9 @@ func TestExpandedDollarSignsViaStandardEnvVar(t *testing.T) {
4141
)
4242
}
4343

44-
func TestExpandedDollarSignsViaEnvConfigSource(t *testing.T) {
45-
testutils.CheckGoldenFileWithCollectorOptions(t, "env_config_source_labels.yaml", "env_config_source_labels_expected.yaml", func(collector testutils.Collector) testutils.Collector {
46-
return collector.WithEnv(map[string]string{"AN_ENVVAR": "an-envvar-value"})
47-
},
48-
pmetrictest.IgnoreScopeVersion(),
49-
pmetrictest.IgnoreTimestamp(),
50-
pmetrictest.IgnoreStartTimestamp(),
51-
pmetrictest.IgnoreMetricDataPointsOrder(),
52-
pmetrictest.IgnoreScopeMetricsOrder(),
53-
pmetrictest.IgnoreResourceMetricsOrder(),
54-
pmetrictest.IgnoreMetricsOrder(),
55-
pmetrictest.IgnoreMetricValues(),
56-
)
57-
}
58-
5944
func TestIncompatibleExpandedDollarSignsViaEnvConfigSource(t *testing.T) {
6045
testutils.CheckGoldenFileWithCollectorOptions(t, "env_config_source_labels.yaml", "incompat_env_config_source_labels_expected.yaml", func(collector testutils.Collector) testutils.Collector {
61-
return collector.WithEnv(map[string]string{
62-
"SPLUNK_DOUBLE_DOLLAR_CONFIG_SOURCE_COMPATIBLE": "false",
63-
"AN_ENVVAR": "an-envvar-value"})
46+
return collector.WithEnv(map[string]string{"AN_ENVVAR": "an-envvar-value"})
6447
},
6548
pmetrictest.IgnoreScopeVersion(),
6649
pmetrictest.IgnoreTimestamp(),

0 commit comments

Comments
 (0)