Early metrics polling returns `Unexpected response code: 500 (json: unsupported value: NaN)`
- Dominant language
- Go
- Stars
- 30.1k
- Forks
- 4.6k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 39
Description
#### Overview of the Issue
Running this code that queries the metrics of consul results is getting repeated `Unexpected response code: 500 (json: unsupported value: NaN)`
#### Reproduction Steps
Steps to reproduce this issue, eg:
1. Run `go run main.go`
2. Start up consul in dev mode
Result: you see continously repeating `Unexpected response code: 500 (json: unsupported value: NaN)`
```main.go
package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"github.com/hashicorp/consul/api"
)
func main() {
client, err := api.NewClient(api.DefaultConfig())
if err != nil {
fmt.Println(err)
return
}
ctx, cancel := context.WithCancel(context.Background())
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
var wg sync.WaitGroup
wg.Add(1)
go func() {
<-sigCh
cancel()
}()
go func() {
for {
value, err := client.Agent().Metrics()
if err != nil {
fmt.Println(err)
fmt.Println(value)
}
select {
case <-ctx.Done():
wg.Done()
default:
}
}
}()
wg.Wait()
}
```
### Consul version
Consul Version : Consul v1.14.0
### Operating system and Environment details
Ran on a mac but seen in ubuntu as well
Contributor guide
Research direction
Start with the main.go reproduction and the client.Agent().Metrics() entry point, then run Consul in dev mode and observe the early polling responses. Trace where the metrics response is encoded and determine why NaN produces the repeated 500 error. Done means the reproduction no longer returns the unsupported-value error during early polling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100