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

Add an attribute to specify unknown type before converting to gauge in prometheusreceiver #17185

Closed
wants to merge 1 commit into from

Conversation

khanhntd
Copy link
Contributor

@khanhntd khanhntd commented Dec 21, 2022

Description:
As Prometheus Receiver currently, all untyped prometheus metrics are converted to OTEL Gauge since the whole reason was not to drop untyped prometheus metrics. However, for some of the backend (such as CloudWatch) using with awsemf as an exporter/proxy, they will have limit bound (not supporting +inf or -inf) and combining with some case untyped can be counter, this won't work and will lose metrics. Therefore, there are two options that has been discussed in this issue:

  • Dropping all untyped metrics with a flag in config
  • Add a metric datapoint's attribute flag specify whether the metric's are unknown.

After consideration, the latter options would be more straightforward since we can use filterprocessor to filter/drop untyped metrics and also allow more metrics processing with untyped in exchange for more bytes (more than 16 bytes scaling per datapoint)

Another thoughts for improvement would be: if this attribute can also apply to others prometheus metrics type such as StateSet and Info since it has been converted to Otel Counter

Will update the spec after everyone agrees on this approach.

Link to tracking Issue:

Testing:
There are two tests I have done:

  • go test ./... with prometheus receiver with update unit test
khanhntd@88665a0eaf54 prometheusreceiver % go test .
ok      github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver   219.046s
  • Using awsemf along with prometheusreceiver with prometheus.go
package main

import (
        "log"
        "net/http"

        "github.com/prometheus/client_golang/prometheus"
        "github.com/prometheus/client_golang/prometheus/promhttp"
)

var gaugeFunc = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
        Name: "gaugeFunc",
        Help: "Test for gauge functions",
},
        func() float64 {
                return float64(1.0)
        })

var noneFunc = prometheus.NewUntypedFunc(prometheus.UntypedOpts{
        Name: "noneFunc",
        Help: "Test for none functions",
},
        func() float64 {
                return float64(1.0)
        })
var summaryFunc = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
        Name: "summaryFunc",
        Help: "Test for summary functions",
},
        func() float64 {
                return float64(1.0)
        })

func main() {
        log.Printf("Registering all metrics...")
        prometheus.MustRegister(gaugeFunc)
        prometheus.MustRegister(noneFunc)
        prometheus.MustRegister(summaryFunc)
        log.Printf("Done registering all metrics...")

        http.Handle("/metrics", promhttp.Handler())
        http.ListenAndServe("0.0.0.0:8000", nil)

}

and have following results:

{
    "Version": "1",
    "_aws": {
        "CloudWatchMetrics": [
            {
                "Namespace": "CWAgent-Internal",
                "Dimensions": [
                    [
                        "key1",
                        "key2",
                        "prom_metric_type",
                        "job",
                        "instance",
                        "Version"
                    ]
                ],
                "Metrics": [
                    {
                        "Name": "noneFunc"
                    }
                ]
            }
        ],
        "Timestamp": 1671606728349
    },
    "instance": "127.0.0.1:8000",
    "job": "MY_JOB",
    "key1": "value1",
    "key2": "value2",
    "noneFunc": 1,
    "prom_metric_type": "unknown"
}

Documentation:

Signed-off-by: Khanh Nguyen khanhntd@amazon.com

@khanhntd khanhntd requested review from a team, Aneurysm9 and dashpole as code owners December 21, 2022 06:46
@github-actions github-actions bot added the receiver/prometheus Prometheus receiver label Dec 21, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2023

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 5, 2023
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants