diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c8e619..fc109037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,6 @@ project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -### Changed - -- Cleanup code and refactor to be more efficient - ### Breaking - drop support for Node.js versions 10, 12 and 17 @@ -23,6 +19,8 @@ project adheres to [Semantic Versioning](http://semver.org/). avoid failures from the server when using `Content-Encoding: gzip` header. - Refactor `escapeString` helper in `lib/registry.js` to improve performance and avoid an unnecessarily complex regex. +- Cleanup code and refactor to be more efficient +- Correct TS types for working with OpenMetrics ### Added diff --git a/index.d.ts b/index.d.ts index 15d4e269..a0968138 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,9 +9,9 @@ export type PrometheusMetricsVersion = '0.0.4'; export type OpenMetricsMIME = 'application/openmetrics-text'; export type OpenMetricsVersion = '1.0.0'; -export type PrometheusContentType = - `${OpenMetricsMIME}; version=${OpenMetricsVersion}; charset=${Charset}`; export type OpenMetricsContentType = + `${OpenMetricsMIME}; version=${OpenMetricsVersion}; charset=${Charset}`; +export type PrometheusContentType = `${PrometheusMIME}; version=${PrometheusMetricsVersion}; charset=${Charset}`; export type RegistryContentType = @@ -119,7 +119,9 @@ export const prometheusContentType: PrometheusContentType; */ export const openMetricsContentType: OpenMetricsContentType; -export class AggregatorRegistry extends Registry { +export class AggregatorRegistry< + T extends RegistryContentType, +> extends Registry { /** * Gets aggregated metrics for all workers. * @return {Promise} Promise that resolves with the aggregated @@ -136,7 +138,9 @@ export class AggregatorRegistry extends Registry { * `registry.getMetricsAsJSON()`. * @return {Registry} aggregated registry. */ - static aggregate(metricsArr: Array): Registry; // TODO Promise? + static aggregate( + metricsArr: Array, + ): Registry; // TODO Promise? /** * Sets the registry or registries to be aggregated. Call from workers to @@ -145,7 +149,14 @@ export class AggregatorRegistry extends Registry { * aggregated. * @return {void} */ - static setRegistries(regs: Array | Registry): void; + static setRegistries( + regs: + | Array< + Registry | Registry + > + | Registry + | Registry, + ): void; } /** @@ -655,13 +666,13 @@ export namespace Summary { /** * Push metrics to a Pushgateway */ -export class Pushgateway { +export class Pushgateway { /** * @param url Complete url to the Pushgateway. If port is needed append url with :port * @param options Options * @param registry Registry */ - constructor(url: string, options?: any, registry?: Registry); + constructor(url: string, options?: any, registry?: Registry); /** * Add metric and overwrite old ones @@ -729,8 +740,10 @@ export function exponentialBuckets( count: number, ): number[]; -export interface DefaultMetricsCollectorConfiguration { - register?: Registry; +export interface DefaultMetricsCollectorConfiguration< + T extends RegistryContentType, +> { + register?: Registry; prefix?: string; gcDurationBuckets?: number[]; eventLoopMonitoringPrecision?: number; @@ -741,8 +754,8 @@ export interface DefaultMetricsCollectorConfiguration { * Configure default metrics * @param config Configuration object for default metrics collector */ -export function collectDefaultMetrics( - config?: DefaultMetricsCollectorConfiguration, +export function collectDefaultMetrics( + config?: DefaultMetricsCollectorConfiguration, ): void; export interface defaultMetrics {