From 7ffd66926177da7e587ee86aa9e71c34bd7e2bad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2020 14:48:01 +0000 Subject: [PATCH 01/14] Bump pyyaml from 3.13 to 5.1 Bumps [pyyaml](https://github.com/yaml/pyyaml) from 3.13 to 5.1. - [Release notes](https://github.com/yaml/pyyaml/releases) - [Changelog](https://github.com/yaml/pyyaml/blob/master/CHANGES) - [Commits](https://github.com/yaml/pyyaml/compare/3.13...5.1) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 56a47a3..f94babe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ flask-restplus==0.12.1 marshmallow==3.0.0rc6 jinja2==2.10.1 Flask==1.0.2 -pyyaml==3.13 +pyyaml==5.1 uwsgi==2.0.16 prometheus_flask_exporter==0.9.0 werkzeug==0.16.1 From f03bf475c228e84d2e4cd29a38fa1cdda34ae71d Mon Sep 17 00:00:00 2001 From: Pierre Diancourt Date: Sat, 15 Feb 2020 14:39:23 +0100 Subject: [PATCH 02/14] Fixed typo --- prom2teams/app/teams_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prom2teams/app/teams_client.py b/prom2teams/app/teams_client.py index 5afdeba..4d5ac65 100644 --- a/prom2teams/app/teams_client.py +++ b/prom2teams/app/teams_client.py @@ -12,7 +12,7 @@ def post(teams_webhook_url, message): exception_msg = 'Error performing request to: {}.\n' \ ' Returned status code: {}.\n' \ ' Returned data: {}\n' \ - ' Sended message: {}\n' + ' Sent message: {}\n' raise MicrosoftTeamsRequestException(exception_msg.format(teams_webhook_url, str(response.status_code), str(response.text), From ba008985ea0d0def7e4597f326c74f009e380813 Mon Sep 17 00:00:00 2001 From: Pierre Diancourt Date: Sat, 15 Feb 2020 14:59:16 +0100 Subject: [PATCH 03/14] Fix typo --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4715174..5221a48 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -76,7 +76,7 @@ Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com ### Pull Requests * Fill in [the required template](PULL_REQUEST_TEMPLATE.md) -* Any pull request should has **idealista:develop** as base branch. +* Any pull request should have **idealista:develop** as base branch. ### Changelog From 32bcf3e3b393758d05c38f00449b75059f18a2e1 Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Sat, 11 Apr 2020 22:56:39 +0200 Subject: [PATCH 04/14] #175 Using multi-stage build to create prom2teams image --- Dockerfile | 33 +++++++++++-------------- docker/{ => rootfs}/config.ini | 0 docker/{ => rootfs}/prom2teams_start.sh | 0 docker/{ => rootfs}/replace_config.py | 0 4 files changed, 15 insertions(+), 18 deletions(-) rename docker/{ => rootfs}/config.ini (100%) rename docker/{ => rootfs}/prom2teams_start.sh (100%) rename docker/{ => rootfs}/replace_config.py (100%) diff --git a/Dockerfile b/Dockerfile index 5da77bc..65936a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,24 @@ -FROM python:3.5-alpine - -LABEL maintainer="labs@idealista.com" - -EXPOSE 8089 - -RUN apk add gcc libc-dev linux-headers --no-cache - -WORKDIR /opt/prom2teams - -COPY ./docker/ \ - LICENSE \ +FROM python:3.5-alpine AS builder +WORKDIR /prom2teams +COPY LICENSE \ MANIFEST.in \ README.md \ requirements.txt \ setup.py \ ./ +COPY prom2teams/ prom2teams +COPY bin/ bin +RUN apk add gcc libc-dev linux-headers --no-cache \ + && python setup.py bdist_wheel -COPY ./bin bin -COPY ./prom2teams prom2teams - -RUN python setup.py install - +FROM python:3.5-alpine +LABEL maintainer="labs@idealista.com" +EXPOSE 8089 +WORKDIR /opt/prom2teams +COPY docker/rootfs . +COPY --from=builder /prom2teams/dist . +RUN apk add gcc libc-dev linux-headers --no-cache \ + && pip install prom2teams*.whl ENV PROM2TEAMS_PORT="8089" \ PROM2TEAMS_HOST="0.0.0.0" \ PROM2TEAMS_LOGLEVEL="INFO" \ @@ -28,5 +26,4 @@ ENV PROM2TEAMS_PORT="8089" \ PROM2TEAMS_GROUP_ALERTS_BY="" \ APP_CONFIG_FILE="/opt/prom2teams/config.ini" \ PROM2TEAMS_PROMETHEUS_METRICS="true" - ENTRYPOINT ["sh", "prom2teams_start.sh"] diff --git a/docker/config.ini b/docker/rootfs/config.ini similarity index 100% rename from docker/config.ini rename to docker/rootfs/config.ini diff --git a/docker/prom2teams_start.sh b/docker/rootfs/prom2teams_start.sh similarity index 100% rename from docker/prom2teams_start.sh rename to docker/rootfs/prom2teams_start.sh diff --git a/docker/replace_config.py b/docker/rootfs/replace_config.py similarity index 100% rename from docker/replace_config.py rename to docker/rootfs/replace_config.py From eb2135fa1de514e6d280e7d7fb42d337a1ab89f6 Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Sat, 11 Apr 2020 23:01:31 +0200 Subject: [PATCH 05/14] #175 Using multi-stage build to create prom2teams image (CHANGELOG) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4e76d..9ab2781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +- *[#175](https://github.com/idealista/prom2teams/issues/175) Building docker image using multi-stage build feature* @dortegau ## [2.5.4](https://github.com/idealista/prom2teams/tree/2.5.4) [Full Changelog](https://github.com/idealista/prom2teams/compare/2.5.3...2.5.4) From 3f448d2eaa9be121372d9ff343aee1fe01f6a31c Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Sun, 12 Apr 2020 19:30:21 +0200 Subject: [PATCH 06/14] #177 Fixing unit tests when using Python <= 3.6 --- CHANGELOG.md | 3 ++ tests/data/{jsons => json_files}/all_ok.json | 0 .../all_ok_extra_annotations.json | 0 .../all_ok_extra_labels.json | 0 .../all_ok_multiple.json | 0 .../teams_alarm_all_ok.json | 0 .../teams_alarm_all_ok_extra_annotations.json | 0 .../teams_alarm_all_ok_extra_labels.json | 0 .../teams_alarm_all_ok_multiple.json | 0 .../teams_alarm_with_common_items.json | 0 .../with_common_items.json | 0 .../without_instance_field.json | 0 .../without_mandatory_field.json | 0 .../without_optional_field.json | 0 ...faults.ini => not_overriding_defaults.ini} | 0 tests/test_app_configuration.py | 16 ++++---- tests/test_json_fields.py | 39 +++++++++---------- 17 files changed, 30 insertions(+), 28 deletions(-) rename tests/data/{jsons => json_files}/all_ok.json (100%) rename tests/data/{jsons => json_files}/all_ok_extra_annotations.json (100%) rename tests/data/{jsons => json_files}/all_ok_extra_labels.json (100%) rename tests/data/{jsons => json_files}/all_ok_multiple.json (100%) rename tests/data/{jsons => json_files}/teams_alarm_all_ok.json (100%) rename tests/data/{jsons => json_files}/teams_alarm_all_ok_extra_annotations.json (100%) rename tests/data/{jsons => json_files}/teams_alarm_all_ok_extra_labels.json (100%) rename tests/data/{jsons => json_files}/teams_alarm_all_ok_multiple.json (100%) rename tests/data/{jsons => json_files}/teams_alarm_with_common_items.json (100%) rename tests/data/{jsons => json_files}/with_common_items.json (100%) rename tests/data/{jsons => json_files}/without_instance_field.json (100%) rename tests/data/{jsons => json_files}/without_mandatory_field.json (100%) rename tests/data/{jsons => json_files}/without_optional_field.json (100%) rename tests/data/{without_overriding_defaults.ini => not_overriding_defaults.ini} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4e76d..1bd058b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +## Fixed +- *[#177](https://github.com/idealista/prom2teams/issues/177) Fixing unit tests when using Python <= 3.6* @dortegau + ## [2.5.4](https://github.com/idealista/prom2teams/tree/2.5.4) [Full Changelog](https://github.com/idealista/prom2teams/compare/2.5.3...2.5.4) ## Fixed diff --git a/tests/data/jsons/all_ok.json b/tests/data/json_files/all_ok.json similarity index 100% rename from tests/data/jsons/all_ok.json rename to tests/data/json_files/all_ok.json diff --git a/tests/data/jsons/all_ok_extra_annotations.json b/tests/data/json_files/all_ok_extra_annotations.json similarity index 100% rename from tests/data/jsons/all_ok_extra_annotations.json rename to tests/data/json_files/all_ok_extra_annotations.json diff --git a/tests/data/jsons/all_ok_extra_labels.json b/tests/data/json_files/all_ok_extra_labels.json similarity index 100% rename from tests/data/jsons/all_ok_extra_labels.json rename to tests/data/json_files/all_ok_extra_labels.json diff --git a/tests/data/jsons/all_ok_multiple.json b/tests/data/json_files/all_ok_multiple.json similarity index 100% rename from tests/data/jsons/all_ok_multiple.json rename to tests/data/json_files/all_ok_multiple.json diff --git a/tests/data/jsons/teams_alarm_all_ok.json b/tests/data/json_files/teams_alarm_all_ok.json similarity index 100% rename from tests/data/jsons/teams_alarm_all_ok.json rename to tests/data/json_files/teams_alarm_all_ok.json diff --git a/tests/data/jsons/teams_alarm_all_ok_extra_annotations.json b/tests/data/json_files/teams_alarm_all_ok_extra_annotations.json similarity index 100% rename from tests/data/jsons/teams_alarm_all_ok_extra_annotations.json rename to tests/data/json_files/teams_alarm_all_ok_extra_annotations.json diff --git a/tests/data/jsons/teams_alarm_all_ok_extra_labels.json b/tests/data/json_files/teams_alarm_all_ok_extra_labels.json similarity index 100% rename from tests/data/jsons/teams_alarm_all_ok_extra_labels.json rename to tests/data/json_files/teams_alarm_all_ok_extra_labels.json diff --git a/tests/data/jsons/teams_alarm_all_ok_multiple.json b/tests/data/json_files/teams_alarm_all_ok_multiple.json similarity index 100% rename from tests/data/jsons/teams_alarm_all_ok_multiple.json rename to tests/data/json_files/teams_alarm_all_ok_multiple.json diff --git a/tests/data/jsons/teams_alarm_with_common_items.json b/tests/data/json_files/teams_alarm_with_common_items.json similarity index 100% rename from tests/data/jsons/teams_alarm_with_common_items.json rename to tests/data/json_files/teams_alarm_with_common_items.json diff --git a/tests/data/jsons/with_common_items.json b/tests/data/json_files/with_common_items.json similarity index 100% rename from tests/data/jsons/with_common_items.json rename to tests/data/json_files/with_common_items.json diff --git a/tests/data/jsons/without_instance_field.json b/tests/data/json_files/without_instance_field.json similarity index 100% rename from tests/data/jsons/without_instance_field.json rename to tests/data/json_files/without_instance_field.json diff --git a/tests/data/jsons/without_mandatory_field.json b/tests/data/json_files/without_mandatory_field.json similarity index 100% rename from tests/data/jsons/without_mandatory_field.json rename to tests/data/json_files/without_mandatory_field.json diff --git a/tests/data/jsons/without_optional_field.json b/tests/data/json_files/without_optional_field.json similarity index 100% rename from tests/data/jsons/without_optional_field.json rename to tests/data/json_files/without_optional_field.json diff --git a/tests/data/without_overriding_defaults.ini b/tests/data/not_overriding_defaults.ini similarity index 100% rename from tests/data/without_overriding_defaults.ini rename to tests/data/not_overriding_defaults.ini diff --git a/tests/test_app_configuration.py b/tests/test_app_configuration.py index e6c795b..85f9f38 100644 --- a/tests/test_app_configuration.py +++ b/tests/test_app_configuration.py @@ -1,4 +1,6 @@ import unittest +import os + from prom2teams.app import configuration from prom2teams.app import exceptions @@ -8,23 +10,23 @@ class TestServer(unittest.TestCase): DEFAULT_CONFIG_RELATIVE_PATH = './prom2teams/config.ini' def test_get_config_with_invalid_path(self): - invalid_relative_path = self.TEST_CONFIG_FILES_PATH + 'invalid_path' + invalid_relative_path = os.path.join(self.TEST_CONFIG_FILES_PATH, 'invalid_path') self.assertRaises(FileNotFoundError, configuration._config_provided, invalid_relative_path) def test_get_config_without_required_keys_should_raise_exception(self): - empty_config_relative_path = self.TEST_CONFIG_FILES_PATH + 'empty_config.ini' + empty_config_relative_path = os.path.join(self.TEST_CONFIG_FILES_PATH, 'empty_config.ini') self.assertRaises(exceptions.MissingConnectorConfigKeyException, configuration._config_provided, empty_config_relative_path) def test_get_config_without_override(self): - provided_config_relative_path = self.TEST_CONFIG_FILES_PATH + 'without_overriding_defaults.ini' + provided_config_relative_path = os.path.join(self.TEST_CONFIG_FILES_PATH, 'not_overriding_defaults.ini') config = configuration._config_provided(provided_config_relative_path) self.assertTrue(config.get('Microsoft Teams', 'Connector')) def test_get_config_overriding_defaults(self): - provided_config_relative_path = self.TEST_CONFIG_FILES_PATH + 'overriding_defaults.ini' + provided_config_relative_path = os.path.join(self.TEST_CONFIG_FILES_PATH, 'overriding_defaults.ini') config = configuration._config_provided(provided_config_relative_path) self.assertEqual(config.get('HTTP Server', 'Host'), '1.1.1.1') @@ -32,7 +34,7 @@ def test_get_config_overriding_defaults(self): self.assertTrue(config.get('Microsoft Teams', 'Connector')) def test_connectors_configured(self): - provided_config_relative_path = self.TEST_CONFIG_FILES_PATH + 'multiple_connectors_config.ini' + provided_config_relative_path = os.path.join(self.TEST_CONFIG_FILES_PATH, 'multiple_connectors_config.ini') config = configuration._config_provided(provided_config_relative_path) self.assertEqual(config['Microsoft Teams']['connector1'], 'teams_webhook_url') @@ -40,7 +42,7 @@ def test_connectors_configured(self): self.assertEqual(config['Microsoft Teams']['connector3'], 'definitely_another_teams_webhook_url') def test_get_config_for_all_fields(self): - provided_config_relative_path = self.TEST_CONFIG_FILES_PATH + 'all_fields.ini' + provided_config_relative_path = os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_fields.ini') config = configuration._config_provided(provided_config_relative_path) self.assertEqual(config.get('HTTP Server', 'Host'), '1.1.1.1') @@ -51,7 +53,5 @@ def test_get_config_for_all_fields(self): self.assertEqual(config.get('Template', 'Path'), 'jinja2/template/path') self.assertEqual(config.get('Group Alerts', 'Field'), 'name') - - if __name__ == '__main__': unittest.main() diff --git a/tests/test_json_fields.py b/tests/test_json_fields.py index 8c9ac99..7d124e4 100644 --- a/tests/test_json_fields.py +++ b/tests/test_json_fields.py @@ -1,45 +1,45 @@ import unittest +import os import json from prom2teams.teams.alarm_mapper import map_prom_alerts_to_teams_alarms from prom2teams.prometheus.message_schema import MessageSchema from prom2teams.app.sender import AlarmSender - class TestJSONFields(unittest.TestCase): - TEST_CONFIG_FILES_PATH = 'tests/data/jsons/' + TEST_CONFIG_FILES_PATH = 'tests/data/json_files/' def test_json_with_all_fields(self): - with open(self.TEST_CONFIG_FILES_PATH + 'all_ok.json') as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_ok.json')) as json_data: json_received = json.load(json_data) alerts = MessageSchema().load(json_received) alarm = map_prom_alerts_to_teams_alarms(alerts)[0] self.assertNotIn('unknown', str(alarm)) def test_json_without_mandatory_field(self): - with open(self.TEST_CONFIG_FILES_PATH + 'without_mandatory_field.json') as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'without_mandatory_field.json')) as json_data: json_received = json.load(json_data) alerts = MessageSchema().load(json_received) alarm = map_prom_alerts_to_teams_alarms(alerts)[0] self.assertIn('unknown', str(alarm)) def test_json_without_optional_field(self): - with open(self.TEST_CONFIG_FILES_PATH + 'without_optional_field.json') as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'without_optional_field.json')) as json_data: json_received = json.load(json_data) alerts = MessageSchema().load(json_received) alarm = map_prom_alerts_to_teams_alarms(alerts)[0] self.assertIn("'description': 'unknown'", str(alarm)) def test_json_without_instance_field(self): - with open(self.TEST_CONFIG_FILES_PATH + 'without_instance_field.json') as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'without_instance_field.json')) as json_data: json_received = json.load(json_data) alerts = MessageSchema().load(json_received) alarm = map_prom_alerts_to_teams_alarms(alerts)[0] self.assertEqual('unknown', str(alarm['instance'])) def test_compose_all(self): - with open(self.TEST_CONFIG_FILES_PATH + 'all_ok.json') as json_data: - with open(self.TEST_CONFIG_FILES_PATH + 'teams_alarm_all_ok.json') as expected_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_ok.json')) as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'teams_alarm_all_ok.json')) as expected_data: json_received = json.load(json_data) json_expected = json.load(expected_data) @@ -51,8 +51,8 @@ def test_compose_all(self): def test_with_common_items(self): self.maxDiff = None - with open(self.TEST_CONFIG_FILES_PATH + 'with_common_items.json') as json_data: - with open(self.TEST_CONFIG_FILES_PATH + 'teams_alarm_with_common_items.json') as expected_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'with_common_items.json')) as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'teams_alarm_with_common_items.json')) as expected_data: json_received = json.load(json_data) json_expected = json.load(expected_data) @@ -63,8 +63,8 @@ def test_with_common_items(self): self.assertEqual(json_rendered.keys(), json_expected.keys()) def test_grouping_multiple_alerts(self): - with open(self.TEST_CONFIG_FILES_PATH + 'all_ok_multiple.json') as json_data: - with open(self.TEST_CONFIG_FILES_PATH + 'teams_alarm_all_ok_multiple.json') as expected_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_ok_multiple.json')) as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'teams_alarm_all_ok_multiple.json')) as expected_data: json_received = json.load(json_data) json_expected = json.load(expected_data) @@ -72,12 +72,12 @@ def test_grouping_multiple_alerts(self): rendered_data = AlarmSender(group_alerts_by='name')._create_alarms(alerts)[0].replace("\n\n\n", " ") json_rendered = json.loads(rendered_data) - self.assertDictEqual(json_rendered, json_expected) + self.assertEqual(json.dumps(json_rendered, sort_keys=True), json.dumps(json_expected, sort_keys=True)) def test_with_extra_labels(self): excluded_labels = ('pod_name', ) - with open(self.TEST_CONFIG_FILES_PATH + 'all_ok_extra_labels.json') as json_data: - with open(self.TEST_CONFIG_FILES_PATH + 'teams_alarm_all_ok_extra_labels.json') as expected_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_ok_extra_labels.json')) as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'teams_alarm_all_ok_extra_labels.json')) as expected_data: json_received = json.load(json_data) json_expected = json.load(expected_data) @@ -85,12 +85,12 @@ def test_with_extra_labels(self): rendered_data = AlarmSender()._create_alarms(alerts)[0] json_rendered = json.loads(rendered_data) - self.assertDictEqual(json_rendered, json_expected) + self.assertEqual(json.dumps(json_rendered, sort_keys=True), json.dumps(json_expected, sort_keys=True)) def test_with_extra_annotations(self): excluded_annotations = ('message', ) - with open(self.TEST_CONFIG_FILES_PATH + 'all_ok_extra_annotations.json') as json_data: - with open(self.TEST_CONFIG_FILES_PATH + 'teams_alarm_all_ok_extra_annotations.json') as expected_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_ok_extra_annotations.json')) as json_data: + with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'teams_alarm_all_ok_extra_annotations.json')) as expected_data: json_received = json.load(json_data) json_expected = json.load(expected_data) @@ -98,8 +98,7 @@ def test_with_extra_annotations(self): rendered_data = AlarmSender()._create_alarms(alerts)[0] json_rendered = json.loads(rendered_data) - self.assertDictEqual(json_rendered, json_expected) - + self.assertEqual(json.dumps(json_rendered, sort_keys=True), json.dumps(json_expected, sort_keys=True)) if __name__ == '__main__': unittest.main() From af3c4603eea38f2de84c360b6ad2e8f82fe048a5 Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Sun, 12 Apr 2020 22:13:25 +0200 Subject: [PATCH 07/14] #177 Fixing unit tests when using Python <= 3.6 --- prom2teams/teams/alarm_mapper.py | 6 ------ requirements.txt | 1 + tests/test_json_fields.py | 14 ++++++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/prom2teams/teams/alarm_mapper.py b/prom2teams/teams/alarm_mapper.py index 39d1158..3269266 100644 --- a/prom2teams/teams/alarm_mapper.py +++ b/prom2teams/teams/alarm_mapper.py @@ -2,12 +2,6 @@ from collections import defaultdict -def map_alarm_to_json(alarm): - schema = TeamsAlarmSchema() - result = schema.dump(alarm) - return result - - def map_prom_alerts_to_teams_alarms(alerts): alerts = group_alerts(alerts, 'status') teams_alarms = [] diff --git a/requirements.txt b/requirements.txt index 56a47a3..8514875 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ pyyaml==3.13 uwsgi==2.0.16 prometheus_flask_exporter==0.9.0 werkzeug==0.16.1 +DeepDiff==4.3.0 \ No newline at end of file diff --git a/tests/test_json_fields.py b/tests/test_json_fields.py index 7d124e4..c05e37e 100644 --- a/tests/test_json_fields.py +++ b/tests/test_json_fields.py @@ -6,6 +6,8 @@ from prom2teams.prometheus.message_schema import MessageSchema from prom2teams.app.sender import AlarmSender +from deepdiff import DeepDiff + class TestJSONFields(unittest.TestCase): TEST_CONFIG_FILES_PATH = 'tests/data/json_files/' @@ -47,7 +49,8 @@ def test_compose_all(self): rendered_data = AlarmSender()._create_alarms(alerts)[0] json_rendered = json.loads(rendered_data) - self.assertDictEqual(json_rendered, json_expected) + diff = DeepDiff(json_rendered, json_expected, ignore_order=True) + self.assertTrue(not diff) def test_with_common_items(self): self.maxDiff = None @@ -72,7 +75,8 @@ def test_grouping_multiple_alerts(self): rendered_data = AlarmSender(group_alerts_by='name')._create_alarms(alerts)[0].replace("\n\n\n", " ") json_rendered = json.loads(rendered_data) - self.assertEqual(json.dumps(json_rendered, sort_keys=True), json.dumps(json_expected, sort_keys=True)) + diff = DeepDiff(json_rendered, json_expected, ignore_order=True) + self.assertTrue(not diff) def test_with_extra_labels(self): excluded_labels = ('pod_name', ) @@ -85,7 +89,8 @@ def test_with_extra_labels(self): rendered_data = AlarmSender()._create_alarms(alerts)[0] json_rendered = json.loads(rendered_data) - self.assertEqual(json.dumps(json_rendered, sort_keys=True), json.dumps(json_expected, sort_keys=True)) + diff = DeepDiff(json_rendered, json_expected, ignore_order=True) + self.assertTrue(not diff) def test_with_extra_annotations(self): excluded_annotations = ('message', ) @@ -98,7 +103,8 @@ def test_with_extra_annotations(self): rendered_data = AlarmSender()._create_alarms(alerts)[0] json_rendered = json.loads(rendered_data) - self.assertEqual(json.dumps(json_rendered, sort_keys=True), json.dumps(json_expected, sort_keys=True)) + diff = DeepDiff(json_rendered, json_expected, ignore_order=True) + self.assertTrue(not diff) if __name__ == '__main__': unittest.main() From fe3602ad3c0db946d1051bdf115b278b9652c743 Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Sun, 12 Apr 2020 22:53:31 +0200 Subject: [PATCH 08/14] #177 Fixing unit tests when using Python <= 3.6 --- tests/test_app_configuration.py | 2 +- tests/test_json_fields.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_app_configuration.py b/tests/test_app_configuration.py index 85f9f38..65de2db 100644 --- a/tests/test_app_configuration.py +++ b/tests/test_app_configuration.py @@ -6,7 +6,7 @@ class TestServer(unittest.TestCase): - TEST_CONFIG_FILES_PATH = 'tests/data/' + TEST_CONFIG_FILES_PATH = './tests/data/' DEFAULT_CONFIG_RELATIVE_PATH = './prom2teams/config.ini' def test_get_config_with_invalid_path(self): diff --git a/tests/test_json_fields.py b/tests/test_json_fields.py index c05e37e..1f008d6 100644 --- a/tests/test_json_fields.py +++ b/tests/test_json_fields.py @@ -9,7 +9,7 @@ from deepdiff import DeepDiff class TestJSONFields(unittest.TestCase): - TEST_CONFIG_FILES_PATH = 'tests/data/json_files/' + TEST_CONFIG_FILES_PATH = './tests/data/json_files/' def test_json_with_all_fields(self): with open(os.path.join(self.TEST_CONFIG_FILES_PATH, 'all_ok.json')) as json_data: From e282d2d7f1b6fb4451d17e5ed007246de997f8eb Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Mon, 13 Apr 2020 01:12:24 +0200 Subject: [PATCH 09/14] #158 Fixing Travis Badge and reordering TOC --- CHANGELOG.md | 3 +++ README.md | 67 ++++++++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4e76d..e3dab4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +## Fixed +- *[#158](https://github.com/idealista/prom2teams/issues/158) Fixing Travis Badge (pointing to master branch) and reordering TOC* @dortegau + ## [2.5.4](https://github.com/idealista/prom2teams/tree/2.5.4) [Full Changelog](https://github.com/idealista/prom2teams/compare/2.5.3...2.5.4) ## Fixed diff --git a/README.md b/README.md index ca28ac1..1e16f00 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ ![Logo](https://raw.githubusercontent.com/idealista/prom2teams/master/logo.gif) -[![Build Status](https://travis-ci.org/idealista/prom2teams.png)](https://travis-ci.org/idealista/prom2teams) +[![Build Status](https://travis-ci.org/idealista/prom2teams.svg?branch=master)](https://travis-ci.org/idealista/prom2teams) [![Docker Build Status](https://img.shields.io/docker/build/idealista/prom2teams.svg)](https://hub.docker.com/r/idealista/prom2teams/) +[![Docker Hub Pulls](https://img.shields.io/docker/pulls/idealista/prom2teams.svg)](https://hub.docker.com/r/idealista/prom2teams/) [![Docker Automated build](https://img.shields.io/docker/automated/idealista/prom2teams.svg)](https://hub.docker.com/r/idealista/prom2teams/) - # prom2teams Alert example @@ -14,9 +14,13 @@ - [Prerequisities](#prerequisites) - [Installing](#installing) - [Usage](#usage) + - [Docker Image](#docker-image) + - [Helm Chart](#helm-chart) - [Config file](#config-file) - [Configuring Prometheus](#configuring-prometheus) - [Templating](#templating) +- [Documentation](#documentation) + - [Swagger UI](#swagger-ui) - [Testing](#testing) - [Built With](#built-with) - [Versioning](#versioning) @@ -61,12 +65,29 @@ $ prom2teams ``` **Note:** Grouping alerts works since v2.2.1 -### Prom2teams Prometheus metrics +### Docker image -Prom2teams uses Flask and, to have the service monitored, we use @rycus66's [Prometheus Flask Exporter](https://github.com/rycus86/prometheus_flask_exporter). This will enable an endpoint in `/metrics` where you could find interesting metrics to monitor such as number of responses with a certain status. To enable this endpoint, just either: +Every new Prom2teams release, a new Docker image is built in our [Dockerhub](https://hub.docker.com/r/idealista/prom2teams). We strongly recommend you to use the images with the version tag, though it will be possible to use them without it. -- Use the `--enablemetrics` or `-m` flag when launching prom2teams. -- Set the environment variable `PROM2TEAMS_PROMETHEUS_METRICS=true`. +There are two things you need to bear in mind when creating a Prom2teams container: + +- The connector URL must be passed as the environment variable `PROM2TEAMS_CONNECTOR` +- In case you want to group alerts, you need to pass the field as the environment variable `PROM2TEAMS_GROUP_ALERTS_BY` +- You need to map container's Prom2teams port to one on your host. + +So a sample Docker run command would be: + +```bash +$ docker run -it -d -e PROM2TEAMS_GROUP_ALERTS_BY=FIELD_YOU_WANT_TO_GROUP_BY -e PROM2TEAMS_CONNECTOR="CONNECTOR_URL" -p 8089:8089 idealista/prom2teams:VERSION +``` + +#### Provide custom config file + +If you prefer to use your own config file, you just need to provide it as a Docker volume to the container and map it to `/opt/prom2teams/config.ini`. Sample: + +```bash +$ docker run -it -d -v pathToTheLocalConfigFile:/opt/prom2teams/config.ini -p 8089:8089 idealista/prom2teams:VERSION +``` ### Helm chart @@ -116,30 +137,6 @@ The following table lists the configurable parameters of the Prom2teams chart an | `prom2teams.templatepath` | Custom Template path (files/teams.j2) | `/opt/prom2teams/helmconfig/teams.j2` | `prom2teams.config` | Config (specific to Helm) | `/opt/prom2teams/helmconfig/config.ini` -### Docker image - -Every new Prom2teams release, a new Docker image is built in our [Dockerhub](https://hub.docker.com/r/idealista/prom2teams). We strongly recommend you to use the images with the version tag, though it will be possible to use them without it. - -There are two things you need to bear in mind when creating a Prom2teams container: - -- The connector URL must be passed as the environment variable `PROM2TEAMS_CONNECTOR` -- In case you want to group alerts, you need to pass the field as the environment variable `PROM2TEAMS_GROUP_ALERTS_BY` -- You need to map container's Prom2teams port to one on your host. - -So a sample Docker run command would be: - -```bash -$ docker run -it -d -e PROM2TEAMS_GROUP_ALERTS_BY=FIELD_YOU_WANT_TO_GROUP_BY -e PROM2TEAMS_CONNECTOR="CONNECTOR_URL" -p 8089:8089 idealista/prom2teams:VERSION -``` - -#### Provide custom config file - -If you prefer to use your own config file, you just need to provide it as a Docker volume to the container and map it to `/opt/prom2teams/config.ini`. Sample: - -```bash -$ docker run -it -d -v pathToTheLocalConfigFile:/opt/prom2teams/config.ini -p 8089:8089 idealista/prom2teams:VERSION -``` - ### Production For production environments you should prefer using a WSGI server. [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) @@ -223,6 +220,13 @@ The url is formed by the host and port defined in the previous step. url: 0.0.0.0:8089/v2/ ``` +### Prom2teams Prometheus metrics + +Prom2teams uses Flask and, to have the service monitored, we use @rycus66's [Prometheus Flask Exporter](https://github.com/rycus86/prometheus_flask_exporter). This will enable an endpoint in `/metrics` where you could find interesting metrics to monitor such as number of responses with a certain status. To enable this endpoint, just either: + +- Use the `--enablemetrics` or `-m` flag when launching prom2teams. +- Set the environment variable `PROM2TEAMS_PROMETHEUS_METRICS=true`. + ### Templating prom2teams provides a [default template](prom2teams/resources/templates/teams.j2) built with [Jinja2](http://jinja.pocoo.org/docs/2.10/) to render messages in Microsoft Teams. This template could be overrided using the 'templatepath' argument ('--templatepath ') during the application start. @@ -232,7 +236,8 @@ If such a field is not included a default value of 'unknown' is assigned. All non-mandatory labels not in excluded list are injected in `extra_labels` key. All non-mandatory annotations not in excluded list are injected in `extra_annotations` key. -#### Swagger UI +## Documentation +### Swagger UI Accessing to `:` (e.g. `localhost:8089`) in a web browser shows the API v1 documentation. From e87fc502416b16b5edade42eec0793fa4527b8c3 Mon Sep 17 00:00:00 2001 From: Daniel Ortega Date: Mon, 13 Apr 2020 19:29:20 +0200 Subject: [PATCH 10/14] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3af0a..6694f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +## Changed - *[#175](https://github.com/idealista/prom2teams/issues/175) Building docker image using multi-stage build feature* @dortegau ## Fixed From c520f3581dae23da1dd2624685c6829d6804d4be Mon Sep 17 00:00:00 2001 From: Fran Tsao Date: Wed, 29 Apr 2020 13:08:25 +0200 Subject: [PATCH 11/14] #182 fix dependances versions and Dockerfile --- CHANGELOG.md | 1 + Dockerfile | 6 +++--- requirements.txt | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edac0b6..c3879e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch ## Fixed - *[#158](https://github.com/idealista/prom2teams/issues/158) Fixing Travis Badge (pointing to master branch) and reordering TOC* @dortegau - *[#177](https://github.com/idealista/prom2teams/issues/177) Fixing unit tests when using Python <= 3.6* @dortegau +- *[#182](https://github.com/idealista/prom2teams/issues/182) Fix dependencies versions; yaml-dev in docker container* @ftsao ## [2.5.4](https://github.com/idealista/prom2teams/tree/2.5.4) [Full Changelog](https://github.com/idealista/prom2teams/compare/2.5.3...2.5.4) diff --git a/Dockerfile b/Dockerfile index 65936a5..8bd5d5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ COPY LICENSE \ ./ COPY prom2teams/ prom2teams COPY bin/ bin -RUN apk add gcc libc-dev linux-headers --no-cache \ +RUN apk add gcc libc-dev yaml-dev linux-headers --no-cache \ && python setup.py bdist_wheel FROM python:3.5-alpine @@ -17,8 +17,8 @@ EXPOSE 8089 WORKDIR /opt/prom2teams COPY docker/rootfs . COPY --from=builder /prom2teams/dist . -RUN apk add gcc libc-dev linux-headers --no-cache \ - && pip install prom2teams*.whl +RUN apk add gcc libc-dev yaml-dev linux-headers --no-cache \ + && pip install prom2teams*.whl ENV PROM2TEAMS_PORT="8089" \ PROM2TEAMS_HOST="0.0.0.0" \ PROM2TEAMS_LOGLEVEL="INFO" \ diff --git a/requirements.txt b/requirements.txt index afabfb1..804eb89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,7 @@ pyyaml==5.1 uwsgi==2.0.16 prometheus_flask_exporter==0.9.0 werkzeug==0.16.1 -DeepDiff==4.3.0 \ No newline at end of file +DeepDiff==4.3.0 +zipp==1.2.0 +MarkupSafe==1.1.1 +pyrsistent==0.16.0 From 591ca9c22cdcd1aca2d6397c70139ba625b7bd52 Mon Sep 17 00:00:00 2001 From: Fran Tsao Date: Wed, 29 Apr 2020 13:13:13 +0200 Subject: [PATCH 12/14] #182 updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3879e4..f194e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch ## Fixed - *[#158](https://github.com/idealista/prom2teams/issues/158) Fixing Travis Badge (pointing to master branch) and reordering TOC* @dortegau - *[#177](https://github.com/idealista/prom2teams/issues/177) Fixing unit tests when using Python <= 3.6* @dortegau -- *[#182](https://github.com/idealista/prom2teams/issues/182) Fix dependencies versions; yaml-dev in docker container* @ftsao +- *[#182](https://github.com/idealista/prom2teams/issues/182) Fix dependances versions; yaml-dev in docker container; updated pyyaml package* @ftsao ## [2.5.4](https://github.com/idealista/prom2teams/tree/2.5.4) [Full Changelog](https://github.com/idealista/prom2teams/compare/2.5.3...2.5.4) From 013516b52fd2a12745ff28465af4a764fe7064a7 Mon Sep 17 00:00:00 2001 From: Fran Tsao Date: Wed, 29 Apr 2020 13:34:42 +0200 Subject: [PATCH 13/14] Updated changelog for release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f194e1f..c948e99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) + +## [2.5.5](https://github.com/idealista/prom2teams/tree/2.5.5) ## Changed - *[#175](https://github.com/idealista/prom2teams/issues/175) Building docker image using multi-stage build feature* @dortegau From 73c9d091e15f37bbd5d17f6a24b402ed3831fd00 Mon Sep 17 00:00:00 2001 From: Fran Tsao Date: Wed, 29 Apr 2020 13:50:47 +0200 Subject: [PATCH 14/14] Updated setup.py for release; fix changelog --- CHANGELOG.md | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c948e99..49ad8e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) ## [2.5.5](https://github.com/idealista/prom2teams/tree/2.5.5) +[Full Changelog](https://github.com/idealista/prom2teams/compare/2.5.4...2.5.5) ## Changed - *[#175](https://github.com/idealista/prom2teams/issues/175) Building docker image using multi-stage build feature* @dortegau diff --git a/setup.py b/setup.py index bd42ca5..e379f3b 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup(name='prom2teams', - version='2.5.4', + version='2.5.5', description='Project that redirects Prometheus Alert Manager ' 'notifications to Microsoft Teams', long_description=readme,