Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into unify-env-var-gate-…
Browse files Browse the repository at this point in the history
…stable
  • Loading branch information
TylerHelmuth committed Aug 6, 2024
2 parents 067d3f1 + 41fa6ff commit 6caabcd
Show file tree
Hide file tree
Showing 31 changed files with 788 additions and 140 deletions.
25 changes: 25 additions & 0 deletions .chloggen/NewCommandMustSetProvider.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: otelcol

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Delete deprecated NewCommandMustSetProvider

# One or more tracking issues or pull requests related to the change
issues: [10778]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
25 changes: 25 additions & 0 deletions .chloggen/int-telemetry-otlp-options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Implement the `temporality_preference` setting for internal telemetry exported via OTLP"

# One or more tracking issues or pull requests related to the change
issues: [ 10745 ]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [ user ]
26 changes: 26 additions & 0 deletions .chloggen/mx-psi_add-string-representation-for-everything.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use this changelog template to create an entry for release notes.

# 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. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow using any YAML structure as a string when loading configuration.

# One or more tracking issues or pull requests related to the change
issues: [10800]

# (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: |
Previous to this change, slices could not be used as strings in configuration.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
26 changes: 26 additions & 0 deletions .chloggen/mx-psi_fix-invalid-yaml-string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: If loading an invalid YAML string through a provider, use it verbatim instead of erroring out.

# One or more tracking issues or pull requests related to the change
issues: [10759]

# (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: |
This makes the ${env:ENV} syntax closer to how ${ENV} worked before unifying syntaxes.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_remove-has-original.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove original string representation if invalid.

# One or more tracking issues or pull requests related to the change
issues: [10787]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_restrict-providers-scheme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# 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. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Check that providers have a correct scheme when building a confmap.Resolver.

# One or more tracking issues or pull requests related to the change
issues: [10786]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
25 changes: 25 additions & 0 deletions .chloggen/stabilize_client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# 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. otlpreceiver)
component: client

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Mark module as stable.

# One or more tracking issues or pull requests related to the change
issues: [10775]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
7 changes: 0 additions & 7 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ jobs:
runs-on: ${{ matrix.runner }}
needs: [setup-environment]
steps:
- name: Set up arkade
uses: alexellis/setup-arkade@b1816384b2260cfd2c023c6798d26075786cfc7f # v3
- name: Install vmmeter
run: |
sudo -E arkade oci install ghcr.io/openfaasltd/vmmeter:latest --path /usr/local/bin/
- name: Run vmmeter
uses: self-actuated/vmmeter-action@c7e2162e39294a810cab647cacc215ecd68a44f6 # v1
- name: Checkout Repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Go
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'Skip Contrib Tests') }}
strategy:
fail-fast: false
matrix:
group:
- receiver-0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: SARIF file
path: results.sarif
Expand Down
3 changes: 0 additions & 3 deletions confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ func caseSensitiveMatchName(a, b string) bool {
func castTo(exp expandedValue, useOriginal bool) (any, error) {
// If the target field is a string, use `exp.Original` or fail if not available.
if globalgates.StrictlyTypedInputGate.IsEnabled() && useOriginal {
if !exp.HasOriginal {
return nil, fmt.Errorf("cannot expand value to string: original value not set")
}
return exp.Original, nil
}
// Otherwise, use the parsed value (previous behavior).
Expand Down
5 changes: 2 additions & 3 deletions confmap/confmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,8 @@ func TestRecursiveUnmarshaling(t *testing.T) {
func TestExpandedValue(t *testing.T) {
cm := NewFromStringMap(map[string]any{
"key": expandedValue{
Value: 0xdeadbeef,
HasOriginal: true,
Original: "original",
Value: 0xdeadbeef,
Original: "original",
}})
assert.Equal(t, 0xdeadbeef, cm.Get("key"))
assert.Equal(t, map[string]any{"key": 0xdeadbeef}, cm.ToStringMap())
Expand Down
30 changes: 11 additions & 19 deletions confmap/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,19 @@ func (mr *Resolver) expandValue(ctx context.Context, value any) (any, bool, erro
// At this point we don't know the target field type, so we need to expand the original representation as well.
originalExpanded, originalChanged, err := mr.expandValue(ctx, v.Original)
if err != nil {
return nil, false, err
// The original representation is not valid, return the expanded value.
return expanded, changed, nil
}

if originalExpanded, ok := originalExpanded.(string); ok {
// If the original representation is a string, return the expanded value with the original representation.
return expandedValue{
Value: expanded,
Original: originalExpanded,
HasOriginal: true,
Value: expanded,
Original: originalExpanded,
}, changed || originalChanged, nil
}

result := expandedValue{
Value: expanded,
Original: v.Original,
HasOriginal: v.HasOriginal,
}

return result, changed || originalChanged, nil
return expanded, changed, nil
case string:
if !strings.Contains(v, "${") || !strings.Contains(v, "}") {
// No URIs to expand.
Expand Down Expand Up @@ -158,10 +152,7 @@ func (mr *Resolver) findURI(input string) string {
type expandedValue struct {
// Value is the expanded value.
Value any
// HasOriginal is true if the original representation is set.
HasOriginal bool
// Original is the original representation of the value.
// It is only valid if HasOriginal is true.
Original string
}

Expand All @@ -182,18 +173,19 @@ func (mr *Resolver) findAndExpandURI(ctx context.Context, input string) (any, bo
return input, false, err
}

expanded := expandedValue{}
expanded.Value, err = ret.AsRaw()
val, err := ret.AsRaw()
if err != nil {
return input, false, err
}

if asStr, err2 := ret.AsString(); err2 == nil {
expanded.HasOriginal = true
expanded.Original = asStr
return expandedValue{
Value: val,
Original: asStr,
}, true, nil
}

return expanded, true, err
return val, true, nil
}
expanded, err := mr.expandURI(ctx, uri)
if err != nil {
Expand Down
29 changes: 3 additions & 26 deletions confmap/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ func TestResolverDoneNotExpandOldEnvVars(t *testing.T) {
envProvider := newFakeProvider("env", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved("some string")
})
emptySchemeProvider := newFakeProvider("", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved("some string")
})

resolver, err := NewResolver(ResolverSettings{URIs: []string{"test:"}, ProviderFactories: []ProviderFactory{fileProvider, envProvider, emptySchemeProvider}, ConverterFactories: nil})
resolver, err := NewResolver(ResolverSettings{URIs: []string{"test:"}, ProviderFactories: []ProviderFactory{fileProvider, envProvider}, ConverterFactories: nil})
require.NoError(t, err)

// Test that expanded configs are the same with the simple config with no env vars.
Expand Down Expand Up @@ -509,12 +506,8 @@ func TestResolverExpandInvalidScheme(t *testing.T) {
panic("must not be called")
})

resolver, err := NewResolver(ResolverSettings{URIs: []string{"input:"}, ProviderFactories: []ProviderFactory{provider, testProvider}, ConverterFactories: nil})
require.NoError(t, err)

_, err = resolver.Resolve(context.Background())

assert.EqualError(t, err, `invalid uri: "g_c_s:VALUE"`)
_, err := NewResolver(ResolverSettings{URIs: []string{"input:"}, ProviderFactories: []ProviderFactory{provider, testProvider}, ConverterFactories: nil})
assert.ErrorContains(t, err, "invalid 'confmap.Provider' scheme")
}

func TestResolverExpandInvalidOpaqueValue(t *testing.T) {
Expand Down Expand Up @@ -549,22 +542,6 @@ func TestResolverExpandUnsupportedScheme(t *testing.T) {
assert.EqualError(t, err, `scheme "unsupported" is not supported for uri "unsupported:VALUE"`)
}

func TestResolverExpandStringValueInvalidReturnValue(t *testing.T) {
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrievedFromYAML([]byte(`test: "localhost:${test:PORT}"`))
})

testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrievedFromYAML([]byte("[1243]"))
})

resolver, err := NewResolver(ResolverSettings{URIs: []string{"input:"}, ProviderFactories: []ProviderFactory{provider, testProvider}, ConverterFactories: nil})
require.NoError(t, err)

_, err = resolver.Resolve(context.Background())
assert.EqualError(t, err, `expanding ${test:PORT}: retrieved value does not have unambiguous string representation: [1243]`)
}

func TestResolverDefaultProviderExpand(t *testing.T) {
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]any{"foo": "${HOST}"})
Expand Down
22 changes: 22 additions & 0 deletions confmap/internal/e2e/testdata/issue-10787-main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:

exporters:
${file:testdata/issue-10787-snippet.yaml}

service:
telemetry:
metrics:
level: detailed
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging]
3 changes: 3 additions & 0 deletions confmap/internal/e2e/testdata/issue-10787-snippet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ${hello.world}
logging:
verbosity: detailed
Loading

0 comments on commit 6caabcd

Please sign in to comment.