Skip to content

Commit

Permalink
reduce cardinality in api metrics to keep from blowing up prometheus (#…
Browse files Browse the repository at this point in the history
…421)

* reduce cardinality in api metrics to keep from blowing up prometheus

* <bot> update requirements-docs.txt

* <bot> update requirements-tests.txt

* <bot> update requirements.txt

* fix f string

* change verb to method to match other k8s labels

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
dsschult and github-actions authored Feb 7, 2025
1 parent 2c1698a commit 867d564
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions iceprod/prom_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class HistogramBuckets:
# DEFAULT = [.005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10]

#: Database bucket centered around 5ms, with outliers up to 10s
DB = [.001, .002, .003, .004, .005, .006, .007, .008, .009, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
DB = [.001, .0025, .005, .0075, .01, .025, .05, .1, .25, .5, 1, 10]

#: API bucket centered around 50ms, up to 10s
API = [.005, .01, .02, .03, .04, .05, .06, .07, .08, .09, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10]
API = [.005, .01, .025, .04, .05, .06, .075, .1, .25, .5, 1, 5, 10]

#: Timer bucket up to 1 second
SECOND = [.0001, .0005, .001, .0025, .005, .0075, .01, .025, .05, .075, .1, .25, .5, .75, 1]
Expand All @@ -36,7 +36,7 @@ class HistogramBuckets:


class PromRequestMixin:
PromHTTPHistogram = Histogram('http_request_duration_seconds', 'HTTP request duration in seconds', labelnames=('verb', 'path', 'status'), buckets=HistogramBuckets.API)
PromHTTPHistogram = Histogram('http_request_duration_seconds', 'HTTP request duration in seconds', labelnames=('method', 'handler', 'status'), buckets=HistogramBuckets.API)

def prepare(self):
super().prepare()
Expand All @@ -46,9 +46,9 @@ def on_finish(self):
super().on_finish()
end_time = time.monotonic()
self.PromHTTPHistogram.labels(
verb=self.request.method,
path=self.request.path,
status=self.get_status(),
method=str(self.request.method).lower(),
handler=f'{self.__class__.__module__.split(".")[-1]}.{self.__class__.__name__}',
status=str(self.get_status()),
).observe(end_time - self._prom_start_time)


Expand Down
6 changes: 3 additions & 3 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ attrs==25.1.0
# referencing
babel==2.17.0
# via sphinx
boto3==1.36.14
boto3==1.36.15
# via iceprod (setup.py)
botocore==1.36.14
botocore==1.36.15
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -50,7 +50,7 @@ exceptiongroup==1.2.2
# via anyio
h11==0.14.0
# via httpcore
htcondor==24.3.0
htcondor==24.4.0
# via iceprod (setup.py)
httpcore==1.0.7
# via httpx
Expand Down
6 changes: 3 additions & 3 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ attrs==25.1.0
# referencing
beautifulsoup4==4.13.3
# via iceprod (setup.py)
boto3==1.36.14
boto3==1.36.15
# via
# iceprod (setup.py)
# moto
botocore==1.36.14
botocore==1.36.15
# via
# boto3
# moto
Expand Down Expand Up @@ -60,7 +60,7 @@ flexmock==0.12.2
# via iceprod (setup.py)
h11==0.14.0
# via httpcore
htcondor==24.3.0
htcondor==24.4.0
# via iceprod (setup.py)
httpcore==1.0.7
# via httpx
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ attrs==25.1.0
# via
# jsonschema
# referencing
boto3==1.36.14
boto3==1.36.15
# via iceprod (setup.py)
botocore==1.36.14
botocore==1.36.15
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -44,7 +44,7 @@ exceptiongroup==1.2.2
# via anyio
h11==0.14.0
# via httpcore
htcondor==24.3.0
htcondor==24.4.0
# via iceprod (setup.py)
httpcore==1.0.7
# via httpx
Expand Down

0 comments on commit 867d564

Please sign in to comment.