mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
refactor: better prom metric helper types (#6261)
Improves typing in our Prometheus metric helpers.
This commit is contained in:
parent
b02f8005f1
commit
5f781b4c8f
@ -1,4 +1,14 @@
|
||||
import { Counter, CounterConfiguration } from 'prom-client';
|
||||
import { Counter as PromCounter, CounterConfiguration } from 'prom-client';
|
||||
|
||||
/**
|
||||
* A wrapped instance of prom-client's Counter, overriding some of its methods for enhanced functionality and type-safety.
|
||||
*/
|
||||
export type Counter<T extends string = string> = {
|
||||
counter: PromCounter<T>;
|
||||
labels: (labels: Record<T, string | number>) => PromCounter.Internal;
|
||||
inc: (value?: number | undefined) => void;
|
||||
increment: (labels: Record<T, string | number>, value?: number) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a wrapped instance of prom-client's Counter, overriding some of its methods for enhanced functionality and type-safety.
|
||||
@ -9,11 +19,11 @@ import { Counter, CounterConfiguration } from 'prom-client';
|
||||
*/
|
||||
export const createCounter = <T extends string>(
|
||||
options: CounterConfiguration<T>,
|
||||
) => {
|
||||
): Counter<T> => {
|
||||
/**
|
||||
* The underlying instance of prom-client's Counter.
|
||||
*/
|
||||
const counter = new Counter(options);
|
||||
const counter = new PromCounter<T>(options);
|
||||
|
||||
/**
|
||||
* Applies given labels to the counter. Labels are key-value pairs.
|
||||
|
@ -1,4 +1,14 @@
|
||||
import { Gauge, GaugeConfiguration } from 'prom-client';
|
||||
import { Gauge as PromGauge, GaugeConfiguration } from 'prom-client';
|
||||
|
||||
/**
|
||||
* A wrapped instance of prom-client's Gauge, overriding some of its methods for enhanced functionality and type-safety.
|
||||
*/
|
||||
export type Gauge<T extends string = string> = {
|
||||
gauge: PromGauge<T>;
|
||||
labels: (labels: Record<T, string | number>) => PromGauge.Internal<T>;
|
||||
reset: () => void;
|
||||
set: (value: number) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a wrapped instance of prom-client's Gauge, overriding some of its methods for enhanced functionality and type-safety.
|
||||
@ -9,11 +19,11 @@ import { Gauge, GaugeConfiguration } from 'prom-client';
|
||||
*/
|
||||
export const createGauge = <T extends string>(
|
||||
options: GaugeConfiguration<T>,
|
||||
) => {
|
||||
): Gauge<T> => {
|
||||
/**
|
||||
* The underlying instance of prom-client's Gauge.
|
||||
*/
|
||||
const gauge = new Gauge(options);
|
||||
const gauge = new PromGauge(options);
|
||||
|
||||
/**
|
||||
* Applies given labels to the gauge. Labels are key-value pairs.
|
||||
|
@ -1,4 +1,13 @@
|
||||
import { Summary, SummaryConfiguration } from 'prom-client';
|
||||
import { Summary as PromSummary, SummaryConfiguration } from 'prom-client';
|
||||
|
||||
/**
|
||||
* A wrapped instance of prom-client's Summary, overriding some of its methods for enhanced functionality and type-safety.
|
||||
*/
|
||||
export type Summary<T extends string = string> = {
|
||||
summary: PromSummary<T>;
|
||||
labels: (labels: Record<T, string | number>) => PromSummary.Internal<T>;
|
||||
observe: (value: number) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a wrapped instance of prom-client's Summary, overriding some of its methods for enhanced functionality and type-safety.
|
||||
@ -9,11 +18,11 @@ import { Summary, SummaryConfiguration } from 'prom-client';
|
||||
*/
|
||||
export const createSummary = <T extends string>(
|
||||
options: SummaryConfiguration<T>,
|
||||
) => {
|
||||
): Summary<T> => {
|
||||
/**
|
||||
* The underlying instance of prom-client's Summary.
|
||||
*/
|
||||
const summary = new Summary(options);
|
||||
const summary = new PromSummary(options);
|
||||
|
||||
/**
|
||||
* Applies given labels to the summary. Labels are key-value pairs.
|
||||
|
Loading…
Reference in New Issue
Block a user