Skip to content

When deleting New Relic monitors, don't fail if monitor can't be found.

Boros Gábor requested to merge safe-delete-monitors into master

Created by: itsjeyd

Follow-up to #143.

Makes sure that the process for shutting down an instance does not fail if the New Relic monitors associated with the instance no longer exist.

Test instructions

  1. Temporarily set NEWRELIC_LICENSE_KEY and NEWRELIC_ADMIN_USER_API_KEY in your .env (check OC IM prod config for appropriate values). This is to make sure that the DELETE request performed by delete_synthetics_monitor does not fail with authentication errors.

  2. Start the shell via make shell.

  3. Create a new instance:

    from instance.factories import instance_factory
    instance = instance_factory(name="Instance with fake monitors", sub_domain="instance-fake-monitors")
  4. Associate a single running app server with the instance. This is to make sure that is_shut_down does not short-circuit later on:

    appserver = instance._create_owned_appserver()
    appserver._status_to_waiting_for_server()
    appserver._status_to_configuring_server()
    appserver._status_to_running()
  5. Associate fake New Relics monitors with it:

    monitor_ids = ["fake-monitor-id-{}".format(i) for i in range(3)]
    for monitor_id in monitor_ids:
        instance.new_relic_availability_monitors.create(pk=monitor_id)
    # Precondition check
    assert instance.new_relic_availability_monitors.count() == 3
    assert instance.is_shut_down == False
  6. Shut down instance:

    instance.shut_down()
  7. Verify that monitors have been deleted and instance manager considers instance to be shut down:

    assert instance.new_relic_availability_monitors.count() == 0
    assert instance.is_shut_down == True

Reviewers

  • @haikuginger

Merge request reports