-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Observe request summary, size, and duration with labels (#3461)
* Send metrics to count endpoints with method and status * Report request size * Observe request duration * Add generic labels on metrics using request matchdict fields * Reinitialize metrics on plugin initialize to ease testing * Fix docstring * Add missing method * Fix crash in response callback when path is invalid unicode
- Loading branch information
Showing
10 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
from unittest import mock | ||
|
||
from kinto.core.testing import skip_if_no_prometheus | ||
|
||
from .support import BaseWebTest | ||
|
||
|
||
@skip_if_no_prometheus | ||
class ViewsMetricsTest(BaseWebTest, unittest.TestCase): | ||
@classmethod | ||
def get_app_settings(cls, extras=None): | ||
settings = super().get_app_settings(extras) | ||
settings["includes"] += "\nkinto.plugins.prometheus" | ||
return settings | ||
|
||
def setUp(self): | ||
super().setUp() | ||
patch = mock.patch("kinto.plugins.prometheus.PrometheusService") | ||
self.mocked = patch.start() | ||
self.addCleanup(patch.stop) | ||
|
||
def test_metrics_have_matchdict_labels(self): | ||
self.app.put("/buckets/beers", headers=self.headers) | ||
self.app.put("/buckets/beers/groups/amateurs", headers=self.headers) | ||
self.app.put("/buckets/beers/collections/barley", headers=self.headers) | ||
self.app.put("/buckets/beers/collections/barley/records/abc", headers=self.headers) | ||
|
||
resp = self.app.get("/__metrics__") | ||
self.assertIn( | ||
'request_size_sum{bucket_id="beers",collection_id="",endpoint="/buckets/beers",group_id="",record_id=""}', | ||
resp.text, | ||
) | ||
self.assertIn( | ||
'request_size_sum{bucket_id="beers",collection_id="",endpoint="/buckets/beers/groups/amateurs",group_id="amateurs",record_id=""}', | ||
resp.text, | ||
) | ||
self.assertIn( | ||
'request_summary_total{bucket_id="beers",collection_id="barley",endpoint="/buckets/beers/collections/barley",group_id="",method="put",record_id="",status="201"}', | ||
resp.text, | ||
) | ||
self.assertIn( | ||
'request_duration_sum{bucket_id="beers",collection_id="barley",endpoint="/buckets/beers/collections/barley/records/abc",group_id="",record_id="abc"}', | ||
resp.text, | ||
) |