Skip to content
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 some collector classes for objects that get registered in a CollectorSet #19098

Conversation

tsullivan
Copy link
Member

Pulled out from #18894

  • Moves CollectorSet class definition file to ./classes in plugins/monitoring/server/kibana_monitoring
  • Adds 2 classes, Collector, a base class for collection objects, and UsageCollector, a collector specific to collecting usage stats
  • Changes some wiring to the collector instances created in plugins/monitoring/server/kibana_monitoring/collectors to use the new Collector class.

@@ -139,6 +137,19 @@ export class CollectorSet {
});
}

async bulkFetchUsage() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this isn't used yet. See #18894 for where it'll be used from an HTTP API

cc @ruflin the API will call this function from the handler, meaning that the stats will get collected whenever the API is called. No internal caching

setLogger,
fetch
};
async fetch() {
Copy link
Member Author

Choose a reason for hiding this comment

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

had to move this function into the object literal for context to work

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@tsullivan
Copy link
Member Author

cc @stacey-gammon, since you chimed in about requested that the collector objects be class instances

Copy link
Member

@pickypg pickypg left a comment

Choose a reason for hiding this comment

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

What do you think about moving the logger?


export class Collector {
/*
* @param {String} type.type - property name as the key for the data
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: all of these have an extraneous type. prefix now.

Copy link
Member Author

Choose a reason for hiding this comment

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

we're adding a server param before this object in the args, so I'm keeping the prefix but calling it properties which matches what it's called in UsageCollector

this.init = init;
this.fetch = fetch;
this.cleanup = cleanup;

Copy link
Member

Choose a reason for hiding this comment

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

Weird blank line makes this extra field seem special.

* Allows using `server.log('debug', message)` as `this.log.debug(message)`.
* Works for info and warn logs as well.
*/
setLogger(logger) {
Copy link
Member

Choose a reason for hiding this comment

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

You could get this without making the Collector mutable by passing in the server object to the constructor, then avoid having a custom logger altogether. It would also avoid the implicit requirement that it gets defined after construction.

@tsullivan tsullivan force-pushed the monitoring/collector-classes-for-collectorset branch from 0ca11a2 to 0aca12d Compare May 18, 2018 18:54
@tsullivan
Copy link
Member Author

What do you think about moving the logger?

++ on it. It wasn't great before because the logger that CollectorSet got was an inline-defined function passed to the constructor.

Collector objects now have server object passed in and set their logger property with a helper function. This is better because it means that a collector can log something any time in its lifecycle, not have to wait until the CollectorSet sets a logger for it.

Copy link
Member

@pickypg pickypg left a comment

Choose a reason for hiding this comment

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

LGTM!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@tsullivan tsullivan merged commit a7c3255 into elastic:master May 18, 2018
@tsullivan tsullivan deleted the monitoring/collector-classes-for-collectorset branch May 18, 2018 20:03
tsullivan added a commit to tsullivan/kibana that referenced this pull request May 18, 2018
…ctorSet (elastic#19098)

* Add some collector classes for objects that get registered in a CollectorSet

* comment cleanup

* don't pass an inline-defined logger to collectorSet

* add a helper logger function so collector has access to logger at construction
tsullivan added a commit that referenced this pull request May 18, 2018
…ctorSet (#19098) (#19230)

* Add some collector classes for objects that get registered in a CollectorSet

* comment cleanup

* don't pass an inline-defined logger to collectorSet

* add a helper logger function so collector has access to logger at construction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants