Skip to content

Commit

Permalink
chore(metrics): Added more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Malinowski authored and Edward Malinowski committed Jun 26, 2024
1 parent 12bd508 commit ee1c407
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fence/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def set_flask_session_values(user):
current_app.scoped_session().add(user)
current_app.scoped_session().commit()

from fence.metrics import login_counter

login_counter.inc()

set_flask_session_values(user)


Expand Down
14 changes: 13 additions & 1 deletion fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ def _log_signed_url_data_info(indexed_file, user_sub, client_id, requested_proto
f"acl={acl} authz={authz} bucket={bucket} user_sub={user_sub} client_id={client_id}"
)

from fence.metrics import presigned_url_counter
from fence.metrics import (
presigned_url_counter,
presigned_url_data_metrics_size_gauge,
)

presigned_url_counter.inc()
presigned_url_data_metrics_size_gauge.set(size_in_kibibytes)


def _get_client_id():
Expand Down Expand Up @@ -1064,6 +1068,10 @@ def get_signed_url(
auth_info,
)

from fence.metrics import presigned_url_download_protocol_s3_counter

presigned_url_download_protocol_s3_counter.inc()

return url

def init_multipart_upload(self, expires_in):
Expand Down Expand Up @@ -1196,6 +1204,10 @@ def get_signed_url(
r_pays_project=r_pays_project,
)

from fence.metrics import presigned_url_download_protocol_gcs_counter

presigned_url_download_protocol_gcs_counter.inc()

return url

def _generate_anonymous_google_storage_signed_url(
Expand Down
5 changes: 5 additions & 0 deletions fence/blueprints/ga4gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ def get_ga4gh_signed_url(object_id, access_id):
requested_protocol=access_id,
ga4gh_passports=ga4gh_passports,
)

from fence.metrics import presigned_urls_ga4gh_drs_counter

presigned_urls_ga4gh_drs_counter.inc()

return flask.jsonify(result)
4 changes: 4 additions & 0 deletions fence/blueprints/login/fence_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def get(self):
)
self.post_login()

from fence.metrics import fence_login_counter

fence_login_counter.inc()

if config["REGISTER_USERS_ON"]:
if not flask.g.user.additional_info.get("registration_info"):
return flask.redirect(
Expand Down
5 changes: 5 additions & 0 deletions fence/blueprints/login/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ def get(self):
config.get("BASE_URL", "")
+ "/link/google/callback?code={}".format(flask.request.args.get("code"))
)

from fence.metrics import google_login_counter

google_login_counter.inc()

return super(GoogleCallback, self).get()
4 changes: 4 additions & 0 deletions fence/blueprints/login/ras.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def post_login(self, user=None, token_result=None, id_from_idp=None):
expires,
)

from fence.metrics import ras_login_counter

ras_login_counter.inc()

flask.current_app.ras_client.store_refresh_token(
user=user, refresh_token=refresh_token, expires=expires + issued_time
)
Expand Down
43 changes: 43 additions & 0 deletions fence/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def _setup_prometheus(app):
multiprocess,
make_wsgi_app,
Counter,
Gauge,
)

# This environment variable MUST be declared before importing the
Expand Down Expand Up @@ -42,6 +43,48 @@ def _setup_prometheus(app):
registry=app.prometheus_registry,
)

fence_login_counter = Counter(
"fence_google_login_requests_total",
"Total number of Google login requests",
registry=app.prometheus_registry,
)

google_login_counter = Counter(
"fence_google_login_requests_total",
"Total number of Google login requests",
registry=app.prometheus_registry,
)

ras_login_counter = Counter(
"fence_ras_login_requests_total",
"Total number of RAS login requests",
registry=app.prometheus_registry,
)

presigned_urls_ga4gh_drs_counter = Counter(
"fence_presigned_urls_ga4gh_drs_requests_total",
"Total number of presigned URL requests for GA4GH DRS",
registry=app.prometheus_registry,
)

presigned_url_download_protocol_gcs_counter = Counter(
"fence_presigned_url_download_protocol_gcs_requests_total",
"Total number of presigned URL requests for GCS",
registry=app.prometheus_registry,
)

presigned_url_download_protocol_s3_counter = Counter(
"fence_presigned_url_download_protocol_s3_requests_total",
"Total number of presigned URL requests for S3",
registry=app.prometheus_registry,
)

presigned_url_data_metrics_size_gauge = Gauge(
"fence_presigned_url_data_metrics_size_bytes",
"Size of data metrics in bytes",
registry=app.prometheus_registry,
)


def init_metrics(app):
from fence import logger
Expand Down

0 comments on commit ee1c407

Please sign in to comment.