Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue enforcing quoted values in config #10659

Closed
MovieStoreGuy opened this issue Jul 18, 2024 · 3 comments · Fixed by #10618 or #11241
Closed

Issue enforcing quoted values in config #10659

MovieStoreGuy opened this issue Jul 18, 2024 · 3 comments · Fixed by #10618 or #11241
Labels
bug Something isn't working

Comments

@MovieStoreGuy
Copy link
Contributor

Describe the bug

When providing a configuration that uses the env provider, it does not preserve the quotes around the "${env:...}".

This means when a complaint time RFC string is supplied, it gets converted into a time.Time value instead of the expected string, which then stops the config from being valid.

Steps to reproduce

  1. Set an env var with a timestamp value
    a. export BUILT_TS="2006-01-02T15:04:05Z07:00"
  2. Reference var in configuration.
    a. value : "${env:BUILT_TS}"
  3. Have collector run with configuration using reference variable.

What did you expect to see?
Considering the provider is in quotes, it should not strip those values

What did you see instead?
Upon running the collector with the provider configuration, the error is show as:

Error: failed to get config: cannot resolve the configuration: unsupported type=time.Time for retrieved config, ensure that values are wrapped in quotes

What version did you use?
v0.105.0

What config did you use?

processors:
  resource/static:
    attributes:
    - key: build.version
      action: insert
      value: "${BUILD_VERSION}"

Environment
Linux, go v1.23.4

Additional context
I've tried a few different combinations, but this currently works in v0.103.0 but upgrading to v0.105.0 surfaced this.

I've also tried:

\"${env:var}\" # Didn't work with error: retrieved value does not have unambiguous string representation: <nil>
"${env:var}"  # moved to calling the env provider directly, same error as reported
@mx-psi
Copy link
Member

mx-psi commented Jul 18, 2024

I believe #10618 would fix this, I will add a test on this specific case.

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Jul 18, 2024

@MovieStoreGuy I was not able to reproduce this on v0.105.0 in a binary or the confmap e2e test from my local computer (macos, arm46).

export BUILT_TS="2006-01-02T15:04:05Z07:00"
receivers:
  nop:

processors:
  resource:
    attributes:
      - key: build.version
        value: "${env:BUILT_TS}"
        action: insert

exporters:
  nop:

service:
  telemetry:
    logs:
      level: debug
  pipelines:
    traces:
      receivers:
        - nop
      processors:
        - resource
      exporters:
        - nop

And in the confmap e2e tests the following tests pass:

{
	value:       "2006-01-02T15:04:05Z07:00",
	targetField: TargetFieldString,
	expected:    "2006-01-02T15:04:05Z07:00",
},
{
	value:       "2006-01-02T15:04:05Z07:00",
	targetField: TargetFieldInlineString,
	expected:    "inline field with 2006-01-02T15:04:05Z07:00 expansion",
},

@TylerHelmuth
Copy link
Member

I believe this is the root cause of the issue

if uri == input {
		// If the value is a single URI, then the return value can be anything.
		// This is the case `foo: ${file:some_extra_config.yml}`.
		ret, err := mr.expandURI(ctx, input)
		if err != nil {
			return input, false, err
		}

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

When the env var being expanded is the entire string, it is expanded and the returned value and it's type is kept as is. I agree that @mx-psi PR will fix the issue.

In the meantime you can use str!! ${env:BUILT_TS} or add "" to the env var value.

@mx-psi mx-psi closed this as completed in 0001db2 Jul 25, 2024
dmitryax pushed a commit that referenced this issue Sep 27, 2024
…ts (#11241)

#### Description

This addresses
#10659.
In #10800
we removed restrictions on the types that can be allowed if expanded but
in our case, this still fails because of the checks existing in
`provider.checkRawConfType()`

This adds `time.Time` as a type in the `provider.checkRawConfType()`
instead of removing it completely.

#### Link to tracking issue
Fixes
#10659

<!--Describe what testing was performed and which tests were added.-->
#### Testing
- added a test case to handle time formats in provider.go and expand.go
- added an e2e test case to handle time formats
jackgopack4 pushed a commit to jackgopack4/opentelemetry-collector that referenced this issue Oct 8, 2024
…ts (open-telemetry#11241)

#### Description

This addresses
open-telemetry#10659.
In open-telemetry#10800
we removed restrictions on the types that can be allowed if expanded but
in our case, this still fails because of the checks existing in
`provider.checkRawConfType()`

This adds `time.Time` as a type in the `provider.checkRawConfType()`
instead of removing it completely.

#### Link to tracking issue
Fixes
open-telemetry#10659

<!--Describe what testing was performed and which tests were added.-->
#### Testing
- added a test case to handle time formats in provider.go and expand.go
- added an e2e test case to handle time formats
HongChenTW pushed a commit to HongChenTW/opentelemetry-collector that referenced this issue Dec 19, 2024
…ts (open-telemetry#11241)

#### Description

This addresses
open-telemetry#10659.
In open-telemetry#10800
we removed restrictions on the types that can be allowed if expanded but
in our case, this still fails because of the checks existing in
`provider.checkRawConfType()`

This adds `time.Time` as a type in the `provider.checkRawConfType()`
instead of removing it completely.

#### Link to tracking issue
Fixes
open-telemetry#10659

<!--Describe what testing was performed and which tests were added.-->
#### Testing
- added a test case to handle time formats in provider.go and expand.go
- added an e2e test case to handle time formats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants