From 941e906d217c99feb9e076b4b1222b527fbf35b1 Mon Sep 17 00:00:00 2001 From: nflaig Date: Tue, 17 Jan 2023 13:06:37 +0100 Subject: [PATCH] fix: add get method to type definitions of metric classes --- CHANGELOG.md | 2 ++ index.d.ts | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57da02ac..8f469b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Added +- Add `get` method to type definitions of metric classes + ## [14.1.1] - 2022-12-31 ### Changed diff --git a/index.d.ts b/index.d.ts index a99bcd0c..e0435578 100644 --- a/index.d.ts +++ b/index.d.ts @@ -29,12 +29,12 @@ export class Registry { /** * Get all metrics as objects */ - getMetricsAsJSON(): Promise; + getMetricsAsJSON(): Promise>[]>; /** * Get all metrics as objects */ - getMetricsAsArray(): metric[]; + getMetricsAsArray(): MetricObject[]; /** * Remove a single metric @@ -136,7 +136,7 @@ export enum MetricType { type CollectFunction = (this: T) => void | Promise; -interface metric { +interface MetricObject { name: string; help: string; type: MetricType; @@ -144,6 +144,20 @@ interface metric { collect: CollectFunction; } +interface MetricObjectWithValues> + extends MetricObject { + values: T[]; +} + +type MetricValue = { + value: number; + labels: LabelValues; +}; + +type MetricValueWithName = MetricValue & { + metricName?: string; +}; + type LabelValues = Partial>; interface MetricConfiguration { @@ -182,6 +196,11 @@ export class Counter { */ inc(value?: number): void; + /** + * Get counter metric object + */ + get(): Promise>>; + /** * Return the child for given labels * @param values Label values @@ -277,6 +296,11 @@ export class Gauge { */ set(value: number): void; + /** + * Get gauge metric object + */ + get(): Promise>>; + /** * Set gauge value to current epoch time in ms * @param labels Object with label keys and values @@ -386,6 +410,11 @@ export class Histogram { */ observe(labels: LabelValues, value: number): void; + /** + * Get histogram metric object + */ + get(): Promise>>; + /** * Start a timer. Calling the returned function will observe the duration in * seconds in the histogram. @@ -488,6 +517,11 @@ export class Summary { */ observe(labels: LabelValues, value: number): void; + /** + * Get summary metric object + */ + get(): Promise>>; + /** * Start a timer. Calling the returned function will observe the duration in * seconds in the summary.