-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: type safe metric labels (#6201)
* refactor: type safe metric labels * Update metrics after merging unstable * Remove collect method from GaugeExtra * Remove startTimer method from Gauge interface * Default to NoLabels to fix type issues * Allow to partially set labels in startTimer * Fix type compatibility with prom-client Histogram * Sort metric types * chore: update prom-client to v15.1.0 (#6230) * Add metric type tests
- Loading branch information
Showing
55 changed files
with
646 additions
and
686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,9 @@ | ||
import {Gauge, GaugeExtra, Histogram} from "@lodestar/utils"; | ||
|
||
export type Metrics = { | ||
requestTime: Histogram<"routeId">; | ||
streamTime: Histogram<"routeId">; | ||
requestErrors: Gauge<"routeId">; | ||
requestToFallbacks: Gauge<"routeId">; | ||
urlsScore: Gauge<"urlIndex">; | ||
requestTime: Histogram<{routeId: string}>; | ||
streamTime: Histogram<{routeId: string}>; | ||
requestErrors: Gauge<{routeId: string}>; | ||
requestToFallbacks: Gauge<{routeId: string}>; | ||
urlsScore: GaugeExtra<{urlIndex: number}>; | ||
}; | ||
|
||
type LabelValues<T extends string> = Partial<Record<T, string | number>>; | ||
type CollectFn<T extends string> = (metric: Gauge<T>) => void; | ||
|
||
export interface Gauge<T extends string> { | ||
/** | ||
* Increment gauge for given labels | ||
* @param labels Object with label keys and values | ||
* @param value The value to increment with | ||
*/ | ||
inc(labels: LabelValues<T>, value?: number): void; | ||
|
||
/** | ||
* Increment gauge | ||
* @param value The value to increment with | ||
*/ | ||
inc(value?: number): void; | ||
|
||
/** | ||
* Set gauge value for labels | ||
* @param labels Object with label keys and values | ||
* @param value The value to set | ||
*/ | ||
set(labels: LabelValues<T>, value: number): void; | ||
|
||
/** | ||
* Set gauge value | ||
* @param value The value to set | ||
*/ | ||
set(value: number): void; | ||
|
||
addCollect(collectFn: CollectFn<T>): void; | ||
} | ||
|
||
export interface Histogram<T extends string> { | ||
/** | ||
* Start a timer where the value in seconds will observed | ||
* @param labels Object with label keys and values | ||
* @return Function to invoke when timer should be stopped | ||
*/ | ||
startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export type {IBlsVerifier} from "./interface.js"; | ||
export type {BlsMultiThreadWorkerPoolModules} from "./multithread/index.js"; | ||
export type {BlsMultiThreadWorkerPoolModules, JobQueueItemType} from "./multithread/index.js"; | ||
export {BlsMultiThreadWorkerPool} from "./multithread/index.js"; | ||
export {BlsSingleThreadVerifier} from "./singleThread.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from "./metrics.js"; | ||
export * from "./server/index.js"; | ||
export * from "./interface.js"; | ||
export * from "./nodeJsMetrics.js"; | ||
export {RegistryMetricCreator} from "./utils/registryMetricCreator.js"; |
Oops, something went wrong.