grafana / oncall

Developer-friendly incident response with brilliant Slack integration
GNU Affero General Public License v3.0
3.49k stars 288 forks source link

[pagerduty-migrator] Error performing migration #387

Closed gilbertobr closed 2 years ago

gilbertobr commented 2 years ago

I came across the following error when using MODE="migrate"

This error usually appears when the process is almost over.

Note: If you run MODE="migrate" again, it breaks elsewhere. Saying that there is already a "schedule" registered. FIle: https://github.com/grafana/oncall/blob/dev/tools/pagerduty-migrator/migrator/oncall_api_client.py

In my view... the behavior should be: If it already exists, it jumps to the next one.

This Field "Start API CALL" and "End API CALL" I put it to make it easier to identify the error.

image

gilbertobr commented 2 years ago

If I add an elif it breaks somewhere else... image

def api_call(method: str, path: str, **kwargs) -> requests.Response:
    url = urljoin(ONCALL_API_URL, path)

    response = requests.request(
        method, url, headers={"Authorization": ONCALL_API_TOKEN}, **kwargs
    )

    try:
        response.raise_for_status()
    except HTTPError as e:
        if e.response.status_code == 429:
            cooldown_seconds = int(e.response.headers["Retry-After"])
            sleep(cooldown_seconds)
            return api_call(method, path, **kwargs)
        elif e.response.status_code == 400:
            print(response.text)
        else:
            raise

    return response

Schedule Value:

{..., 'oncall_schedule': {'detail': 'Schedule with this name already exists'}, 'unmatched_users': []}

vadimkerr commented 2 years ago

Thank you for opening the issue! After taking a look on this, I discovered that the script deletes a Grafana OnCall integration with the same title before migration, please see: https://github.com/grafana/oncall/blob/dev/tools/pagerduty-migrator/migrator/resources/integrations.py#L43. I couldn't reproduce this as well, so I'm closing the issue.