-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor default runtime metrics tests for Go collector so that default runtime metric set autogenerates #1631
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
Changes from 5 commits
13b607a
154e9da
0a62ed8
3cdd683
dcb8936
fe0487b
2158a2f
70b1a8b
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 |
---|---|---|
|
@@ -62,6 +62,28 @@ var memstatMetrics = []string{ | |
"go_memstats_sys_bytes", | ||
} | ||
|
||
func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string { | ||
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. Hm, can you remind me why we need this? It looks we use it here:
But it all those cases we expect default metrics, so why not adding 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 see your point. I also would like for it to be simpler, and maybe there are ways to simplify it that I'm not seeing right now... but in any case it's not only about deduplicating and sorting; it's also about not including metrics (especially when they don't exist in go1.20) according to the different allow/deny list scenarios. In fact it's also used once in 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. And thanks for taking care of the other 2 problems! <3 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.
but that is solved with 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. The But in this function (which lives in a file that has to work with all the supported Go versions indifferently) I chose the approach where in practice I append the non-denied default metrics to the rest of the other requested metrics in a hard-coded way. That is to say, I append a subset of those metrics; a subset that is not dynamically generated, unlike the whole set. So when it comes to cases when only some of the default runtime metrics have to be filtered out because of deny lists matching 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. Incidentally: Arthur just wrote in Slack that we shouldn’t be worrying about supporting go1.20. If that means that the tests for go1.20 can be deleted, then at least half of this problem is solved, as the default runtime metrics list looks exactly the same starting from go 1.21. But maybe there are reasons we should still be keeping them around for a while. 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'm fine with deleting 1.20 test files, we don't even run them in CI anymore |
||
if withoutGC && withoutSched { | ||
// If both flags are true, return the metricNames as is. | ||
return metricNames | ||
} else if withoutGC && !withoutSched && defaultRuntimeMetrics != nil { | ||
// If only withoutGC is true and the Go version is at least 1.20, include "go_sched_gomaxprocs_threads" only. | ||
metricNames = append(metricNames, []string{"go_sched_gomaxprocs_threads"}...) | ||
} else if withoutSched && !withoutGC && len(defaultRuntimeMetrics) > 1 { | ||
// If only withoutSched is true and the Go version is higher than 1.20, exclude "go_sched_gomaxprocs_threads". | ||
metricNames = append(metricNames, []string{"go_gc_gogc_percent", "go_gc_gomemlimit_bytes"}...) | ||
} else if withoutSched && len(defaultRuntimeMetrics) == 1 { | ||
// If only withoutSched is true and the Go version is 1.20, return the metricNames as is. | ||
return metricNames | ||
} else { | ||
// In any other case, use the default metrics. | ||
metricNames = append(metricNames, defaultRuntimeMetrics...) | ||
} | ||
// sorting is required | ||
sort.Strings(metricNames) | ||
return metricNames | ||
} | ||
|
||
func TestGoCollectorMarshalling(t *testing.T) { | ||
reg := prometheus.NewPedanticRegistry() | ||
reg.MustRegister(NewGoCollector( | ||
|
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.
What does
trans
means? Not sure I understand the variable name 🥲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.
Hi, I was still simplifying a bit as announced ;), so I condensed the piece of code you are referring to. Nonetheless, to answer your question. I maintained the naming of that
trans
variable to be consistent with similar pre-existing usages in this file and ingen_go_collector_metrics_set.go
. Under the hood, the functionrm2prom
callsinternal.RuntimeMetricsToProm
and there I could assume thattrans
stands for "translation".