Skip to content
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

Ignore users #21

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions egi_notebooks_accounting/eosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
accounting_url=https://api.acc.staging.eosc.grnet.gr
installaion_id=<id of the installation to report accounting for>
timestamp_file=<file where the timestamp of the last run is kept>
# define which users to ignore for EOSC accounting
ignore_users=monitor

[eosc.flavors]
# contains a list of flavors and metrics they are mapped to
Expand Down Expand Up @@ -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 = ["monitor"]


def get_access_token(token_url, client_id, client_secret):
Expand Down Expand Up @@ -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}")
Expand All @@ -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,
Expand Down Expand Up @@ -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}")
Expand All @@ -251,6 +260,7 @@ def main():
flavor_config,
timestamp_file,
installation,
ignore_users,
args.dry_run,
)
period_start = period_end + timedelta(minutes=1)
Expand Down
Loading