Skip to content

Commit

Permalink
Clean up aggregate metrics logs (#1348)
Browse files Browse the repository at this point in the history
Co-authored-by: Saliou Diallo <saliou@audius.co>
  • Loading branch information
sddioulde and Saliou Diallo committed Mar 24, 2021
1 parent abd42d0 commit 290e583
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions discovery-provider/src/utils/redis_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def merge_metrics(metrics, end_time, metric_type, db):
Persist metrics in the database
"""
logger.info(f"about to merge {metric_type} metrics: {metrics}")
logger.info(f"about to merge {metric_type} metrics: {len(metrics)} new entries")
day = end_time.split(':')[0]
month = f"{day[:7]}/01"

Expand Down Expand Up @@ -262,15 +262,15 @@ def merge_metrics(metrics, end_time, metric_type, db):
if timestamp > yesterday_str}
if daily_metrics:
redis_set_and_dump(REDIS, daily_key, json.dumps(daily_metrics))
logger.info(f"updated cached daily {metric_type} metrics: {daily_metrics}")
logger.info(f"updated cached daily {metric_type} metrics")

# clean up metrics METRICS_INTERVAL after the end of the month from monthly_metrics
thirty_one_days_ago = (datetime.utcnow() - timedelta(days=31)).strftime(datetime_format_secondary)
monthly_metrics = {timestamp: metrics for timestamp, metrics in monthly_metrics.items() \
if timestamp > thirty_one_days_ago}
if monthly_metrics:
redis_set_and_dump(REDIS, monthly_key, json.dumps(monthly_metrics))
logger.info(f"updated cached monthly {metric_type} metrics: {monthly_metrics}")
logger.info(f"updated cached monthly {metric_type} metrics")

# persist aggregated metrics from other nodes
day_format = datetime_format_secondary.split(':')[0]
Expand Down Expand Up @@ -361,7 +361,7 @@ def update_personal_metrics(key, old_timestamp, timestamp, value, metric_type):
updated_metrics = {timestamp: metrics for timestamp, metrics in values.items() if timestamp > old_timestamp}
if updated_metrics:
redis_set_and_dump(REDIS, key, json.dumps(updated_metrics))
logger.info(f"updated cached {metric_type} metrics: {updated_metrics}")
logger.info(f"updated cached personal {metric_type} metrics")

def record_aggregate_metrics():
now = datetime.utcnow()
Expand Down

0 comments on commit 290e583

Please sign in to comment.