Skip to content

fix: issue with empty prior_values list#54

Merged
monoxgas merged 2 commits into
mainfrom
fix/sum-error
May 16, 2025
Merged

fix: issue with empty prior_values list#54
monoxgas merged 2 commits into
mainfrom
fix/sum-error

Conversation

@danielvaughn
Copy link
Copy Markdown
Contributor

@danielvaughn danielvaughn commented May 16, 2025

Fixes ValueError when passing mode=sum to log_metric

Observed Behavior:

When you log_metric("some_metric", some_number, mode="sum"), the SDK raises the following error. This does not occur for any other aggregation modes.

Caught an error in Dreadnode. This will not prevent code from running, but you may lose data.
Traceback (most recent call last):
  File "sdk/dreadnode/task.py", line 326, in __call__
    span = await self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 [...stack trace...]
 
  File "sdk/dreadnode/metric.py", line 91, in apply_mode
    self.value += max(prior_values)
                  ^^^^^^^^^^^^^^^^^
ValueError: max() arg is an empty sequence

Resolution:

I swapped the summation method for an approach that can handle an empty list.


Generated Summary:

  • Updated the Metric class to modify how values are aggregated in "sum" mode.
  • Changed the logic from using max(prior_values) to sum([self.value, *prior_values]).
  • This change enables more accurate cumulative metrics rather than only taking the maximum value.
  • Potential impact includes adjustment of metric calculations which may affect downstream processes relying on these metrics.

This summary was generated with ❤️ by rigging

@danielvaughn danielvaughn changed the title fix issue with empty prior_values list fix: issue with empty prior_values list May 16, 2025
@monoxgas monoxgas merged commit 4bb5cb4 into main May 16, 2025
8 checks passed
@monoxgas monoxgas deleted the fix/sum-error branch June 17, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants