Skip to content

Commit

Permalink
Update index.d.ts - add generic definition for registry using types
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeRiderBysik authored May 13, 2023
1 parent 30a52c5 commit 6a4fb3f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const prometheusContentType: PrometheusContentType;
*/
export const openMetricsContentType: OpenMetricsContentType;

export class AggregatorRegistry extends Registry {
export class AggregatorRegistry<T extends RegistryContentType> extends Registry<T> {
/**
* Gets aggregated metrics for all workers.
* @return {Promise<string>} Promise that resolves with the aggregated
Expand All @@ -136,7 +136,7 @@ export class AggregatorRegistry extends Registry {
* `registry.getMetricsAsJSON()`.
* @return {Registry} aggregated registry.
*/
static aggregate(metricsArr: Array<Object>): Registry; // TODO Promise?
static aggregate<T extends RegistryContentType>(metricsArr: Array<Object>): Registry<T>; // TODO Promise?

/**
* Sets the registry or registries to be aggregated. Call from workers to
Expand All @@ -145,7 +145,10 @@ export class AggregatorRegistry extends Registry {
* aggregated.
* @return {void}
*/
static setRegistries(regs: Array<Registry> | Registry): void;
static setRegistries(regs:
| Array<Registry<PrometheusContentType> | Registry<OpenMetricsContentType>>
| Registry<PrometheusContentType>
| Registry<OpenMetricsContentType>): void;
}

/**
Expand Down Expand Up @@ -655,13 +658,13 @@ export namespace Summary {
/**
* Push metrics to a Pushgateway
*/
export class Pushgateway {
export class Pushgateway<T extends RegistryContentType> {
/**
* @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<T>);

/**
* Add metric and overwrite old ones
Expand Down Expand Up @@ -729,8 +732,8 @@ export function exponentialBuckets(
count: number,
): number[];

export interface DefaultMetricsCollectorConfiguration {
register?: Registry;
export interface DefaultMetricsCollectorConfiguration<T extends RegistryContentType> {
register?: Registry<T>;
prefix?: string;
gcDurationBuckets?: number[];
eventLoopMonitoringPrecision?: number;
Expand All @@ -741,8 +744,8 @@ export interface DefaultMetricsCollectorConfiguration {
* Configure default metrics
* @param config Configuration object for default metrics collector
*/
export function collectDefaultMetrics(
config?: DefaultMetricsCollectorConfiguration,
export function collectDefaultMetrics<T extends RegistryContentType>(
config?: DefaultMetricsCollectorConfiguration<T>,
): void;

export interface defaultMetrics {
Expand Down

0 comments on commit 6a4fb3f

Please sign in to comment.