fix(pagerduty): apply several small PagerDuty migrator fixes (#5536)
This PR applies the diff described in https://github.com/grafana/irm/issues/1863 to the PagerDuty migrator tool. Specifically, it: - Fixes the target type check for user references in service filtering - Ensures escalation policies are included in the PagerDuty API request - Corrects the logging output for service migration errors
This commit is contained in:
parent
bf7a834e17
commit
307afbe464
2 changed files with 16 additions and 10 deletions
|
|
@ -49,7 +49,7 @@ def filter_services(services: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|||
if service.get("escalation_policy"):
|
||||
for rule in service["escalation_policy"].get("escalation_rules", []):
|
||||
for target in rule.get("targets", []):
|
||||
if target["type"] == "user":
|
||||
if target["type"] == "user_reference":
|
||||
service_users.add(target["id"])
|
||||
|
||||
if not any(user_id in service_users for user_id in PAGERDUTY_FILTER_USERS):
|
||||
|
|
@ -163,6 +163,7 @@ def fetch_services(
|
|||
if include_teams:
|
||||
include_params.append("teams")
|
||||
|
||||
include_params.append("escalation_policies")
|
||||
params = {}
|
||||
if include_params:
|
||||
params["include[]"] = include_params
|
||||
|
|
@ -570,7 +571,7 @@ def _migrate_technical_service(
|
|||
if errors:
|
||||
service.migration_errors = errors
|
||||
service.preserved = False
|
||||
print(TAB + format_service(service, False))
|
||||
print(TAB + format_service(service, True))
|
||||
return None
|
||||
|
||||
if dry_run:
|
||||
|
|
@ -589,7 +590,7 @@ def _migrate_technical_service(
|
|||
except Exception as e:
|
||||
service.migration_errors = str(e)
|
||||
service.preserved = False
|
||||
print(TAB + format_service(service, False))
|
||||
print(TAB + format_service(service, True))
|
||||
return None
|
||||
|
||||
|
||||
|
|
@ -624,7 +625,7 @@ def _migrate_business_service(
|
|||
if errors:
|
||||
service.migration_errors = errors
|
||||
service.preserved = False
|
||||
print(TAB + format_service(service, False))
|
||||
print(TAB + format_service(service, True))
|
||||
return None
|
||||
|
||||
if dry_run:
|
||||
|
|
@ -643,7 +644,7 @@ def _migrate_business_service(
|
|||
except Exception as e:
|
||||
service.migration_errors = str(e)
|
||||
service.preserved = False
|
||||
print(TAB + format_service(service, False))
|
||||
print(TAB + format_service(service, True))
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ def sample_services():
|
|||
"escalation_rules": [
|
||||
{
|
||||
"targets": [
|
||||
{"type": "user", "id": "U123"},
|
||||
{"type": "user", "id": "U456"},
|
||||
{"type": "user_reference", "id": "U123"},
|
||||
{"type": "user_reference", "id": "U456"},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -63,7 +63,9 @@ def sample_services():
|
|||
"type": "service",
|
||||
"teams": [{"summary": "DevOps Team"}],
|
||||
"escalation_policy": {
|
||||
"escalation_rules": [{"targets": [{"type": "user", "id": "U789"}]}]
|
||||
"escalation_rules": [
|
||||
{"targets": [{"type": "user_reference", "id": "U789"}]}
|
||||
]
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -201,7 +203,8 @@ def test_fetch_services(mock_session):
|
|||
|
||||
# Verify API call
|
||||
mock_session.list_all.assert_called_once_with(
|
||||
"services", params={"include[]": ["integrations", "teams"]}
|
||||
"services",
|
||||
params={"include[]": ["integrations", "teams", "escalation_policies"]},
|
||||
)
|
||||
|
||||
# Verify results
|
||||
|
|
@ -220,7 +223,9 @@ def test_fetch_services_without_includes(mock_session):
|
|||
)
|
||||
|
||||
# Verify API call with no includes
|
||||
mock_session.list_all.assert_called_once_with("services", params={})
|
||||
mock_session.list_all.assert_called_once_with(
|
||||
"services", params={"include[]": ["escalation_policies"]}
|
||||
)
|
||||
|
||||
# Verify results
|
||||
assert len(services) == 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue