google / google/slo-generator

`IndexError` exception is not caught during `count()` with Cloud Monitoring backend

Open
#296 4 comments 0 reactions 1 assignee Claimed by @lvaylet View on GitHub
backend bug p/cloud_monitoring
Dominant language
Python
Stars
564
Forks
88
PR merge metrics
No merged PRs in 30d

Description

There are issue when I use the backend cloud_monitoring.py in particular the count function. When I have no value like good event, I have the following error :

`Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/slo_generator/backends/cloud_monitoring.py", line 227, in count
return timeseries[0].points[0].value.int64_value`

In meanwhile for fix, I do that
```
@staticmethod
def count(timeseries):
"""Count events in time series assuming it was aligned with ALIGN_SUM
and reduced with REDUCE_SUM (default).

Args:
:obj:`monitoring_v3.TimeSeries`: Timeseries object.

Returns:
int: Event count.
"""
try:
return timeseries[0].points[0].value.int64_value
#except (IndexError, AttributeError) as exception:
# LOGGER.debug(exception, exc_info=True)
except:
return NO_DATA # no events in timeseries
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.