Skip to content

Add supporting multi-target dynamic scraping #1120

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

iamhalje
Copy link

@iamhalje iamhalje commented Aug 3, 2025

This PR introduces support for multi-target scraping via the /scrape?target=... endpoint, even when --mongodb.uri is configured globally. This allows dynamic discovery and monitoring of MongoDB instances without restarting the exporter, improving integration with Prometheus service discovery and multi-target configurations.

https://prometheus.io/docs/guides/multi-target-exporter/

scrape_configs:
  - job_name: 'mongodb_exporter_targets'
    metrics_path: /scrape
    static_configs:
      - targets:
          - mongodb://mongo-host1:27017
          - mongo-host2:27017
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: <<MONGODB-EXPORTER-HOSTNAME>>:9216

Unlike the previous approach, where scraping was limited to the fixed list of instances specified by --mongodb.uri and when need added new host, need restart exported, this change enables flexible, on-demand querying of arbitrary MongoDB targets through the /scrape?target=... parameter.

Related issue: #878 — Multi target without need for specifying --mongodb.uri

Leave notes to the reviewers if you need to focus their attention on something specific:

This change affects core logic related to connection handling and target resolution. Existing setups using --mongodb.uri continue to work without changes. At the same time, users can now add dynamic targets seamlessly.
If you notice anything that could affect stability or how can do more good with code structure, caching or backward compatibility, especially in edge cases or other contributed rights, please let me know and we fixed this.

iamhalje added 12 commits August 3, 2025 11:57
…ndle concurrent access

Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
@iamhalje iamhalje requested a review from a team as a code owner August 3, 2025 10:12
@iamhalje iamhalje requested review from BupycHuk and JiriCtvrtka and removed request for a team August 3, 2025 10:12
@it-percona-cla
Copy link

it-percona-cla commented Aug 3, 2025

CLA assistant check
All committers have signed the CLA.

@iamhalje
Copy link
Author

iamhalje commented Aug 7, 2025

any feedback? can be produced

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.

2 participants