-
Notifications
You must be signed in to change notification settings - Fork 78
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
Update default Go metrics #564
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//go:build go1.18 && !go1.19 | ||
// +build go1.18,!go1.19 | ||
|
||
package admin | ||
|
||
var expectedMetrics = []string{ | ||
"go_gc_duration_seconds", | ||
"go_goroutines", | ||
"go_info", | ||
"go_memstats_alloc_bytes", | ||
"go_memstats_alloc_bytes_total", | ||
"go_memstats_buck_hash_sys_bytes", | ||
"go_memstats_frees_total", | ||
"go_memstats_gc_sys_bytes", | ||
"go_memstats_heap_alloc_bytes", | ||
"go_memstats_heap_idle_bytes", | ||
"go_memstats_heap_inuse_bytes", | ||
"go_memstats_heap_objects", | ||
"go_memstats_heap_released_bytes", | ||
"go_memstats_heap_sys_bytes", | ||
"go_memstats_last_gc_time_seconds", | ||
"go_memstats_lookups_total", | ||
"go_memstats_mallocs_total", | ||
"go_memstats_mcache_inuse_bytes", | ||
"go_memstats_mcache_sys_bytes", | ||
"go_memstats_mspan_inuse_bytes", | ||
"go_memstats_mspan_sys_bytes", | ||
"go_memstats_next_gc_bytes", | ||
"go_memstats_other_sys_bytes", | ||
"go_memstats_stack_inuse_bytes", | ||
"go_memstats_stack_sys_bytes", | ||
"go_memstats_sys_bytes", | ||
"go_sched_goroutines_goroutines", | ||
"go_sched_latencies_seconds", | ||
"go_threads", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build go1.19 | ||
// +build go1.19 | ||
|
||
package admin | ||
|
||
var expectedMetrics = []string{ | ||
"go_gc_duration_seconds", | ||
"go_goroutines", | ||
"go_info", | ||
"go_memstats_alloc_bytes", | ||
"go_memstats_alloc_bytes_total", | ||
"go_memstats_buck_hash_sys_bytes", | ||
"go_memstats_frees_total", | ||
"go_memstats_gc_sys_bytes", | ||
"go_memstats_heap_alloc_bytes", | ||
"go_memstats_heap_idle_bytes", | ||
"go_memstats_heap_inuse_bytes", | ||
"go_memstats_heap_objects", | ||
"go_memstats_heap_released_bytes", | ||
"go_memstats_heap_sys_bytes", | ||
"go_memstats_last_gc_time_seconds", | ||
"go_memstats_lookups_total", | ||
"go_memstats_mallocs_total", | ||
"go_memstats_mcache_inuse_bytes", | ||
"go_memstats_mcache_sys_bytes", | ||
"go_memstats_mspan_inuse_bytes", | ||
"go_memstats_mspan_sys_bytes", | ||
"go_memstats_next_gc_bytes", | ||
"go_memstats_other_sys_bytes", | ||
"go_memstats_stack_inuse_bytes", | ||
"go_memstats_stack_sys_bytes", | ||
"go_memstats_sys_bytes", | ||
"go_sched_gomaxprocs_threads", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π this one seems to be the diff between 1.18 and 1.19? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, new feature in Go 1.19. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would skip the build tags and just do
Or you could use https://pkg.go.dev/golang.org/x/mod/semver if you want to be a bit more precise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I thought about this a bit.
I think we need to keep this testing the way it is. (This is how upstream Prometheus client_golang does testing) |
||
"go_sched_goroutines_goroutines", | ||
"go_sched_latencies_seconds", | ||
"go_threads", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package admin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/collectors" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
reg := prometheus.NewRegistry() | ||
reg.MustRegister(collectors.NewGoCollector(baseplateGoCollectors)) | ||
|
||
result, err := reg.Gather() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
got := []string{} | ||
for _, r := range result { | ||
got = append(got, r.GetName()) | ||
} | ||
|
||
if diff := cmp.Diff(expectedMetrics, got); diff != "" { | ||
t.Errorf("registered metrics mismatch (-want +got):\n%s", diff) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π why do we have to do this :sigh:, why isn't that the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the default registry includes some default settings for Go metrics to make it easy for end users.
Customizing the default registry is a bit awkward. We could avoid this by completely eliminating use of the default registry in baseplate.go. But, that means we would need to have user switch to
promauto.With(reg)...
.So, we do a little bit of dance to get around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are actually already using
promauto.With(reg)
because of f68284fThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'm not sure that was the right thing to do. :-/