-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Description
Legacy
In order to collect and report on metrics, plugins create and register "collectors" with:
const myCollector = server.usage.collectorSet.makeUsageCollector({
type: 'dashboard',
fetch: async (callCluster: CallAPI): Record<string, any>
})
server.usage.collectorSet.register(myCollector);Each collector defines a fetch() function which returns the collected metrics. Registering a collector simply adds it to the server.usage.collectorSet, collector's fetch() methods don't automatically get called.
Registered collectors are consumed from the following locations, each of which independently calls the various collector's fetch() functions:
api/statsfor stats collectors andapi/stats?extended=truefor usage collectors- monitoring plugin
- telemetry plugin
New Platform: metrics plugin (TBD)
We create a metrics OSS plugin which exposes an API to allow other plugins to register which metrics they want captured similar to collectorSet.register. This plugin will also expose the api/stats endpoint. As a first step metric collectors can simply be registered. In the future, this plugin will also be responsible for fetching the metrics and exposing the data, not the collectors, through an API. When plugins register a metric they can define the collection interval or use the default. Monitoring, Telemetry and api/stats can then pull data from this plugin.
metrics and telemetry are quite closely related and could be implemented in the same OSS plugin. However, having these separate allows paranoid administrators to disable the telemetry plugin entirely, which means the code that uploads telemetry data won't even be loaded, without affecting the functionality of the monitoring plugin or the api/stats endpoint.
Although I don't believe there is a strong case for it right now, having a small dedicated metrics plugin would also make it much easier to move this API into Core in the future.
Implementation
- Implement NP metrics plugin
- Change Legacy
usageMixinto proxy all calls toserver.usage.collectorSetto the NP metrics plugin withserver.newPlatform.setup.plugins.metrics. This way legacy plugins can continue to use the legacy collectorSet API but all the logic is located in the NP metrics plugin.
Open questions:
- Is there any existing functionality which wouldn't be supported by the suggested design?
- We have two constructors for creating collectors
makeUsageCollectorvsmakeStatsCollector. But when we want stats collectors we seem to always filter byTYPEgetCollectorByType()and when we want usage collectors we filter by constructorisUsageCollector(). There should be a consistent way to create/distinguish between these two.