oncall-engine/engine/apps
Joey Orlando 2bb80b487e
address issue with metrics calculations when redis cluster is used (#3510)
## Which issue(s) this PR fixes

Fixes this issue we started seeing popping up because of a change
introduced in #3496:
```python3
File "/etc/app/apps/metrics_exporter/views.py", line 22, in get
    result = generate_latest(application_metrics_registry).decode("utf-8")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prometheus_client/exposition.py", line 198, in generate_latest
    for metric in registry.collect():
  File "/usr/local/lib/python3.11/site-packages/prometheus_client/registry.py", line 97, in collect
    yield from collector.collect()
  File "/etc/app/apps/metrics_exporter/metrics_collectors.py", line 56, in collect
    alert_groups_total, missing_org_ids_1 = self._get_alert_groups_total_metric(org_ids)
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/etc/app/apps/metrics_exporter/metrics_collectors.py", line 97, in _get_alert_groups_total_metric
    org_id_from_key = RE_ALERT_GROUPS_TOTAL.match(org_key).groups()[0]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'groups'
```



```python3
>>> import re
>>> ALERT_GROUPS_TOTAL = "oncall_alert_groups_total"
>>> _RE_BASE_PATTERN = r"{{?{}}}?_(\d+)"
>>> RE_ALERT_GROUPS_TOTAL = re.compile(_RE_BASE_PATTERN.format(ALERT_GROUPS_TOTAL))
>>> org_key = "{oncall_alert_groups_total}_1"
>>> RE_ALERT_GROUPS_TOTAL.match(org_key).groups()[0]
'1'
>>> org_key = "oncall_alert_groups_total_1"
>>> RE_ALERT_GROUPS_TOTAL.match(org_key).groups()[0]
'1'
```

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-12-05 12:12:08 -05:00
..
alerts Revert "upgrade to Python 3.12 (#3456)" and "bump uwsgi version to latest #3466" (#3483) 2023-12-01 09:56:26 -05:00
api Disallow creating and deleting direct paging integrations (#3475) 2023-12-04 13:13:53 +00:00
api_for_grafana_incident Add render_for_web information to alert group incident API (#3005) 2023-09-12 12:02:42 +00:00
auth_token Change service account auth to use instance id instead (#3435) 2023-11-28 15:56:29 +00:00
base Revert "upgrade to Python 3.12 (#3456)" and "bump uwsgi version to latest #3466" (#3483) 2023-12-01 09:56:26 -05:00
email Minor formatting changes (#2641) 2023-07-26 14:45:44 +01:00
grafana_plugin Revert "Refactor gcom api calls when syncing org" (#3498) 2023-12-04 18:02:58 +00:00
heartbeat Update transaction.on_commit to use partial instead of lambda (#3448) 2023-11-29 12:01:30 +00:00
integrations Add test ensuring integration endpoints work if redis cache is down (#3445) 2023-12-01 17:45:18 +00:00
labels Skip empty alert group labels (#3495) 2023-12-04 13:46:03 +00:00
metrics_exporter address issue with metrics calculations when redis cluster is used (#3510) 2023-12-05 12:12:08 -05:00
mobile_app patch redis cluster multi-key operations (#3496) 2023-12-04 13:08:57 -05:00
oss_installation Revert "upgrade to Python 3.12 (#3456)" and "bump uwsgi version to latest #3466" (#3483) 2023-12-01 09:56:26 -05:00
phone_notifications Revert "upgrade to Python 3.12 (#3456)" and "bump uwsgi version to latest #3466" (#3483) 2023-12-01 09:56:26 -05:00
public_api Disallow creating and deleting direct paging integrations (#3475) 2023-12-04 13:13:53 +00:00
schedules patch redis cluster multi-key operations (#3496) 2023-12-04 13:08:57 -05:00
slack Revert "upgrade to Python 3.12 (#3456)" and "bump uwsgi version to latest #3466" (#3483) 2023-12-01 09:56:26 -05:00
social_auth Enable flake8-bugbear, fix issues (#3454) 2023-11-29 15:04:48 +00:00
telegram Make telegram on_alert_group_action_triggered asynchronous (#3471) 2023-12-01 10:49:00 +00:00
twilioapp add missing db migrations + add additional backend db migration check to CI (#3234) 2023-10-31 16:00:55 -04:00
user_management Revert "Refactor gcom api calls when syncing org" (#3498) 2023-12-04 18:02:58 +00:00
webhooks Enable flake8-bugbear, fix issues (#3454) 2023-11-29 15:04:48 +00:00
zvonok add missing db migrations + add additional backend db migration check to CI (#3234) 2023-10-31 16:00:55 -04:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00