Skip to content

Support registry as Pushgateway second argument#769

Merged
jdmarshall merged 2 commits into
prometheus:mainfrom
bugprone:fix-pushgateway-registry-argument
Jul 12, 2026
Merged

Support registry as Pushgateway second argument#769
jdmarshall merged 2 commits into
prometheus:mainfrom
bugprone:fix-pushgateway-registry-argument

Conversation

@bugprone

@bugprone bugprone commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Purpose

Pushgateway accepts an optional options argument before the registry argument. In TypeScript, new Pushgateway(url, registry) was accepted because options was typed as any, but at runtime that registry object was treated as request options and the Pushgateway fell back to the global registry.

This makes the two-argument registry form work at runtime and declares it explicitly in the TypeScript definitions.

Fixes #652.

Changes

  • Treat a Registry passed as the second Pushgateway constructor argument as the registry
  • Add constructor overloads for new Pushgateway(url, registry) and new Pushgateway(url, options, registry)
  • Add a small Pushgateway.Options type with requireJobName plus request option passthrough
  • Add runtime coverage for pushing metrics from a second-argument registry
  • Add TypeScript compile coverage for the supported constructor forms
  • Update the unreleased changelog

Testing

  • npm test -- --runInBand --forceExit
  • Manual smoke check with a local HTTP server verifying new Pushgateway(url, registry).push() sends metrics from the provided registry

Signed-off-by: Jace <bugprone@gmail.com>
Comment thread lib/pushgateway.js
@jdmarshall

Copy link
Copy Markdown
Contributor

Related to #652

Signed-off-by: Jace <bugprone@gmail.com>

@jdmarshall jdmarshall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jdmarshall
jdmarshall merged commit c51c2cd into prometheus:main Jul 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem in .d.ts definition, -> logical errors when using typescript code

2 participants