name composer: fast and slow (reflect-based) implementations #79
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context && Motivation
To create a new metric we have to manually write the full metric name (+ stringified labels) e.g.
foo{bar="baz",aaa="b"}
That can be tricky and overwhelming when doing it manually: raw strings always give a chance to make a typo (invalid syntax, wrong name, wrong type, missing/extra labels, etc)Solution
Provide a helper function "NameCompose" that will let us to compose full metric name with given metric_name and labels. To avoid using raw maps (that still can lead to typos and issues explained above), let's do the type-safe solution, using structs.
Two possible solutions are available here:
1. Fast solution (but manual declaring helper for each labels set)
2. Auto-compose solution (but slow, reflect is involved)
Notes:
ToLabelsString()
method to your labels struct and use it.What do you think about such a feature?