-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Refactor default runtime metrics tests for Go collector so that default runtime metric set autogenerates #1631
Refactor default runtime metrics tests for Go collector so that default runtime metric set autogenerates #1631
Conversation
…tests according to Go version Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
… version Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
…runtime-metrics-tests
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Once I'll have fixed the linters' complaints, I might still do some refactoring in |
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.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.
Does it make sense to add a Github Action workflow that runs make generate-go-collector-test-files
and asserts that there's no git diff?
var defaultRuntimeMetricsList []string | ||
|
||
for _, d := range defaultRuntimeDesc { | ||
if trans := rm2prom(d); trans != "" { |
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 in gen_go_collector_metrics_set.go
. Under the hood, the function rm2prom
calls internal.RuntimeMetricsToProm
and there I could assume that trans
stands for "translation".
…csList Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
I haven't looked into what GitHub Actions does right now, but if as things stand there's no such check, then I guess it wouldn't hurt. I wonder if that would be for another PR though. On a side note, one thing I noticed is that before I merged the |
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.
LGTM, I am happy to solve 2 other problems (2 generative scripts instead of one and CI job for no manual changes) in other PRs.
However I want double check if we can get rid of this complex withDefaultRuntimeMetrics function... 🤔 Proposed something
@@ -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 comment
The 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:
{
name: "allow GC",
rules: []GoRuntimeMetricsRule{MetricsGC},
expected: withDefaultRuntimeMetrics(withGCMetrics(), true, false),
},
{
name: "allow Memory",
rules: []GoRuntimeMetricsRule{MetricsMemory},
expected: withDefaultRuntimeMetrics(withMemoryMetrics(), false, false),
},
{
name: "allow Scheduler",
rules: []GoRuntimeMetricsRule{MetricsScheduler},
expected: withDefaultRuntimeMetrics(withSchedulerMetrics(), false, true),
},
{
name: "allow debug",
rules: []GoRuntimeMetricsRule{MetricsDebug},
expected: withDefaultRuntimeMetrics(withDebugMetrics(), false, false),
},
But it all those cases we expect default metrics, so why not adding defaultRuntimeMetrics
always? Is it about duplications? Then let's have dedupSort
function for 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.
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 TestGoCollectorDenyList
. Shall I change the name to dedupSort
all the same? Or make any other change?
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.
And thanks for taking care of the other 2 problems! <3
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.
. 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)
but that is solved with defaultRuntimeMetrics
generation, no?
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.
The defaultRuntimeMetrics
generation solves the problem of defining what the set of default runtime metrics looks like for a given Go version; in practice this allows adding the right set of default runtime metrics as is, when there are no deny lists at all OR when no deny list matches either all gc
or all sched
metrics.
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 gc
OR sched
(not both: both is a non-problem), the subset to be appended may be different according to the version but I cannot dynamically/automatically reflect those differences in that function: hence all the many conditionals. Shall I think of a different, more dynamic solution?
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.
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 comment
The 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
And thanks for helping 💪🏽 |
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
I could simplify the function a bit, but it's still the same not completely dynamic approach. Maybe I can think of something more future proof. |
…rics subsets Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Ok, I implemented another approach. Now the default runtime metrics subsets (needed to be included in or excluded from the final selection of metrics) are also generated. This makes withDefaultRuntimeMetrics func cleaner and more resilient. I'm still leaving it in the |
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.
Thanks! Let me propose what I meant (or realize there is no better approach) in a different PR, this is already a lot better thank You!
Thank you! I wouldn't be surprised if there were better approaches and I'd be very happy if you could come up with one 👯 . I know it's not ideal to have so many similar-looking variables (outside of functions, on top of that); I mainly tried to keep what's in the Go templates to a minimum, as not everybody finds them super readable 😝 |
…lt runtime metric set autogenerates (prometheus#1631) * Enable autogeneration for default runtime metrics list in collectors tests according to Go version Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Adapt withDefaultRuntimeMetrics function to work regardless of the Go version Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Autogenerate go collector test for go1.23 Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Modify gen_go_collector_set.go to please linter and regenerate files Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Simplify gen_go_collector_set.go logic by modifying func computeMetricsList Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Slight simplification of withDefaultRuntimeMetrics func Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> * Refactor withDefaultRuntimeMetrics with generated default runtime metrics subsets Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> --------- Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it> Signed-off-by: Eugene <eugene@amberpixels.io>
In this PR I modify the
gen_go_collector_set.go
file so that the default runtime metrics list gets autogenerated (like a few test helpers functions already did) so that it can vary automatically according to the Go versions.This is tied to the #1575 issue.