-
Notifications
You must be signed in to change notification settings - Fork 765
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 'collect' URL parameter to filter enabled collectors #235
Conversation
mysqld_exporter.go
Outdated
@@ -170,6 +173,76 @@ func init() { | |||
prometheus.MustRegister(version.NewCollector("mysqld_exporter")) | |||
} | |||
|
|||
func filter(filters map[string]bool, name string) bool { | |||
flg := flag.Lookup("collect." + 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.
Minor nit, I think the golang style for this would just be f
.
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 had used f
in the original implementation, but changed it to flg
later 😄
I'll change it back.
mysqld_exporter.go
Outdated
HeartbeatTable: *collectHeartbeatTable, | ||
} | ||
|
||
//start := time.Now() |
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 remove commented out extras.
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.
Ah, some leftovers from my lazy copy/pasting 😅
Very nice! A few minor nits. |
Please update the README.md with usage info. |
/cc @roman-vynar This will be great for PMM. |
mysqld_exporter.go
Outdated
|
||
if len(query) > 0 { | ||
filters = make(map[string]bool) | ||
params := strings.Split(query, ",") |
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 usage should be ?collect[]=foo&collect[]=bar
to keep in line with other places in Prometheus
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.
Good point 👌🏻
HeartbeatTable: *collectHeartbeatTable, | ||
} | ||
|
||
registry := prometheus.NewRegistry() |
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 won't include the default process stuff, so you should add it back in
@SuperQ awesome 😎 Much better than having 3 exporters. @siavashs Great work! |
mysqld_exporter.go
Outdated
@@ -170,6 +172,74 @@ func init() { | |||
prometheus.MustRegister(version.NewCollector("mysqld_exporter")) | |||
} | |||
|
|||
func filter(filters map[string]bool, name string) bool { | |||
f := flag.Lookup("collect." + 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.
The only down-side to this approach is that we want to switch to kingpin for flag parsing. I haven't been able to find an equivalent feature in kingpin. 😦
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.
Yes, it would have been nice if kingpin had a Lookup()
method 😕
I can change the filter()
implementation or submit a PR for kingpin 😅
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.
Oh, I totally forgot to merge #222, which does the kingpin change. I would like to merge that, and have the filter changed to match. I think it will take too much time to get it implemented in kingpin.
Sorry, I should have taken care of the flag issue first.
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.
No problem, I'll update my branch.
As discussed on IRC, currently the |
The promhttp documentation is here: https://godoc.org/github.com/prometheus/client_golang/prometheus/promhttp Prior to removing the deprecated functions, there will be more documentation, examples, and tooling. https://godoc.org/github.com/prometheus/client_golang/prometheus#InstrumentHandler is handy but doing so much wrong that we cannot just not declare it deprecated. |
143b2d0 exposes the |
mysqld_exporter.go
Outdated
registry.MustRegister(collector.New(dsn, collect)) | ||
prometheus.DefaultRegisterer = registry | ||
|
||
// Delegate http serving to Promethues client library, which will call collector.Collect. |
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.
Promethues -> Prometheus
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 copied this typo from another exporter 😄
mysqld_exporter.go
Outdated
registry.MustRegister(prometheus.NewGoCollector()) | ||
registry.MustRegister(prometheus.NewProcessCollector(os.Getpid(), "")) | ||
registry.MustRegister(collector.New(dsn, collect)) | ||
prometheus.DefaultRegisterer = registry |
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 will create a data race if multiple requests hit /metrics concurrently.
I assume you are only doing this here to make prometheus.InstrumentHandler
work.
If you use the individual handler instrumentation helpers in promhttp, you can avoid that. Also, you can instrument the handler appropriately. (I'm pretty sure that some of the things that get auto-instrumented now are not needed, like request size. And response latency might be better done in a histogram so that you can aggregate over many exporters.)
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.
Yes, I noticed the issue while trying to make the instrumentation metrics work.
The next commit fixes this issue by creating a Gatherers
instance from default gatherer and newly created registry per request.
mysqld_exporter.go
Outdated
|
||
registry := prometheus.NewRegistry() | ||
registry.MustRegister(collector.New(dsn, collect)) | ||
prometheus.DefaultRegisterer = registry |
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 think you can now delete this line. (As long as this line is there, you have a race.)
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.
Ah, of course.
👍 from my side, leaving final say to @SuperQ . |
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.
Great!
} | ||
|
||
registry := prometheus.NewRegistry() | ||
registry.MustRegister(collector.New(dsn, collect)) |
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.
@SuperQ @siavashs I think this broke scrapes_total
and scrape_errors_total
metrics. Previously collector.New()
was created once - in main
func. Now it's created on every scrape and so is scrapes_total
and scrape_errors_total
leading to constant values as every time scrapes_total
is reset to 0, so we get only 1 scrape. It's not total
anymore.
https://github.com/prometheus/mysqld_exporter/blob/master/collector/exporter.go#L107-L118
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 can confirm this bug, I think we can fix it by having a separate collector for exporter metrics.
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.
Sounds correct to me. Thanks for the report. I'll make a separate issue for this.
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.
For the reference: #269
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.
@SuperQ @siavashs Actually, there is one more confusing thing. Looks like now this metric is constant 2
#245, and even after fixing it, this will be increased every http call by 2
because each call ask for metrics and their description, and Describe
again increases scrapes_total
metric. Should scrapes_total
be increased also when Describe
is called? If only Collect
would increase this metric then each http call would increase this metric only by 1
. I'm working right now on fix for this so let me please know ;)
But maybe increasing this metric by 2
is correct and we simply should have separate metric for http calls?
} | ||
|
||
c := collector.New(dsn, collect) | ||
prometheus.MustRegister(c) |
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.
After this change, registering collector every http request, we now call Describe()
every http request, and as in result we call Collect()
twice every http request.
As discussed on #234 and IRC, this PR adds a
collect
URL parameter to filter currently enabled collectors.Closes: #234