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

host / runtime metrics broken in prometheus #2787

Closed
corani opened this issue Sep 21, 2022 · 2 comments
Closed

host / runtime metrics broken in prometheus #2787

corani opened this issue Sep 21, 2022 · 2 comments
Milestone

Comments

@corani
Copy link

corani commented Sep 21, 2022

With the new Metrics API (v0.32.0), we somewhere ends up calling https://github.com/prometheus/common/blob/main/model/metric.go#L92 which rejects any metrics with dots such as the ones created by by the host and runtime instrumentation (e.g. process.cpu.time).

As a result, every time when Prometheus collects the metrics my logs are being spammed full with "xxx is not a valid metric name" errors (directly to stderr, which is another issue) and those metrics aren't returned to Prometheus.

Note: prior to the new Metrics API this worked (v0.31.0).

An example to reproduce this can be found in the comment below.

@corani
Copy link
Author

corani commented Sep 21, 2022

To reproduce:

package main

import (
    "context"
    "fmt"
    "net/http"
    "net/http/httptest"

    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promhttp"
    "go.opentelemetry.io/contrib/instrumentation/host"
    otelprom "go.opentelemetry.io/otel/exporters/prometheus"
    "go.opentelemetry.io/otel/sdk/metric"
)

func main() {
    exporter := otelprom.New()
    provider := metric.NewMeterProvider(metric.WithReader(exporter))

    registry := prometheus.NewRegistry()
    if err := registry.Register(exporter.Collector); err != nil {
        panic(err)
    }

    // this generates metrics that are rejected by the prometheus module
    if err := host.Start(host.WithMeterProvider(provider)); err != nil {
        panic(err)
    }

    // similar for `runtime` instrumentation

    // this metric does work
    counter, err := provider.Meter("my_meter").SyncInt64().Counter("my_counter")
    if err != nil {
        panic(err)
    }
    counter.Add(context.Background(), 1)

    handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})

    w := httptest.NewRecorder()
    r := httptest.NewRequest(http.MethodGet, "/", nil)

    handler.ServeHTTP(w, r)

    fmt.Println("body:\n", w.Body.String())
}

Output:

$ go run main.go
2022/09/21 11:56:30 "system.network.io" is not a valid metric name
2022/09/21 11:56:30 "system.network.io" is not a valid metric name
2022/09/21 11:56:30 "process.cpu.time" is not a valid metric name
2022/09/21 11:56:30 "process.cpu.time" is not a valid metric name
2022/09/21 11:56:30 "system.cpu.time" is not a valid metric name
2022/09/21 11:56:30 "system.cpu.time" is not a valid metric name
2022/09/21 11:56:30 "system.cpu.time" is not a valid metric name
2022/09/21 11:56:30 "system.cpu.time" is not a valid metric name
2022/09/21 11:56:30 "system.memory.usage" is not a valid metric name
2022/09/21 11:56:30 "system.memory.usage" is not a valid metric name
2022/09/21 11:56:30 "system.memory.utilization" is not a valid metric name
2022/09/21 11:56:30 "system.memory.utilization" is not a valid metric name
body:
 # HELP my_counter
# TYPE my_counter counter
my_counter 1

@dmathieu dmathieu transferred this issue from open-telemetry/opentelemetry-go-contrib Sep 21, 2022
@dmathieu dmathieu transferred this issue from open-telemetry/opentelemetry-go Sep 21, 2022
@MrAlias
Copy link
Contributor

MrAlias commented Sep 21, 2022

Thanks for the bug report. This is currently identified and tracked by open-telemetry/opentelemetry-go#3183. Closing this as it is a duplicate. Please follow the other issue to track the resolution.

@MrAlias MrAlias closed this as completed Sep 21, 2022
@pellared pellared added this to the untracked milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants