ID | IEP-114 |
Author | |
Sponsor | |
Created | |
Status | DRAFT |
It is useful for user to work with own metrics, not only with provided by Ignite. Current public metrics API doesn't expose any method to add or delete additional metrics.
The most important reason to provide custom is probably the convenience of collecting of desired metrics using one platform, the same client, through the same API. This feature can simplify user application.
Oracle DB , Postgres , Oracle Coherence , MS SQL Server , IBM DB2
In future, we might want to provide an internal API to obtain metrics like this. It could be quite different and we should split them.
package org.apache.ignite;
public interface Ignite {
public IgniteCustomMetrics metrics();
}
To keep custom metrics detached from the internals, we should either automaticall add a prefix to custom name or throw an exception if provided metric name doesn't start with that prefix.
package org.apache.ignite;
/**
* Allows to add custom metrics. Custom metrics registers is always stored with name prefix "custom.".
* If provided registry name is "a.b.regname", it is automatically converted to "custom.a.b.regname".
* If the name is "custom.a.b.regname", it is used as is.
*/
public interface IgniteCustomMetrics {
/**
* Registers metric in registry {@code registryName}. Adds new metric registry if absent.
*
* @return Previous metric if it already exists with the same name. {@code metric} otherwise.
*/
<T extends Metric> T metric(String registryName, String metricName, T metric);
/** Removes metric from registry {@code registryName}. */
void removeMetric(String registryName, String metricName);
/** @return Metric registry named '{@code registryName}'. */
ReadOnlyMetricRegistry registry(String registryName);
/** Removes registry named '{@code registryName}'. */
void removeRegistry(String registryName);
// Simple type metrics. Int, Long and Double should be enough.
/**
* Registers a {@link LongMetric} in registry {@code registryName}. Adds new metric registry if absent.
*
* @return Previous long value setter if it already exists with the same name. A new one otherwise.
*/
LongConsumer longMetric(String registryName, String metricName, @Nullable String description);
/**
* Registers a {@link DoubleMetric} in registry {@code registryName}. Adds new metric registry if absent.
*
* @return Previous double value setter if it already exists with the same name. A new one otherwise.
*/
DoubleConsumer doubleMetric(String registryName, String metricName, @Nullable String description);
/**
* Registers a {@link IntMetric} in registry {@code registryName}. Adds new metric registry if absent.
*
* @return Previous int value setter if it already exists with the same name. A new one otherwise.
*/
IntConsumer booleanMetric(String registryName, String metricName, @Nullable String description);
// Might be useful the gauges.
/**
* Registers a {@link LongMetric} metric in registry {@code registryName} with long value supplier {@code valueSupplier}.
* Adds new metric registry if absent.
*
* @return {@code True} if metric was added. {@code False} if another meric already exists under the same name.
*/
boolean longMetric(String registryName, String metricName, LongSupplier valueSupplier, @Nullable String description);
/**
* Registers a {@link DoubleMetric} metric in registry {@code registryName} with double value supplier {@code valueSupplier}.
* Adds new metric registry if absent.
*
* @return {@code True} if metric was added. {@code False} if another meric already exists under the same name.
*/
boolean doubleMetric(String registryName, String metricName, DoubleSupplier valueSupplier, @Nullable String description);
/**
* Registers a {@link IntMetric} metric in registry {@code registryName} with int value supplier {@code valueSupplier}.
* Adds new metric registry if absent.
*
* @return {@code True} if metric was added. {@code False} if another meric already exists under the same name.
*/
boolean intMetric(String registryName, String metricName, BooleanSupplier valueSupplier, @Nullable String description);
// Additionnaly, we might expose an object metrics API.
/**
* Registers a {@link ObjectMetric} metric in registry {@code registryName} with object value supplier {@code valueSupplier}.
* Adds new metric registry if absent.
*
* @return {@code True} if metric was added. {@code False} if another meric already exists under the same name.
*/
<T> boolean objectMetric(String registryName, String metricName, Class<T> valueType, Supplier<T> valueSupplier, @Nullable String description);
/**
* Registers a {@link ObjectMetric} in registry {@code registryName} with object value supplier {@code valueSupplier}.
* Adds new metric registry if absent.
*
* @return New or previously registered object setter.
*/
<T> Consumer<T> objectMetric(String registryName, String metricName, Class<T> valueType, Supplier<T> valueSupplier, @Nullable String description);
}
We already have implementations of more complex and useful metrics. We could also store custom metrics. Thus, the development stages might be: