Skip to content

JSON marshalling of GoCollector metrics in v1.12.1 results in NaN error #981

Closed
@tsandall

Description

@tsandall

We recently upgraded from v1.12.0 to v1.12.1 and noticed that the GoCollector metrics are generating JSON marshalling errors because of NaN values. The metrics in question are go_gc_pauses_seconds_total and go_sched_latencies_seconds. This is on Go 1.17 if that helps.

Here's a small program that reproduces the issue.

$ go run x.go
err: json: unsupported value: NaN

x.go:

package main

import (
	"encoding/json"
	"fmt"
	"log"

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

func main() {
	registry := prometheus.NewRegistry()
	registry.MustRegister(collectors.NewGoCollector())
	result, err := registry.Gather()
	if err != nil {
		log.Fatal(err)
	}

	_, err = json.Marshal(result)
	fmt.Println("err:", err)
}

go.mod:

module github.com/tsandall/prometheus-go-collector-bug

go 1.17

require github.com/prometheus/client_golang v1.12.1

require (
	github.com/beorn7/perks v1.0.1 // indirect
	github.com/cespare/xxhash/v2 v2.1.2 // indirect
	github.com/golang/protobuf v1.5.2 // indirect
	github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
	github.com/prometheus/client_model v0.2.0 // indirect
	github.com/prometheus/common v0.32.1 // indirect
	github.com/prometheus/procfs v0.7.3 // indirect
	golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
	google.golang.org/protobuf v1.26.0 // indirect
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions