Skip to content

metrics: add support for non-standard metrics #18175

@yaauie

Description

@yaauie

This is an implementation detail of #18107, which will provide a ratio metric to track the bytes-in vs bytes-out of PQ compression.

As a: developer who needs to expose metrics via the Logstash HTTP API,
I want: a method for defining my own metric
So that: I can provide api-private metric implementations without wiring each new implementation through the public API

To this end:

Add a method to the public-api co.elastic.logstash.api.NamespacedMetric:

<U extends UserMetric<?>> U register(String metric, UserMetric.Factory<U> userMetricFactory);

Where UserMetric and UserMetric.Factory are defined as:

public interface UserMetric<T extends Serializable> {
    T getValue();

    interface Factory<U extends UserMetric<?>> {
        U create(String name);
        Class<U> getType();
        U nullImplementation();
    }
}

And wire it through to the underlying metric collector.

NOTE:

  • naming TBD
  • We may need a co.elastic.logstash.api.MetricType (which would be a super-interface for the existing enum org.logstash.instrument.metrics.MetricType) so that we can construct a org.logstash.instrument.metrics.Metric<?> -- although the MetricType is only actually used for gauge-type metrics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions