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

Default value in collector config is interpreted as integer/float, where a string is expected. There is no way to typehint #11879

Open
timbeemster opened this issue Dec 13, 2024 · 4 comments
Labels
area:confmap bug Something isn't working

Comments

@timbeemster
Copy link

What happened?

Description

In our setup we use the VERSION environment variable to set a dimension on metrics, so we can query our metrics based on the version of the application.
The version is sourced in the environment variables and consists of a combination of numbers and letters.
It has come to our attention that in a newer version (v109) the spanmetrics connector does not allow a default of only digits to be set.
Similarly, if there are only digits and the letter e, it will try to decode the value as a float.

For this problem I went ahead and opened a bug report in the spanmetrics project: open-telemetry/opentelemetry-collector-contrib#36786 - however, there it was suggested that the actual problem is probably in the confmap component.

A related issue: #10552

I have not found a way to force the environment variable to be interpreted as a string value.

Steps to Reproduce

I've created a minimal setup in a public repo: https://github.com/timbeemster/otelcol-custom/blob/main/README
Build the docker image and run the setup.

Expected Result

A running otel collector

Actual Result

Error message on startup (see log output section)

Let me know if I can assist in debugging the problem.

Collector version

v0.109.0

Environment information

Environment

OS: Golang base image for building + Debian12 (distroless variant for running)
Compiler(if manually compiled): golang:1.23.2

(see: https://github.com/timbeemster/otelcol-custom/blob/main/Dockerfile )

OpenTelemetry Collector configuration

builder config: https://github.com/timbeemster/otelcol-custom/blob/main/otel-builder-config.yml
collector config: https://github.com/timbeemster/otelcol-custom/blob/main/otel-collector-config.yml

Log output

Error: failed to get config: cannot unmarshal the configuration: decoding failed due to the following error(s):

error decoding 'connectors': error reading configuration for "spanmetrics": decoding failed due to the following error(s):

'dimensions[0].default' expected type 'string', got unconvertible type 'float64', value: '1.23e+06'
2024/12/11 15:45:40 collector server run finished with error: failed to get config: cannot unmarshal the configuration: decoding failed due to the following error(s):

error decoding 'connectors': error reading configuration for "spanmetrics": decoding failed due to the following error(s):

'dimensions[0].default' expected type 'string', got unconvertible type 'float64', value: '1.23e+06'

Additional context

No response

@timbeemster timbeemster added the bug Something isn't working label Dec 13, 2024
@mx-psi
Copy link
Member

mx-psi commented Dec 16, 2024

@timbeemster Thanks for reporting, I am able to reproduce in the latest version.

Looks like the type is *string for this field https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/f72ef07e008b03eb42363ed77296d9351bb34d81/connector/spanmetricsconnector/config.go#L31

which probably explains this.

The workaround is to use a YAML explicit tag, setting VERSION='!!str <version here>' works for me on the latest version.

@timbeemster
Copy link
Author

Hi @mx-psi, thanks for reaching out.
I'm not 100% sure, but I think changing the config to:

default: '!!str ${VERSION}'

would simply set the version number to the actual string: !!str ${VERSION}

I've done a test with a config without the quotes:
default: !!str ${VERSION}
but this is not accepted in both 109 and 115.
I have the feeling it might have something to do with the extracting the environment variable..

@mx-psi
Copy link
Member

mx-psi commented Dec 17, 2024

Sorry I meant an environment variable with value !!str 1234, without the quotes (the quotes were just how I passed that value on bash).

@timbeemster
Copy link
Author

I've found that this config is only a "default" that is used when the gitHash property is not available.
Funnily enough, our Spans always have the gitHash attribute already.
The workarond was dead simple: not use a default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:confmap bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants