Skip to content

collectorSets in the New Platform #46924

@rudolf

Description

@rudolf

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/stats for stats collectors and api/stats?extended=true for 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

  1. Implement NP metrics plugin
  2. Change Legacy usageMixin to proxy all calls to server.usage.collectorSet to the NP metrics plugin with server.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:

  1. Is there any existing functionality which wouldn't be supported by the suggested design?
  2. We have two constructors for creating collectors makeUsageCollector vs makeStatsCollector. But when we want stats collectors we seem to always filter by TYPE getCollectorByType() and when we want usage collectors we filter by constructor isUsageCollector(). There should be a consistent way to create/distinguish between these two.

Metadata

Metadata

Labels

Feature:TelemetryTeam:CorePlatform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t//Team:MonitoringStack Monitoring teamdiscuss

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions