Package io.roastedroot.proxywasm
Interface MetricsHandler
-
- All Known Implementing Classes:
SimpleMetricsHandler
public interface MetricsHandlerDefines the contract for handling metrics operations initiated by a Proxy-WASM module. Implementations of this interface are responsible for interacting with the underlying metrics system of the host environment (Prometheus etc.).The host environment provides implementations of these methods to allow WASM modules to define, manipulate, and retrieve metric values.
-
-
Field Summary
Fields Modifier and Type Field Description static MetricsHandlerDEFAULTA default, non-functional instance ofMetricsHandler.
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default intdefineMetric(MetricType metricType, String name)Defines a new metric.default longgetMetric(int metricId)Retrieves the current value of a metric.default io.roastedroot.proxywasm.internal.WasmResultincrementMetric(int metricId, long value)Increments a metric's value (typically used for Counters).default io.roastedroot.proxywasm.internal.WasmResultrecordMetric(int metricId, long value)Records a value for a metric (typically used for Gauges or Histograms).default io.roastedroot.proxywasm.internal.WasmResultremoveMetric(int metricId)Removes or deletes a previously defined metric.
-
-
-
Field Detail
-
DEFAULT
static final MetricsHandler DEFAULT
A default, non-functional instance ofMetricsHandler. This instance throwsWasmExceptionwithWasmResult.UNIMPLEMENTEDfor methods that define or retrieve metrics, and returnsWasmResult.UNIMPLEMENTEDfor methods that modify or remove metrics. Useful as a placeholder or base when only a subset of metrics functionality is needed.
-
-
Method Detail
-
defineMetric
default int defineMetric(MetricType metricType, String name) throws WasmException
Defines a new metric.- Parameters:
metricType- The type of the metric (e.g., Counter, Gauge, Histogram).name- The name of the metric.- Returns:
- A unique identifier (metric ID) for the newly defined metric.
- Throws:
WasmException- If the metric cannot be defined (e.g., name conflict, unsupported type, or if the operation is unimplemented by the host).
-
removeMetric
default io.roastedroot.proxywasm.internal.WasmResult removeMetric(int metricId)
Removes or deletes a previously defined metric.- Parameters:
metricId- The unique identifier of the metric to remove.- Returns:
- A
WasmResultindicating the outcome of the operation (e.g., OK, NOT_FOUND, UNIMPLEMENTED).
-
recordMetric
default io.roastedroot.proxywasm.internal.WasmResult recordMetric(int metricId, long value)Records a value for a metric (typically used for Gauges or Histograms).- Parameters:
metricId- The unique identifier of the metric.value- The value to record.- Returns:
- A
WasmResultindicating the outcome of the operation (e.g., OK, BAD_ARGUMENT, UNIMPLEMENTED).
-
incrementMetric
default io.roastedroot.proxywasm.internal.WasmResult incrementMetric(int metricId, long value)Increments a metric's value (typically used for Counters).- Parameters:
metricId- The unique identifier of the metric.value- The amount to increment by (can be negative to decrement, although convention is usually positive).- Returns:
- A
WasmResultindicating the outcome of the operation (e.g., OK, BAD_ARGUMENT, UNIMPLEMENTED).
-
getMetric
default long getMetric(int metricId) throws WasmExceptionRetrieves the current value of a metric.- Parameters:
metricId- The unique identifier of the metric.- Returns:
- The current value of the metric.
- Throws:
WasmException- If the metric cannot be retrieved (e.g., metric not found, type mismatch, or if the operation is unimplemented by the host).
-
-