Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export supporting metrics types #462

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum MessageSource {
type LabelsGeneric = Record<string, string | undefined>
type CollectFn<Labels extends LabelsGeneric> = (metric: Gauge<Labels>) => void

interface Gauge<Labels extends LabelsGeneric = never> {
export interface Gauge<Labels extends LabelsGeneric = never> {
// Sorry for this mess, `prom-client` API choices are not great
// If the function signature was `inc(value: number, labels?: Labels)`, this would be simpler
inc(value?: number): void
Expand All @@ -36,7 +36,7 @@ interface Gauge<Labels extends LabelsGeneric = never> {
addCollect(collectFn: CollectFn<Labels>): void
}

interface Histogram<Labels extends LabelsGeneric = never> {
export interface Histogram<Labels extends LabelsGeneric = never> {
startTimer(): () => void

observe(value: number): void
Expand All @@ -46,26 +46,26 @@ interface Histogram<Labels extends LabelsGeneric = never> {
reset(): void
}

interface AvgMinMax<Labels extends LabelsGeneric = never> {
export interface AvgMinMax<Labels extends LabelsGeneric = never> {
set(values: number[]): void
set(labels: Labels, values: number[]): void
set(arg1?: Labels | number[], arg2?: number[]): void
}

type GaugeConfig<Labels extends LabelsGeneric> = {
export type GaugeConfig<Labels extends LabelsGeneric> = {
name: string
help: string
labelNames?: keyof Labels extends string ? (keyof Labels)[] : undefined
}

type HistogramConfig<Labels extends LabelsGeneric> = {
export type HistogramConfig<Labels extends LabelsGeneric> = {
name: string
help: string
labelNames?: (keyof Labels)[]
buckets?: number[]
}

type AvgMinMaxConfig<Labels extends LabelsGeneric> = GaugeConfig<Labels>
export type AvgMinMaxConfig<Labels extends LabelsGeneric> = GaugeConfig<Labels>

export interface MetricsRegister {
gauge<T extends LabelsGeneric>(config: GaugeConfig<T>): Gauge<T>
Expand Down