From 88063d6ed0b73ae4ca0db7b934d577280626bcfa Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Tue, 17 Sep 2024 15:47:50 +0100 Subject: [PATCH] Ignore users --- egi_notebooks_accounting/eosc.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/egi_notebooks_accounting/eosc.py b/egi_notebooks_accounting/eosc.py index 781398c..1da4d23 100644 --- a/egi_notebooks_accounting/eosc.py +++ b/egi_notebooks_accounting/eosc.py @@ -38,6 +38,8 @@ accounting_url=https://api.acc.staging.eosc.grnet.gr installaion_id= timestamp_file= +# define which users to ignore for EOSC accounting +ignore_users=monitoring [eosc.flavors] # contains a list of flavors and metrics they are mapped to @@ -67,6 +69,7 @@ DEFAULT_TOKEN_URL = "https://proxy.staging.eosc-federation.eu/OIDC/token" DEFAULT_ACCOUNTING_URL = "https://api.acc.staging.eosc.grnet.gr" DEFAULT_TIMESTAMP_FILE = "eosc-accounting.timestamp" +DEFAULT_IGNORE_USERS = ["monitoring"] def get_access_token(token_url, client_id, client_secret): @@ -148,6 +151,7 @@ def generate_day_metrics( flavor_config, timestamp_file, installation, + ignore_users, dry_run, ): logging.info(f"Generate metrics from {period_start} to {period_end}") @@ -165,6 +169,9 @@ def generate_day_metrics( period_start_str = period_start.strftime("%Y-%m-%dT%H:%M:%SZ") period_end_str = period_end.strftime("%Y-%m-%dT%H:%M:%SZ") for (user, group), flavors in metrics.items(): + if user in ignore_users: + logging.debug(f"Not sending metrics for user {user} (set to ignore)") + continue for metric_key, value in flavors.items(): metric_data = { "metric_definition_id": metric_key, @@ -236,6 +243,8 @@ def main(): "TIMESTAMP_FILE", eosc_config.get("timestamp_file", DEFAULT_TIMESTAMP_FILE) ) + ignore_users = eosc_config.get("ignore_users", DEFAULT_IGNORE_USERS) + # ==== queries ==== from_date, to_date = get_from_to_dates(args, timestamp_file) logging.debug(f"Reporting from {from_date} to {to_date}") @@ -251,6 +260,7 @@ def main(): flavor_config, timestamp_file, installation, + ignore_users, args.dry_run, ) period_start = period_end + timedelta(minutes=1)