Skip to content

Commit

Permalink
Clean up push gateway metrics on exit (#805)
Browse files Browse the repository at this point in the history
This commit adds a cleanup step to the pushgateway application.
This will make it so stale metrics don't hang around.
  • Loading branch information
pawalt authored Jul 9, 2024
1 parent 8c8adb2 commit 27ffca3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 10_integrations/pushgateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def run_pushgateway():
from prometheus_client import (
CollectorRegistry,
Counter,
delete_from_gateway,
push_to_gateway,
)

Expand All @@ -103,6 +104,16 @@ def init(self):
registry=self.registry,
)

# We must explicitly clean up the metric when the app exits so Prometheus doesn't
# keep stale metrics around.
@modal.exit()
def cleanup(self):
delete_from_gateway(
self.web_url,
job="hello",
grouping_key={"instance": self.instance_id},
)

@web_endpoint()
def hello(self):
self.counter.inc()
Expand Down

0 comments on commit 27ffca3

Please sign in to comment.