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

Freshness metrics #275

Merged
merged 2 commits into from
Oct 4, 2023
Merged

Freshness metrics #275

merged 2 commits into from
Oct 4, 2023

Conversation

KludgeKML
Copy link
Contributor

Adds a freshness metric for OS Places postcodes. Every hour we update the oldest postcode sourced from OS Places APi and allow prometheus to collect its age rounded down to the day. We can then see a graph of the age in seconds of the least-recently updated postcode. Since we're expecting the entire database to be refreshed roughly once a week, we should see this hover around the 7 mark. If it increases significantly above that, we may be seeing problems.

We will evaluate this for a while before deciding if we need to add an alarm state to it.

https://trello.com/c/8P4LRqvl/2171-investigate-how-we-can-handle-os-places-api-being-down

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

@KludgeKML KludgeKML requested a review from 1pretz1 October 3, 2023 10:28
Copy link
Contributor

@1pretz1 1pretz1 left a comment

Choose a reason for hiding this comment

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

Nice idea adding a metric! Left a couple comments on the implementation.

def get_oldest_postcode
# Cache metric to prevent needless expensive calls to the database
Rails.cache.fetch("metrics:oldest_postcode", expires_in: 1.hour) do
(Time.zone.now.to_i - Postcode.os_places.order(updated_at: :asc).first.updated_at.to_i)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the updated_at timestamp seems a little flakey as any update to the record would influence the timestamp, have we considered adding a separate time field for OS places request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is pretty safe because the only way these records get updated is via OS Places API calls (with one exception: bulk CSV import, which is also a reasonable consideration of freshness and is unlikely to happen again anyway).

Copy link
Contributor

@1pretz1 1pretz1 Oct 4, 2023

Choose a reason for hiding this comment

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

For now yes, agreed. However, if the code changes in the future and the records are updated outside of OS places requests then this is metric may no longer be meaningful. I think relying on the standard timestamp values for harvesting data will probably trip someone up in the future. Don't think I'd classify this as a blocker as we're only at risk of breaking a metric but one we'd probably want to consider more if we plan to alert on it 👍

lib/collectors/global_prometheus_collector.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@1pretz1 1pretz1 left a comment

Choose a reason for hiding this comment

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

LGTM

@KludgeKML KludgeKML merged commit e83385b into main Oct 4, 2023
4 checks passed
@KludgeKML KludgeKML deleted the freshness-metrics branch October 4, 2023 11:55
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