-
Notifications
You must be signed in to change notification settings - Fork 236
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
add constant labels for the metrics (#385) #386
Conversation
Looks like there's an issue in with config: http: # http probes
- name: EaseProbe Github
url: https://github.com/megaease/easeprobe
labels:
abc: xx
def: y
instance: github.com/megaeas
- name: 163
url: https://www.163.com the lablels of 'EaseProbe Github' binds to '163' as well:
|
After changing the order: http: # http probes
- name: 163
url: https://www.163.com
- name: EaseProbe Github
url: https://github.com/megaease/easeprobe
labels:
abc: xx
def: y
instance: github.com/megaeas the labels was overwritten into empty:
|
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #386 +/- ##
==========================================
- Coverage 99.68% 99.42% -0.26%
==========================================
Files 83 84 +1
Lines 5722 5769 +47
==========================================
+ Hits 5704 5736 +32
- Misses 12 25 +13
- Partials 6 8 +2
☔ View full report in Codecov by Sentry. |
This was caused by the strategy of that is the config should be as below: http: # http probes
- name: 163
url: https://www.163.com
labels:
abc: x163
def: y163
instance: 163
- name: EaseProbe Github
url: https://github.com/megaease/easeprobe
labels:
abc: xx
def: y
instance: megaease but since the golang map is unordered, the configuration should be like below: http: # http probes
- name: 163
url: https://www.163.com
labels:
- name: abc
value: x163
- name: def
value: y163
- name: instance
value: 163
- name: EaseProbe Github
url: https://github.com/megaease/easeprobe
labels:
- name: abc
value: xx
- name: def
value: y
- name: instance
value: megaease this looks verbose and error-prone. |
Thanks for contributing this PR, there is a week from last commit, is it ready for review now? |
@samanhappy , the solution is a little ugly. As per the Prometheus Collector constraint, a metric must have the same set of constant labels, which looks like below, all prober should define the three labels:
I've tried to use a collector for each prober but didn't find a way to bind all the collectors to one HTTP handler. Anyway, this meets my reqirement and I am deploying it to the production environment. The code is ready for review if this solution is acceptable. |
You're correct. The current solution is overly verbose and susceptible to errors. We should strive to discover a more effective approach. Is it possible to consolidate these customized labels into a singular Prometheus label field? This would enable us to maintain label consistency. However, I'm uncertain about the ease of management within Prometheus consumers like Kibana. What are your thoughts on this? |
this solution requires all metrics to have the same set of constant labels, but users may forget this requirement and get an unexpected result. is it possible that we merge the constant labels of all metrics to one set, and set the value of a label to empty if a metric does not need it while keep the configured value if the metric need it? |
This PR is ready for review. the merge solution works fine. it passes the collector's checking and the empty labels are discarded by the exporter. |
docs/Manual.md
Outdated
labels: | ||
- name: team | ||
value: ease | ||
- name: owner | ||
value: megaease |
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.
as we merged all constant labels into one set, using a map instead of an array will be more user friendly.
labels: | |
- name: team | |
value: ease | |
- name: owner | |
value: megaease | |
labels: | |
team: ease | |
owner: megaease |
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.
updated
@samanhappy @localvar this PR is ready for review . |
conf/conf.go
Outdated
@@ -436,7 +436,9 @@ func isProbe(t reflect.Type) bool { | |||
// AllProbers return all probers | |||
func (conf *Conf) AllProbers() []probe.Prober { | |||
log.Debugf("--------- Process the probers settings ---------") | |||
return allProbersHelper(*conf) | |||
all := allProbersHelper(*conf) | |||
MergeConstLabels(all) |
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.
AllProbers
may be called more than once (even it is not currently, the name suggest it could be), which result in MergeConstLabels
be called more than once, this is not necessary and may cause a bug in the future.
propose moving MergeConstLabels
to somewhere that will only be called once.
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.
updated.
conf/constlables.go
Outdated
"github.com/megaease/easeprobe/probe" | ||
) | ||
|
||
var constLabels = make(map[string]bool) |
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 it is a global variable? I think we can make it a local variable by refactor the code below, this could make the code more maintainable and avoid potential bugs.
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.
this was a digress of an original design. updated.
for k, v := range constLabels { | ||
labels[k] = v | ||
} |
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.
should check if a label exists both in labels
and constLabels
and report the error.
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.
updated
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'll approve this PR now, but please fix the github workflow errors.
fixed. but I cannot verify fully as some unit tests failed on mac m1 due to the bou.ke/monkey issue. please run a github workflow to verify 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.
LGTM,please fix all the code lint warnings and some verbose comments
conf/constlables.go
Outdated
// | ||
// Prometheus requires all metric of the same name have the same set of labels in a collector |
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.
// | |
// Prometheus requires all metric of the same name have the same set of labels in a collector | |
// Prometheus requires all metric of the same name have the same set of labels in a collector |
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.
updated
conf/constlables.go
Outdated
func MergeConstLabels(ps []probe.Prober) { | ||
var constLabels = make(map[string]bool) | ||
for _, p := range ps { | ||
for k, _ := range p.LabelMap() { |
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.
please fix this and the following code lint warnings
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.
updated.
metric/prometheus.go
Outdated
|
||
// registries[len(registries)-1].MustRegister(m) |
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.
// registries[len(registries)-1].MustRegister(m) |
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.
updated.
No description provided.