Skip to content

Commit

Permalink
17219 FIX gcp_status: Fix KeyError: 'global'
Browse files Browse the repository at this point in the history
This change affects users which have configured the rule 'Google Cloud Platform (GCP) Status'.
Previously, Checkmk did not handle incidents correctly, which had set `global` as an associated location.
This was the corresponding traceback:
```
  File "/omd/sites/mon_home/lib/python3/cmk/plugins/gcp/agent_based/gcp_status.py", line 72, in parse
    data.setdefault(constants.RegionMap[location.id_], []).append(incident)
KeyError: 'global'
```
With this werk, the crash is fixed.

SUP-21870

Change-Id: I56b787d1526d228027d4dc4f9ad5ac069e3aa85e
  • Loading branch information
SoloJacobs committed Jan 9, 2025
1 parent 0cbed36 commit 5c6fe28
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .werks/17219.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[//]: # (werk v2)
# gcp_status: Fix KeyError: 'global'

key | value
---------- | ---
date | 2025-01-02T13:02:00+00:00
version | 2.4.0b1
class | fix
edition | cre
component | checks
level | 1
compatible | yes

This change affects users which have configured the rule 'Google Cloud Platform (GCP) Status'.
Previously, Checkmk did not handle incidents correctly, which had set `global` as an associated location.
This was the corresponding traceback:
```
File "/omd/sites/mon_home/lib/python3/cmk/plugins/gcp/agent_based/gcp_status.py", line 72, in parse
data.setdefault(constants.RegionMap[location.id_], []).append(incident)
KeyError: 'global'
```
With this werk, the crash is fixed.
3 changes: 2 additions & 1 deletion cmk/plugins/gcp/agent_based/gcp_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def parse(string_table: StringTable) -> Section:
data: dict[str, list[Incident]] = {}
for incident in output.health_info:
for location in incident.currently_affected_locations:
data.setdefault(constants.RegionMap[location.id_], []).append(incident)
item = "Global" if location.id_ == "global" else constants.RegionMap[location.id_]
data.setdefault(item, []).append(incident)
return Section(discovery_param=output.discovery_param, data=data)


Expand Down
85 changes: 85 additions & 0 deletions tests/unit/cmk/plugins/gcp/agent_based/test_gcp_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,91 @@ def test_parsing(section: gcp_status.Section) -> None:
}


def test_parsing_global() -> None:
# This is an agent output, which is edited to only have a single (unedited) incident.
string_table = [
[
r"""{
"discovery_param": {
"regions": [
"europe-west3"
]
},
"health_info": [
{
"id": "rZvZvSKVdDHyWh4dZJ8D",
"number": "15564124031412553730",
"begin": "2023-03-10T14:09:43+00:00",
"created": "2023-03-10T14:26:24+00:00",
"end": "2023-03-10T14:54:50+00:00",
"modified": "2023-03-10T14:54:50+00:00",
"external_desc": "Retry errors for Google BigQuery in global",
"updates": [
{
"created": "2023-03-10T14:26:17+00:00",
"modified": "2023-03-10T14:26:28+00:00",
"when": "2023-03-10T14:26:17+00:00",
"text": "Summary: Retry errors for Google BigQuery in global\nDescription: We are experiencing an issue with Google BigQuery.\nOur engineering team continues to investigate the issue.\nWe will provide an update by Friday, 2023-03-10 07:30 US/Pacific with current details.\nDiagnosis: Customers may experience retry errors when running DatasetService.*, TableService.*, BigQueryRead.CreateReadSession, BigQueryRead.ReadRows and BigQueryWrite.* commands for Google BigQuery in global\nWorkaround: Retry requests",
"status": "SERVICE_INFORMATION",
"affected_locations": [
{
"title": "Finland (global)",
"id": "global"
}
]
}
],
"most_recent_update": {
"created": "2023-03-10T14:26:17+00:00",
"modified": "2023-03-10T14:26:28+00:00",
"when": "2023-03-10T14:26:17+00:00",
"text": "Summary: Retry errors for Google BigQuery in global\nDescription: We are experiencing an issue with Google BigQuery.\nOur engineering team continues to investigate the issue.\nWe will provide an update by Friday, 2023-03-10 07:30 US/Pacific with current details.\nDiagnosis: Customers may experience retry errors when running DatasetService.*, TableService.*, BigQueryRead.CreateReadSession, BigQueryRead.ReadRows and BigQueryWrite.* commands for Google BigQuery in global\nWorkaround: Retry requests",
"status": "SERVICE_INFORMATION",
"affected_locations": [
{
"title": "Finland (global)",
"id": "global"
}
]
},
"status_impact": "SERVICE_INFORMATION",
"severity": "low",
"service_key": "9CcrhHUcFevXPSVaSxkf",
"service_name": "Google BigQuery",
"affected_products": [
{
"title": "Google BigQuery",
"id": "9CcrhHUcFevXPSVaSxkf"
}
],
"uri": "incidents/rZvZvSKVdDHyWh4dZJ8D",
"currently_affected_locations": [
{
"title": "Finland (global)",
"id": "global"
}
],
"previously_affected_locations": []
}
]
}
"""
]
]
section_global = gcp_status.parse(string_table)
assert section_global.discovery_param == gcp_status.DiscoveryParam(regions=["europe-west3"])
assert section_global.data == {
"Global": [
gcp_status.Incident(
affected_products=[gcp_status.AffectedProduct(title="Google BigQuery")],
currently_affected_locations=[gcp_status.AffectedLocation(id="global")],
external_desc="Retry errors for Google BigQuery in global",
uri="incidents/rZvZvSKVdDHyWh4dZJ8D",
)
]
}


def test_no_indicents() -> None:
discovery_param = gcp_status.DiscoveryParam(regions=["us-east"])
section = gcp_status.Section(discovery_param=discovery_param, data={})
Expand Down

0 comments on commit 5c6fe28

Please sign in to comment.