Skip to content

Use homeserver specific Prometheus CollectorRegistry for metrics instead of global REGISTRY#18443

Closed
MadLittleMods wants to merge 42 commits intodevelopfrom
madlittlemods/hs-specific-metrics
Closed

Use homeserver specific Prometheus CollectorRegistry for metrics instead of global REGISTRY#18443
MadLittleMods wants to merge 42 commits intodevelopfrom
madlittlemods/hs-specific-metrics

Conversation

@MadLittleMods
Copy link
Copy Markdown
Contributor

@MadLittleMods MadLittleMods commented May 15, 2025

Use homeserver specific Prometheus CollectorRegistry (hs.metrics_collector_registry) for metrics instead of global REGISTRY which can be polluted with whatever other code/libraries that are running in the same Python process that also use the default REGISTRY.

This is specifically spawning from running multiple Synapse in the same Python process and wanting separate metrics.

Other breaking changes:

  • Remove the specialized metrics listener in favor of our standard http listener with the metrics resource

Initial exploration for #18592

Todo

Update: This is now better tracked by #18592

  • Ensure _set_prometheus_client_use_created_metrics is used with the new path (PrometheusMetricsHackTestCase)
  • Refactor built-in Prometheus metrics to use registry=hs.metrics_collector_registry
    • Counter
    • Histogram
    • Gauge
    • Summary
    • Info
    • Enum
  • Refactor our custom Prometheus Collector metrics to use registry=hs.metrics_collector_registry
    • LaterGauge
    • GaugeBucketCollector
    • CPUMetrics
    • GCCounts
    • PyPyGCStats
    • ReactorLastSeenMetric
    • Background process _Collector
    • JemallocCollector
    • DynamicCollectorRegistry

  • LruCache
    • @cached
      • Make sure _CachedFunctionDescriptor is accounted for in the mypy plugin (scripts-dev/mypy_synapse_plugin.py)

Dev notes

Parts of this PR have been split out to other PRs:

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

@github-actions github-actions Bot deployed to PR Documentation Preview May 15, 2025 21:58 Active
@MadLittleMods MadLittleMods changed the title Use homeserver specific Prometheus CollectorRegistry for metrics instead of using global REGISTRY Use homeserver specific Prometheus CollectorRegistry for metrics instead of global REGISTRY May 15, 2025
@github-actions github-actions Bot deployed to PR Documentation Preview May 16, 2025 22:55 Active
@github-actions github-actions Bot deployed to PR Documentation Preview May 19, 2025 22:00 Active
@github-actions github-actions Bot deployed to PR Documentation Preview May 20, 2025 19:24 Active
@github-actions github-actions Bot deployed to PR Documentation Preview May 20, 2025 21:17 Active
@github-actions github-actions Bot deployed to PR Documentation Preview May 21, 2025 18:14 Active
Conflicts:
	docs/usage/configuration/config_documentation.md
	synapse/module_api/callbacks/spamchecker_callbacks.py
@github-actions github-actions Bot deployed to PR Documentation Preview June 11, 2025 21:39 Active
@MadLittleMods
Copy link
Copy Markdown
Contributor Author

Closing in favor of the smaller PRs that target #18592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant