Skip to content

add seperate info metric per homeserver to reduce label growth #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
from dotenv import load_dotenv
from flask import Flask, request, jsonify
from .metrics import Prometheus, INFOS
from .metrics import Prometheus, INFOS, KEYS

load_dotenv() # take environment variables from .env.

Expand Down Expand Up @@ -58,11 +58,14 @@
@app.route("/report-usage-stats/push", methods=['PUT'])
def report_usage_stats():
"""Receive usage stats and write to prometheus metrics."""
labels = [request.json[key] or 'None' for key in INFOS]
labels = [request.json[key] or 'None' for key in KEYS]
infos = [request.json[key] or 'None' for key in INFOS]
if not app.config['LABELS_INITIALIZED']:
app.logger.debug('Initialize labels %s', labels)
prometheus.metrics['info'].labels(*infos)
prometheus.metrics['info'].labels(*infos).set(1)
for key, value in request.json.items():
if key in INFOS:
if key in INFOS or key in KEYS:
continue
if not app.config['LABELS_INITIALIZED']:
prometheus.metrics[key].labels(*labels)
Expand Down
8 changes: 6 additions & 2 deletions app/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
'event_cache_size'
]

INFOS = [
KEYS = [
'homeserver',
]

INFOS = KEYS + [
'server_context',
'python_version',
'database_engine',
Expand Down Expand Up @@ -66,5 +69,6 @@ def init_app(self, app: Flask):
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {'/metrics': make_wsgi_app()})
self.metadata.info({'version': app.config['VERSION'], 'build': app.config['BUILD']})
self.metrics = {
metric: Gauge(app.config['METRICS_PREFIX'] + metric, metric, INFOS) for metric in GAUGES
metric: Gauge(app.config['METRICS_PREFIX'] + metric, metric, KEYS) for metric in GAUGES
}
self.metrics['info'] = Gauge(app.config['METRICS_PREFIX'] + 'info', 'info', INFOS)