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

[exporter/influxdb] influxdb exporter does not accept v1_compatibility config #27084

Closed
otbe opened this issue Sep 23, 2023 · 5 comments
Closed
Labels
bug Something isn't working exporter/influxdb help wanted Extra attention is needed

Comments

@otbe
Copy link

otbe commented Sep 23, 2023

Component(s)

exporter/influxdb

What happened?

Description

I would like to use the influxdb exporter to send metrics to influx that the opentelemetry collector receives via OTLP.
Sadly I have to use the influx v1 compat mode and it seems like Im not able to configure it. Looks like theres a runtime error during constructing the basic auth header.

Steps to Reproduce

You can simple take the config from below and put it into a docker container.
Something like this works in my machine: docker run -v $(PWD)/otel.yml:/etc/otelcol-contrib/config.yaml otel/opentelemetry-collector-contrib:0.85.0

Expected Result

Should work :)

Actual Result

panic, runtime error. Collector stops working at all.

Collector version

0.85.0

Environment information

Environment

Docker image: otel/opentelemetry-collector-contrib:0.85.0

OpenTelemetry Collector configuration

extensions:
  health_check:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 100
    spike_limit_mib: 20

exporters:
  influxdb:
    endpoint: https://foo.bar
    log_record_dimensions:
    span_dimensions:
    v1_compatibility:
      enabled: true
      db: foo
      username: bar
      password: baz

service:
  pipelines:
    metrics:
      receivers: [ otlp ]
      processors: [ memory_limiter ]
      exporters: [ influxdb ]

  extensions: [ health_check ]

Log output

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
encoding/base64.(*Encoding).Encode(0x68471e0?, {0x0?, 0x6fe1906?, 0x7da5688?}, {0x4001dfa478?, 0x40027b0a20?, 0x4001dfa448?})
        encoding/base64/base64.go:158 +0x284
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/influxdbexporter.composeWriteURL(0x4002822900)
        github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/writer.go:92 +0x25c
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/influxdbexporter.newInfluxHTTPWriter({0x7dc84e0?, 0x4002841aa0}, 0x4002822900, {0x40023a4620, {0x7dcb000, 0x400282ec00}, {0x7dfd2a0, 0x40028411e0}, 0x0, {0x4002846740}})
        github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/writer.go:43 +0x4c
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/influxdbexporter.createMetricsExporter({0x7e45808, 0xc9f4dc0}, {{{0x40027b1288, 0x8}, {0x0, 0x0}}, {0x40023a4620, {0x7dcb000, 0x400282ec00}, {0x7dfd2a0, ...}, ...}, ...}, ...)
        github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/factory.go:94 +0x194
go.opentelemetry.io/collector/exporter.CreateMetricsFunc.CreateMetricsExporter(...)



### Additional context

_No response_
@otbe otbe added bug Something isn't working needs triage New item requiring triage labels Sep 23, 2023
@otbe otbe changed the title influxdb exporter does not accept v1_compatibility config [exporter/influxdb] influxdb exporter does not accept v1_compatibility config Sep 23, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@crobert-1
Copy link
Member

This looks like a pretty simple out of bounds indexing error.

Here's the line hitting the exception:

func (enc *Encoding) Encode(dst, src []byte) {
    ...
		dst[di+0] = enc.encode[val>>18&0x3F]

Here's the code calling the above method:

func composeWriteURL(config *Config) (string, error) {
    ...
                if config.V1Compatibility.Username != "" && config.V1Compatibility.Password != "" {
			var basicAuth []byte
			base64.StdEncoding.Encode(basicAuth, []byte(config.V1Compatibility.Username+":"+string(config.V1Compatibility.Password)))
			config.HTTPClientSettings.Headers["Authorization"] = configopaque.String("Basic " + string(basicAuth))
		}

The Encode method is attempting to set the value at index 0 in the byte array, but the byte array is initialized without any space. In golang, this equates to nil with length 0.

The solution should be pretty simple, allocate the required space when declaring the slice.
Replace:

			var basicAuth []byte
			base64.StdEncoding.Encode(basicAuth, []byte(config.V1Compatibility.Username+":"+string(config.V1Compatibility.Password)))

With: (I renamed basicAuth to encodedAuth for clarity)

                       	authInfo := []byte(config.V1Compatibility.Username + ":" + string(config.V1Compatibility.Password))
                         // Allocate the right length of slice for the encoded byte array
			encodedAuth := make([]byte, base64.StdEncoding.EncodedLen(len(authInfo)))
			base64.StdEncoding.Encode(encodedAuth, authInfo)

@crobert-1 crobert-1 removed the needs triage New item requiring triage label Nov 1, 2023
@vv0s4k
Copy link

vv0s4k commented Nov 13, 2023

Ran into the same issue with opentelemetry-collector-contrib:0.88.0
May we expect it to get fixed in observable future?

@crobert-1 crobert-1 added the help wanted Extra attention is needed label Nov 13, 2023
@crobert-1
Copy link
Member

Any contributions are appreciated! I don't think I'd be able to get around to testing the fix anytime soon.

@vv0s4k
Copy link

vv0s4k commented Nov 15, 2023

Any contributions are appreciated! I don't think I'd be able to get around to testing the fix anytime soon.

I see. I wish I knew Golang. I'd be able to help then.

jacobmarble added a commit to jacobmarble/opentelemetry-collector-contrib that referenced this issue Nov 16, 2023
graphaelli pushed a commit to graphaelli/opentelemetry-collector-contrib that referenced this issue Nov 17, 2023
When InfluxDB v1 compatibility is enabled AND username&password are set,
the exporter panics. Not any more!

Fixes open-telemetry#27084

**Testing:** I've added one regression test.
aishyandapalli pushed a commit to aishyandapalli/opentelemetry-collector-contrib that referenced this issue Nov 17, 2023
When InfluxDB v1 compatibility is enabled AND username&password are set,
the exporter panics. Not any more!

Fixes open-telemetry#27084

**Testing:** I've added one regression test.
RoryCrispin pushed a commit to ClickHouse/opentelemetry-collector-contrib that referenced this issue Nov 24, 2023
When InfluxDB v1 compatibility is enabled AND username&password are set,
the exporter panics. Not any more!

Fixes open-telemetry#27084

**Testing:** I've added one regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working exporter/influxdb help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants