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

Problem when pushing using golang client - invalid metric name #48

Open
bzon opened this issue Oct 30, 2020 · 4 comments
Open

Problem when pushing using golang client - invalid metric name #48

bzon opened this issue Oct 30, 2020 · 4 comments

Comments

@bzon
Copy link

bzon commented Oct 30, 2020

Version: github.com/prometheus/client_golang v1.5.1

Code:

import (
	"github.com/prometheus/client_golang/prometheus/push"
	"github.com/prometheus/client_golang/prometheus"
)

	pusher := push.New(
		"http://localhost:9091",
		"foo-job",
	).Gatherer(prometheus.DefaultGatherer)

	if err := pusher.Push(); err != nil {
		fmt.Println(err)
	}

Error:

unexpected status code 400 while pushing to http://localhost:9091/metrics/job/foo-job: text format parsing error in line 1: invalid metric name
@bboreham
Copy link
Contributor

bboreham commented Nov 19, 2020

I’ve not looked at the Pusher package, but “foo-job” is invalid per the spec - minus sign is not allowed.

@sptrakesh
Copy link

sptrakesh commented Dec 11, 2020

I am trying out this project, and I am getting a similar error. Same code works with the prometheus push gateway.

Could not push metrics to push gateway. unexpected status code 400 while pushing to http://push-gateway/metrics/job/region_metrics/assets/regions: text format parsing error in line 1: invalid metric name
if err := push.New("http://push-gateway/", "region_metrics").
        Collector(metric).
        Grouping("assets", "regions").
        Push(); err != nil {
        log.Printf("metrics.%v - Could not push metrics to push gateway. %v", fn, err)
}

@bboreham
Copy link
Contributor

I looked at the package; you need to call .Format(expfmt.FmtText) to meet the expectations of this program (documented here).

I filed prometheus/client_golang#824 for the inconsistency.

@sptrakesh
Copy link

Indeed, that fixes the error.

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