Skip to content

Add collect[] parameter#699

Merged
SuperQ merged 8 commits intoprometheus:masterfrom
siavashs:parameters
Oct 14, 2017
Merged

Add collect[] parameter#699
SuperQ merged 8 commits intoprometheus:masterfrom
siavashs:parameters

Conversation

@siavashs
Copy link
Contributor

This PR adds a collect[] URL parameter to filter currently enabled collectors.

staticcheck: $(STATICCHECK)
@echo ">> running staticcheck"
@$(STATICCHECK) $(pkgs)
@$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't introduce staticcheck violations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed on IRC with @beorn7 and @SuperQ
Without this we will get:

node_exporter.go:86:32: prometheus.InstrumentHandlerFunc is deprecated: InstrumentHandlerFunc is deprecated for the same reasons as InstrumentHandler is. Use the tooling provided in package promhttp instead.  (SA1019)

Another solution is to use prometheus@v0.8.0 instead of v0.9.0-pre1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Please add a comment mentioning InstrumentHandlerFunc and when that ignoring can be removed again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this will also warn in client_golang v0.8.0 as well. :(


// NewNodeCollector creates a new NodeCollector
func NewNodeCollector() (*nodeCollector, error) {
func NewNodeCollector(filters map[string]bool) (*nodeCollector, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a clean interface, leaking implementation internals (for performance reasons or to safe some lines of code I suppose?) into the function signature.

I propose to use NewNodeCollector(filters ...string) (*nodeCollector, error).

return nil, err
}
collectors[key] = collector
if len(filters) == 0 || filters[key] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should error out if someone tries to use a filter which is not loaded. I suggest to not add this code to the collectorState loop but to do another one on top in case any filters are given.

node_exporter.go Outdated

nc, err := collector.NewNodeCollector(filters)
if err != nil {
log.Fatalf("Couldn't create collector: %s", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should certainly not exit here if an invalid filter request is given. Return a normal HTTP response error.

node_exporter.go Outdated
registry,
}
// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the handleropts? These are important.

node_exporter.go Outdated
log.Infoln("Build context", version.BuildContext())

nc, err := collector.NewNodeCollector()
// This instance is only used to check collector creation and logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End comments with a dot.

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One more comment, but looks good otherwise.

node_exporter.go Outdated
}

registry := prometheus.NewRegistry()
registry.MustRegister(nc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can panic. Let's use the Register function instead and return a server error response if it fails.

Copy link
Contributor Author

@siavashs siavashs Oct 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out!
@SuperQ We should fix this in mysqld_exporter as well.

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a log. Please add some documentation about the new parameters to the README, then we can merge this.

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This is great.

@SuperQ SuperQ merged commit f3a7022 into prometheus:master Oct 14, 2017
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
* Add `collect[]` parameter

* Add TODo comment about staticcheck ignored

* Restore promhttp.HandlerOpts

* Log a warning and return HTTP error instead of failing

* Check collector existence and status, cleanups

* Fix warnings and error messages

* Don't panic, return error if collector registration failed

* Update README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants