Skip to content

Refactor Gauge metrics to be homeserver-scoped#18725

Merged
MadLittleMods merged 25 commits intodevelopfrom
madlittlemods/18592-refactor-gauge
Jul 29, 2025
Merged

Refactor Gauge metrics to be homeserver-scoped#18725
MadLittleMods merged 25 commits intodevelopfrom
madlittlemods/18592-refactor-gauge

Conversation

@MadLittleMods
Copy link
Copy Markdown
Contributor

@MadLittleMods MadLittleMods commented Jul 23, 2025

Bulk refactor Gauge metrics to be homeserver-scoped. We also add lints to make sure that new Gauge metrics don't sneak in without using the server_name label (SERVER_NAME_LABEL).

Part of #18592

Testing strategy

  1. Add the metrics listener in your homeserver.yaml
    listeners:
      # This is just showing how to configure metrics either way
      #
      # `http` `metrics` resource
      - port: 9322
        type: http
        bind_addresses: ['127.0.0.1']
        resources:
          - names: [metrics]
            compress: false
      # `metrics` listener
      - port: 9323
        type: metrics
        bind_addresses: ['127.0.0.1']
  2. Start the homeserver: poetry run synapse_homeserver --config-path homeserver.yaml
  3. Fetch http://localhost:9322/_synapse/metrics and/or http://localhost:9323/metrics
  4. Observe response includes the TODO metrics with the server_name label

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)

"synapse_federation_last_received_pdu_time",
"The timestamp of the last PDU which was successfully received from the given domain",
labelnames=("server_name",),
labelnames=("origin_server_name", SERVER_NAME_LABEL),
Copy link
Copy Markdown
Contributor Author

@MadLittleMods MadLittleMods Jul 23, 2025

Choose a reason for hiding this comment

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

This metric was already using the server_name label so I've had to rename the label. I've updated the contrib/grafana/synapse.json but it's something we probably want to call out in the upgrade notes (added)

"synapse_federation_last_sent_pdu_time",
"The timestamp of the last PDU which was successfully sent to the given domain",
labelnames=("server_name",),
labelnames=("destination_server_name", SERVER_NAME_LABEL),
Copy link
Copy Markdown
Contributor Author

@MadLittleMods MadLittleMods Jul 23, 2025

Choose a reason for hiding this comment

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

This metric was already using the server_name label so I've had to rename the label. I've updated the contrib/grafana/synapse.json but it's something we probably want to call out in the upgrade notes (added)

@MadLittleMods MadLittleMods force-pushed the madlittlemods/18592-refactor-gauge branch from 18de228 to 6b308e6 Compare July 23, 2025 22:56
@MadLittleMods MadLittleMods force-pushed the madlittlemods/18592-refactor-gauge branch from 6b308e6 to 0fd34a6 Compare July 23, 2025 22:56
@github-actions github-actions Bot deployed to PR Documentation Preview July 23, 2025 22:58 Active
@github-actions github-actions Bot deployed to PR Documentation Preview July 23, 2025 23:27 Active
@github-actions github-actions Bot deployed to PR Documentation Preview July 23, 2025 23:39 Active
@github-actions github-actions Bot deployed to PR Documentation Preview July 23, 2025 23:58 Active
@github-actions github-actions Bot deployed to PR Documentation Preview July 24, 2025 00:18 Active
@github-actions github-actions Bot deployed to PR Documentation Preview July 24, 2025 16:27 Active
@MadLittleMods MadLittleMods marked this pull request as ready for review July 24, 2025 18:42
@MadLittleMods MadLittleMods requested a review from a team as a code owner July 24, 2025 18:42
@github-actions github-actions Bot deployed to PR Documentation Preview July 24, 2025 20:37 Active
Copy link
Copy Markdown
Member

@devonh devonh left a comment

Choose a reason for hiding this comment

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

Other than the small fixes and the comment about argument consistency, these changes seem pretty straightforward.

Comment thread synapse/federation/federation_server.py
Comment thread scripts-dev/mypy_synapse_plugin.py Outdated
Comment thread scripts-dev/mypy_synapse_plugin.py Outdated
return None


def check_prometheus_metric_instantiation(ctx: FunctionSigContext) -> CallableType:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for adding this lint!
This should make maintenance of these changes much more manageable going forward.

Conflicts:
	scripts-dev/mypy_synapse_plugin.py
@github-actions github-actions Bot deployed to PR Documentation Preview July 25, 2025 20:02 Active
MadLittleMods added a commit that referenced this pull request Jul 25, 2025
MadLittleMods added a commit that referenced this pull request Jul 25, 2025
@github-actions github-actions Bot deployed to PR Documentation Preview July 25, 2025 20:24 Active
@MadLittleMods MadLittleMods requested a review from devonh July 25, 2025 20:37
@MadLittleMods MadLittleMods merged commit f13a136 into develop Jul 29, 2025
78 of 80 checks passed
@MadLittleMods MadLittleMods deleted the madlittlemods/18592-refactor-gauge branch July 29, 2025 15:38
@MadLittleMods
Copy link
Copy Markdown
Contributor Author

Thanks for the review @devonh 🐬

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.

2 participants