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/clickhouse] Nil pointer exception on Metrics without service.name Resource Attributes #37030

Open
Fiery-Fenix opened this issue Jan 6, 2025 · 2 comments · May be fixed by #37034
Open
Labels
bug Something isn't working exporter/clickhouse needs triage New item requiring triage

Comments

@Fiery-Fenix
Copy link
Contributor

Component(s)

exporter/clickhouse

What happened?

Description

This bug is a regression after #33634
In case of not set service.name Resource Attribute for Metric clickhouse exporter will throw next panic:

opentelemetry-collector panic: runtime error: invalid memory address or nil pointer dereference
opentelemetry-collector [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa78bdc]
opentelemetry-collector 
opentelemetry-collector goroutine 46 [running]:
opentelemetry-collector go.opentelemetry.io/collector/pdata/pcommon.Value.Type(...)
opentelemetry-collector     go.opentelemetry.io/collector/[email protected]/pcommon/value.go:183
opentelemetry-collector go.opentelemetry.io/collector/pdata/pcommon.Value.AsString({0x0?, 0xc0006e0fa0?})
opentelemetry-collector     go.opentelemetry.io/collector/[email protected]/pcommon/value.go:370 +0x1c
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.(*gaugeMetrics).insert.func1(0x0?)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/gauge_metrics.go:125 +0x367
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.doWithTx({0x6eac320?, 0xc0007bfce0?}, 0x0?, 0xc000b07f40)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/metrics_model.go:210 +0xd3
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.(*gaugeMetrics).insert(0xc00060e0f0, {0x6eac320, 0xc0007bfce0}, 0xc0010d6750)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/gauge_metrics.go:101 +0xd8
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.InsertMetrics.func1({0x6e5d6b0?, 0xc00060e0f0?}, 0xc0006e0fb0)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/metrics_model.go:100 +0x43
opentelemetry-collector created by github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.InsertMetrics in goroutine 21
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/metrics_model.go:99 +0xcc

This panic happens due to unsafe usage of pcommon.Map.Get() in next line:
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/clickhouseexporter/internal/gauge_metrics.go#L112
While documentation explicitly states that "Calling any functions on the returned invalid instance may cause a panic.". This panic happens on line https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/clickhouseexporter/internal/gauge_metrics.go#L125, where in case of absent service.name in Map we are trying to call <invalid instance>.AsString()

The bug is valid for all types of Metrics and also Traces, Logs are unaffected because they are using correct value check for some reason

Steps to Reproduce

Just try to export a Metric without service.name attribute using clickhouse exporter

Expected Result

No panic

Actual Result

Panic

Collector version

0.116.0

Environment information

No response

OpenTelemetry Collector configuration

No response

Log output

opentelemetry-collector panic: runtime error: invalid memory address or nil pointer dereference
opentelemetry-collector [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa78bdc]
opentelemetry-collector 
opentelemetry-collector goroutine 46 [running]:
opentelemetry-collector go.opentelemetry.io/collector/pdata/pcommon.Value.Type(...)
opentelemetry-collector     go.opentelemetry.io/collector/[email protected]/pcommon/value.go:183
opentelemetry-collector go.opentelemetry.io/collector/pdata/pcommon.Value.AsString({0x0?, 0xc0006e0fa0?})
opentelemetry-collector     go.opentelemetry.io/collector/[email protected]/pcommon/value.go:370 +0x1c
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.(*gaugeMetrics).insert.func1(0x0?)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/gauge_metrics.go:125 +0x367
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.doWithTx({0x6eac320?, 0xc0007bfce0?}, 0x0?, 0xc000b07f40)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/metrics_model.go:210 +0xd3
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.(*gaugeMetrics).insert(0xc00060e0f0, {0x6eac320, 0xc0007bfce0}, 0xc0010d6750)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/gauge_metrics.go:101 +0xd8
opentelemetry-collector github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.InsertMetrics.func1({0x6e5d6b0?, 0xc00060e0f0?}, 0xc0006e0fb0)
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/metrics_model.go:100 +0x43
opentelemetry-collector created by github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal.InsertMetrics in goroutine 21
opentelemetry-collector     github.com/open-telemetry/opentelemetry-collector-contrib/exporter/[email protected]/internal/metrics_model.go:99 +0xcc

Additional context

No response

@Fiery-Fenix Fiery-Fenix added bug Something isn't working needs triage New item requiring triage labels Jan 6, 2025
Copy link
Contributor

github-actions bot commented Jan 6, 2025

Pinging code owners:

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

@Fiery-Fenix
Copy link
Contributor Author

PR with fix: #37034

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/clickhouse needs triage New item requiring triage
Projects
None yet
1 participant