Skip to content

Support registry as Pushgateway second argument#769

Open
bugprone wants to merge 1 commit into
prometheus:mainfrom
bugprone:fix-pushgateway-registry-argument
Open

Support registry as Pushgateway second argument#769
bugprone wants to merge 1 commit 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

class Pushgateway {
constructor(gatewayUrl, options, registry) {
if (options instanceof Registry) {

@jdmarshall jdmarshall Jul 10, 2026

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.

Strictly speaking, This block and the following block are entangled, since gatewayUrl, registry, registry would not be a legal combination.

Otherwise, I'm surprised this is missing. Someone got enthusiastic in the TS file.

Probably this should be:

constructor(gatewayUrl, options, registry = globalRegistry) {
	if (options instanceof Registry) {
		registry = options;
		options = {};
	}

@jdmarshall

Copy link
Copy Markdown
Contributor

Related to #652

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