Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request dylangalea/panic!45
  • Loading branch information
Vitaly committed Mar 24, 2021
2 parents 7ecb32a + 0f7c6ab commit 9befc6f
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 395 deletions.
4 changes: 4 additions & 0 deletions alerter/src/data_store/redis/store_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def get_alert_system_is_down(origin_id: str) -> str:
def get_alert_invalid_url(origin_id: str) -> str:
return Keys._as_prefix(_key_alert_invalid_url) + origin_id

@staticmethod
def get_alert_metric_not_found(origin_id: str) -> str:
return Keys._as_prefix(_key_alert_metric_not_found) + origin_id

@staticmethod
def get_alert_github_release(origin_id: str) -> str:
return Keys._as_prefix(_key_alert_github_release) + origin_id
Expand Down
6 changes: 5 additions & 1 deletion alerter/test/alerter/managers/test_github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,16 @@ def test_process_ping_restarts_dead_processes(
self.fail("Test failed: {}".format(e))

@mock.patch.object(multiprocessing.Process, "is_alive")
@mock.patch.object(multiprocessing.Process, "start")
@mock.patch.object(multiprocessing, 'Process')
def test_process_ping_does_not_send_hb_if_processing_fails(
self, is_alive_mock) -> None:
self, mock_process, mock_start, is_alive_mock) -> None:
# This test creates a queue which receives messages with the same
# routing key as the ones sent by send_heartbeat. In this test we will
# check that no heartbeat is sent when mocking a raised exception.
is_alive_mock.side_effect = self.test_exception
mock_start.return_value = None
mock_process.side_effect = self.dummy_process1
try:
self.test_manager._initialise_rabbitmq()
self.test_manager._start_alerters_processes()
Expand Down
6 changes: 5 additions & 1 deletion alerter/test/alerter/managers/test_system_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,16 @@ def test_process_ping_restarts_dead_processes_with_correct_info(
self.fail("Test failed: {}".format(e))

@mock.patch.object(multiprocessing.Process, "is_alive")
@mock.patch.object(multiprocessing.Process, "start")
@mock.patch.object(multiprocessing, 'Process')
def test_process_ping_does_not_send_hb_if_processing_fails(
self, is_alive_mock) -> None:
self, mock_process, mock_start, is_alive_mock) -> None:
# This test creates a queue which receives messages with the same
# routing key as the ones sent by send_heartbeat. In this test we will
# check that no heartbeat is sent when mocking a raised exception.
is_alive_mock.side_effect = self.test_exception
mock_start.return_value = None
mock_process.side_effect = self.dummy_process1
try:
self.test_manager._initialise_rabbitmq()

Expand Down
29 changes: 16 additions & 13 deletions alerter/test/data_store/stores/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from freezegun import freeze_time
from parameterized import parameterized

from multiprocessing import Process
from src.data_store.starters import (start_system_store, start_github_store,
start_alert_store, start_config_store)
from src.data_store.stores.manager import StoreManager
Expand All @@ -26,6 +27,7 @@
disconnect_from_rabbit,
delete_exchange_if_exists,
delete_queue_if_exists)
from test.utils.utils import infinite_fn


class TestStoreManager(unittest.TestCase):
Expand All @@ -48,6 +50,10 @@ def setUp(self) -> None:
self.manager_name,
self.rabbitmq)

# Adding dummy process
self.dummy_process = Process(target=infinite_fn, args=())
self.dummy_process.daemon = True

connect_to_rabbit(self.rabbitmq)
connect_to_rabbit(self.test_rabbit_manager)
self.rabbitmq.exchange_declare(HEALTH_CHECK_EXCHANGE, 'topic', False,
Expand Down Expand Up @@ -79,6 +85,7 @@ def tearDown(self) -> None:
disconnect_from_rabbit(self.test_rabbit_manager)

self.dummy_logger = None
self.dummy_process = None
self.connection_check_time_interval = None
self.rabbitmq = None
self.test_rabbit_manager = None
Expand Down Expand Up @@ -255,11 +262,11 @@ def test_start_stores_processes_starts_the_processes_correctly(
new_alert_process.terminate()
new_alert_process.join()

new_alert_process = self.test_store_manager._store_process_dict[
new_config_process = self.test_store_manager._store_process_dict[
CONFIG_STORE_NAME]
self.assertTrue(new_alert_process.is_alive())
new_alert_process.terminate()
new_alert_process.join()
self.assertTrue(new_config_process.is_alive())
new_config_process.terminate()
new_config_process.join()

@freeze_time("2012-01-01")
@mock.patch("src.data_store.starters.create_logger")
Expand Down Expand Up @@ -527,12 +534,16 @@ def test_process_ping_restarts_dead_processes(
self.fail("Test failed: {}".format(e))

@mock.patch.object(multiprocessing.Process, "is_alive")
@mock.patch.object(multiprocessing.Process, "start")
@mock.patch.object(multiprocessing, 'Process')
def test_process_ping_does_not_send_hb_if_processing_fails(
self, is_alive_mock) -> None:
self, mock_process, mock_start, is_alive_mock) -> None:
# This test creates a queue which receives messages with the same
# routing key as the ones sent by send_heartbeat. In this test we will
# check that no heartbeat is sent when mocking a raised exception.
is_alive_mock.side_effect = self.test_exception
mock_start.return_value = None
mock_process.side_effect = self.dummy_process
try:
self.test_store_manager._initialise_rabbitmq()
self.test_store_manager._start_stores_processes()
Expand Down Expand Up @@ -565,10 +576,6 @@ def test_process_ping_does_not_send_hb_if_processing_fails(
auto_delete=False, passive=True
)
self.assertEqual(0, res.method.message_count)
for store, process in \
self.test_store_manager._store_process_dict.items():
process.terminate()
process.join()
except Exception as e:
self.fail("Test failed: {}".format(e))

Expand All @@ -588,10 +595,6 @@ def test_proc_ping_send_hb_does_not_raise_msg_not_del_exce_if_hb_not_routed(

self.test_store_manager._process_ping(blocking_channel, method,
properties, body)
for store, process in \
self.test_store_manager._store_process_dict.items():
process.terminate()
process.join()
except Exception as e:
self.fail("Test failed: {}".format(e))

Expand Down
3 changes: 2 additions & 1 deletion alerter/test/data_store/stores/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest import mock
from unittest.mock import call

import time
import pika
import pika.exceptions
from freezegun import freeze_time
Expand Down Expand Up @@ -310,7 +311,7 @@ def test_initialise_rabbitmq_initialises_everything_as_expected(
body=self.test_data_str, is_body_dict=False,
properties=pika.BasicProperties(delivery_mode=2),
mandatory=False)

time.sleep(1)
# Re-declare queue to get the number of messages
res = self.test_store.rabbitmq.queue_declare(
SYSTEM_STORE_INPUT_QUEUE, False, True, False, False)
Expand Down
7 changes: 6 additions & 1 deletion alerter/test/data_transformers/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,17 @@ def test_process_ping_does_not_restart_dead_processes_if_all_alive(
@freeze_time("2012-01-01")
@mock.patch.object(DataTransformersManager, "_send_heartbeat")
@mock.patch.object(multiprocessing.Process, "is_alive")
@mock.patch.object(multiprocessing.Process, "start")
@mock.patch.object(multiprocessing, 'Process')
def test_process_ping_does_not_send_hb_if_processing_fails(
self, mock_is_alive, mock_send_hb) -> None:
self, mock_process, mock_start, mock_is_alive, mock_send_hb
) -> None:
# We will perform this test by checking that _send_heartbeat is not
# called. Note we will generate an exception from is_alive
mock_is_alive.side_effect = self.test_exception
mock_send_hb.return_value = None
mock_start.return_value = None
mock_process.side_effect = self.dummy_process1
try:
# Some of the variables below are needed as parameters for the
# process_ping function
Expand Down
6 changes: 5 additions & 1 deletion alerter/test/monitors/managers/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,12 +1566,16 @@ def test_process_ping_restarts_dead_processes_with_correct_info(
self.fail("Test failed: {}".format(e))

@mock.patch.object(multiprocessing.Process, "is_alive")
@mock.patch.object(multiprocessing.Process, "start")
@mock.patch.object(multiprocessing, 'Process')
def test_process_ping_does_not_send_hb_if_processing_fails(
self, is_alive_mock) -> None:
self, mock_process, mock_start, is_alive_mock) -> None:
# This test creates a queue which receives messages with the same
# routing key as the ones sent by send_heartbeat. In this test we will
# check that no heartbeat is sent when mocking a raised exception.
is_alive_mock.side_effect = self.test_exception
mock_start.return_value = None
mock_process.side_effect = self.dummy_process1
try:
self.test_manager._initialise_rabbitmq()

Expand Down
6 changes: 5 additions & 1 deletion alerter/test/monitors/managers/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,12 +1603,16 @@ def test_process_ping_restarts_dead_processes_with_correct_info(
self.fail("Test failed: {}".format(e))

@mock.patch.object(multiprocessing.Process, "is_alive")
@mock.patch.object(multiprocessing.Process, "start")
@mock.patch.object(multiprocessing, 'Process')
def test_process_ping_does_not_send_hb_if_processing_fails(
self, is_alive_mock) -> None:
self, mock_process, mock_start, is_alive_mock) -> None:
# This test creates a queue which receives messages with the same
# routing key as the ones sent by send_heartbeat. In this test we will
# check that no heartbeat is sent when mocking a raised exception.
is_alive_mock.side_effect = self.test_exception
mock_start.return_value = None
mock_process.side_effect = self.dummy_process1
try:
self.test_manager._initialise_rabbitmq()

Expand Down
2 changes: 1 addition & 1 deletion docker-compose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
build:
context: './'
dockerfile: './alerter/Tests_Dockerfile'
image: 'simplyvc/panic_alerter_tests:1.0.0'
image: 'simplyvc/panic_alerter_tests:0.1.1'
volumes:
- './config:/opt/panic/config'
- './alerter/logs:/opt/panic/alerter/logs'
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
build:
context: './'
dockerfile: './web-installer/Dockerfile'
image: 'simplyvc/panic_installer:1.0.0'
image: 'simplyvc/panic_installer:0.1.1'
volumes:
- './config:/opt/panic/config'
- './certificates:/opt/panic/certificates'
Expand Down Expand Up @@ -94,7 +94,7 @@ services:
build:
context: './'
dockerfile: './alerter/Alerter_Dockerfile'
image: 'simplyvc/panic_alerter:1.0.0'
image: 'simplyvc/panic_alerter:0.1.1'
volumes:
- './config:/opt/panic/config'
- './alerter/logs:/opt/panic/alerter/logs'
Expand Down Expand Up @@ -144,7 +144,7 @@ services:
build:
context: './'
dockerfile: './alerter/Health_Checker_Dockerfile'
image: 'simplyvc/alerter_health_checker:1.0.0'
image: 'simplyvc/alerter_health_checker:0.1.1'
volumes:
- './alerter/logs:/opt/panic/alerter/logs'
restart: always
Expand Down
21 changes: 21 additions & 0 deletions docs/CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Change the contents of this file to this:

# Change Log

## 0.1.1

Released on 24th March 2021

- Fixed bug where the `metric_not_found` key was missing inside the store keys.
- Fixed tests having issues running in docker and pipenv.

## 0.1.0

Released on 22nd March 2021

This version contains the following:
* A base alerter that can alert about the host system the nodes are running by monitoring system metrics exposed by node exporter
* A base alerter that can alert on new releases for any GitHub repository.
* Multiple alerting channels supported, namely PagerDuty, OpsGenie, Telegram, E-mail and Twilio.
* A web-based installer to easily set-up PANIC
* A dockerized set-up for easy installation and communication between the different components.
Loading

0 comments on commit 9befc6f

Please sign in to comment.