Avoid prometheus metrics explosion

Openstacksdk reports metrics for prometheus and adds an endpoint-label
containing the full url of every request. In case the endpoints
contain query strings this can easily cause metric explosion. To fix
this we can parse the url and strip the query string.

Change-Id: Ief3c3981a039b3ae38eeaeccd1fb70e974c94082
This commit is contained in:
Tobias Henkel 2021-04-06 12:13:04 +02:00
parent 88f6a31d73
commit 3f2034832b
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2

View File

@ -11,6 +11,7 @@
# under the License.
import urllib
from urllib.parse import urlparse
try:
import simplejson
@ -226,10 +227,13 @@ class Proxy(adapter.Adapter):
url = response.request.url
if response is not None and not method:
method = response.request.method
parsed_url = urlparse(url)
endpoint = "{}://{}{}".format(
parsed_url.scheme, parsed_url.netloc, parsed_url.path)
if response is not None:
labels = dict(
method=method,
endpoint=url,
endpoint=endpoint,
service_type=self.service_type,
status_code=response.status_code,
)