Skip to content
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

GovukPrometheus - custom labels from rack env #424

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

richardTowers
Copy link
Contributor

Apps can use request.env['govuk.prometheus_labels'] to specify custom labels for prometheus.

For example, and app might do:

prometheus_labels = request.env.fetch('govuk.prometheus_labels', {})
request.env['govuk.prometheus_labels'] = prometheus_labels.merge(
  document_type: @content_item.document_type,
  schema_name: @content_item.schema_name,
)

To set the document type / schema name as custom labels (which is useful for the apps where this isn't obvious based on controller / action, like government-frontend)

Testing locally, this results in metrics like:

http_request_duration_seconds_count{action="show",controller="content_items",document_type="answer",schema_name="answer"} 1

Care does need to be taken with the cardinality of prometheus labels (i.e. there shouldn't be too many different combinations of labels), but things like document_type are useful and shouldn't increase cardinality too much.

Apps can use request.env['govuk.prometheus_labels'] to specify custom
labels for prometheus.

For example, and app might do:

    prometheus_labels = request.env.fetch('govuk.prometheus_labels', {})
    request.env['govuk.prometheus_labels'] = prometheus_labels.merge(
      document_type: @content_item.document_type,
      schema_name: @content_item.schema_name,
    )

To set the document type / schema name as custom labels (which is useful
for the apps where this isn't obvious based on controller / action, like
government-frontend)

Testing locally, this results in metrics like:

    http_request_duration_seconds_count{action="show",controller="content_items",document_type="answer",schema_name="answer"} 1

Care does need to be taken with the cardinality of prometheus labels
(i.e. there shouldn't be too many different combinations of labels), but
things like document_type are useful and shouldn't increase cardinality
too much.
@richardTowers richardTowers force-pushed the support-custom-prometheus-labels branch from 70df4ed to d28c553 Compare January 15, 2025 16:00
@richardTowers richardTowers merged commit 3e00ab1 into main Jan 15, 2025
10 checks passed
@richardTowers richardTowers deleted the support-custom-prometheus-labels branch January 15, 2025 16:11
richardTowers added a commit to alphagov/government-frontend that referenced this pull request Jan 15, 2025
This will allow us to investigate the performance of different content
types, for example how long does it take to load a manual vs. an answer
or a case_study.

If there are some content types which take a much longer time to load,
maybe there are performance issues we should address.

This follows on from alphagov/govuk_app_config#424
which adds the functionality to support setting prometheus labels in this way.
richardTowers added a commit to alphagov/government-frontend that referenced this pull request Jan 15, 2025
This will allow us to investigate the performance of different content
types, for example how long does it take to load a manual vs. an answer
or a case_study.

If there are some content types which take a much longer time to load,
maybe there are performance issues we should address.

This follows on from alphagov/govuk_app_config#424
which adds the functionality to support setting prometheus labels in this way.
richardTowers added a commit to alphagov/government-frontend that referenced this pull request Jan 15, 2025
This results in metrics like:

    http_requests_total{action="show",controller="content_items",document_type="answer",schema_name="answer",status="200"} 1

This will allow us to investigate the performance of different content
types, for example how long does it take to load a manual vs. an answer
or a case_study. Currently we can't distinguish these in the metrics for
government-frontend, because it uses the same controller action for all
content types.

If there are some content types which take a much longer time to load,
maybe there are performance issues we should address.

This follows on from alphagov/govuk_app_config#424
which adds the functionality to support setting prometheus labels in this way.
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