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

fix: Metrics cleanup based on syn module #1233

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

filipecabaco
Copy link
Contributor

What kind of change does this PR introduce?

Adds a new worker that will cleanup metrics based on our syn information to reduce the amount of data pulled by Prometheus.

Copy link

vercel bot commented Nov 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
realtime-demo ⬜️ Ignored (Inspect) Visit Preview Nov 22, 2024 10:12am

@filipecabaco filipecabaco force-pushed the fix/remove-disconnected-tenants-from-metrics branch from 69289d3 to 866ad44 Compare November 21, 2024 23:55
Adds a new worker that will cleanup metrics based on our syn information to reduce the amount of data pulled by Prometheus.
@filipecabaco filipecabaco force-pushed the fix/remove-disconnected-tenants-from-metrics branch from 866ad44 to 17f3fdc Compare November 22, 2024 00:32
config/runtime.exs Outdated Show resolved Hide resolved
Comment on lines +44 to +49
tenant_ids = :ets.select(@table_name, @tenant_id_spec)

:ets.select(@metrics_table, @filter_spec)
|> Enum.uniq()
|> Enum.reject(fn tenant_id -> tenant_id in tenant_ids end)
|> Enum.each(fn tenant_id -> delete_metric(tenant_id) end)
Copy link
Member

Choose a reason for hiding this comment

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

as an alternative

Suggested change
tenant_ids = :ets.select(@table_name, @tenant_id_spec)
:ets.select(@metrics_table, @filter_spec)
|> Enum.uniq()
|> Enum.reject(fn tenant_id -> tenant_id in tenant_ids end)
|> Enum.each(fn tenant_id -> delete_metric(tenant_id) end)
:ets.foldl(
fn {{_, tags}, _}, acc ->
if tags[:tenant],
do: delete_metric(tags[:tenant]) + acc,
else: acc
end,
0,
@table_name
)

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 I prefer the simpler readability since it will be handling a low amount of data... at least for now

Deletes all metrics that contain the given tenant.
"""
@spec delete_metric(String.t()) :: :ok
def delete_metric(tenant) do
Copy link
Member

Choose a reason for hiding this comment

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

:ets.select_delete returns a count of deleted items, which can be useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes but I was ignoring it for now as we don't have a good use case for it now

@filipecabaco filipecabaco merged commit 18dfc46 into main Nov 22, 2024
4 checks passed
@filipecabaco filipecabaco deleted the fix/remove-disconnected-tenants-from-metrics branch November 22, 2024 11:00
@kiwicopple
Copy link
Member

🎉 This PR is included in version 2.33.56 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants