prom-aggregation-gateway icon indicating copy to clipboard operation
prom-aggregation-gateway copied to clipboard

Problem when pushing using golang client - invalid metric name

Open bzon opened this issue 5 years ago • 4 comments
trafficstars

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

bzon avatar Oct 30 '20 13:10 bzon

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

bboreham avatar Nov 19 '20 20:11 bboreham

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)
}

sptrakesh avatar Dec 11 '20 17:12 sptrakesh

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

I filed https://github.com/prometheus/client_golang/issues/824 for the inconsistency.

bboreham avatar Dec 12 '20 17:12 bboreham

Indeed, that fixes the error.

sptrakesh avatar Dec 12 '20 22:12 sptrakesh