diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea24f3..909e89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.10.0 (2023-7-19) + +* Added `AmazonEventBridgeNotification` for Amazon EventBridge integration within detectors. +* Added combinators `EQ` (Equal) and `NE` (Not Equal). + ## 2.9.3 (2020-3-18) * Added `Alerts` in `signal_analog.flow` module to allow linking Detectors to Charts. diff --git a/requirements_dev.txt b/requirements_dev.txt index d94e3bc..9f970f7 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -5,8 +5,7 @@ click coverage email_validator enum34 -# https://github.com/PyCQA/pycodestyle/issues/728 --e git+https://gitlab.com/pycqa/flake8@9631dac5#egg=flake8 +flake8 hypothesis mock pytest diff --git a/setup.cfg b/setup.cfg index 869f064..cddec03 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [bumpversion] -current_version = 2.9.3 +current_version = 2.10.0 commit = True -tag = True +tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\.(?P[a-z]+)(?P\d+))? serialize = {major}.{minor}.{patch}.{release}{build} @@ -34,4 +34,3 @@ test = pytest [tool:pytest] addopts = -n auto - diff --git a/setup.py b/setup.py index 5a23682..2307d8a 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ setup( name='signal_analog', - version='2.9.3', + version='2.10.0', description='A troposphere-like library for managing SignalFx' + 'Charts, Dashboards, and Detectors.', long_description=readme + '\n\n' + history, diff --git a/signal_analog/__init__.py b/signal_analog/__init__.py index 25b27f5..9f73602 100644 --- a/signal_analog/__init__.py +++ b/signal_analog/__init__.py @@ -9,7 +9,7 @@ __author__ = """Fernando Freire""" __email__ = 'Lst-nike.plus.platform.sharedinfrastructure@nike.com' -__version__ = '2.9.3' +__version__ = '2.10.0' logging_config = pkg_resources.resource_string( __name__, 'logging.yaml').decode('utf-8') diff --git a/signal_analog/combinators.py b/signal_analog/combinators.py index 68a565e..2688c10 100644 --- a/signal_analog/combinators.py +++ b/signal_analog/combinators.py @@ -99,6 +99,22 @@ def __init__(self, left, right): super(GTE, self).__init__('>=', left, right) +class EQ(NAryCombinator): + """Equal combinator for comparing SignalFlow objects. + """ + + def __init__(self, left, right): + super(EQ, self).__init__('==', left, right) + + +class NE(NAryCombinator): + """Not Equal combinator for comparing SignalFlow objects. + """ + + def __init__(self, left, right): + super(NE, self).__init__('!=', left, right) + + class Mul(NAryCombinator): """Multiplication combinator for performing math on SignalFlow objects. """ diff --git a/signal_analog/detectors.py b/signal_analog/detectors.py index 0375c78..4d78db3 100644 --- a/signal_analog/detectors.py +++ b/signal_analog/detectors.py @@ -180,6 +180,27 @@ def __init__(self, vo_id, routing_key): } +class AmazonEventBridgeNotification(Notification): + """An Amazon EventBridge notification for detector rules.""" + + def __init__(self, aeb_id): + """Initializes a new Amazon EventBridge notification. + + This does not set up a Amazon EventBridge integration for you, one must already + exist before using this notification type. No validation is done to + ensure that a Amazon EventBridge integration id is valid. + + Arguments: + aeb_id: the Amazon EventBridge integration id to use + """ + util.assert_valid(aeb_id) + + self.options = { + 'type': 'AmazonEventBridge', + 'credentialId': aeb_id + } + + class WebhookNotification(Notification): """A Webhook notification for detector rules.""" diff --git a/tests/generators.py b/tests/generators.py index 9b30096..b7647a6 100644 --- a/tests/generators.py +++ b/tests/generators.py @@ -11,13 +11,14 @@ def ascii(): return text( characters(min_codepoint=1, max_codepoint=128, blacklist_categories=['Cc', 'Cs']), - min_size=1) + min_size=1, max_size=5) def flows(): return recursive( filters() | datas() | consts() | graphites() | newrelics(), - lambda children: whens() | detects()) + lambda children: whens() | detects(), + max_leaves=5) @composite diff --git a/tests/test_signal_analog_combinators.py b/tests/test_signal_analog_combinators.py index d9d0f93..55452c3 100644 --- a/tests/test_signal_analog_combinators.py +++ b/tests/test_signal_analog_combinators.py @@ -82,6 +82,18 @@ def test_binary_combinator_gte(f, ff): assert str(comb.GTE(f, ff)) == "{0} >= {1}".format(str(f), str(ff)) +@given(flows(), flows()) +def test_binary_combinator_eq(f, ff): + """EQ combinator should always intersperse '==' in the elements.""" + assert str(comb.EQ(f, ff)) == "{0} == {1}".format(str(f), str(ff)) + + +@given(flows(), flows()) +def test_binary_combinator_ne(f, ff): + """NE combinator should always intersperse '!=' in the elements.""" + assert str(comb.NE(f, ff)) == "{0} != {1}".format(str(f), str(ff)) + + @given(flows()) def test_combinator_not(expr): """Not combinator should always prefix 'not' to its expression.""" diff --git a/tests/test_signal_analog_detectors.py b/tests/test_signal_analog_detectors.py index 09b12ff..42f540b 100644 --- a/tests/test_signal_analog_detectors.py +++ b/tests/test_signal_analog_detectors.py @@ -14,6 +14,7 @@ SlackNotification, HipChatNotification, \ ServiceNowNotification, \ VictorOpsNotification, \ + AmazonEventBridgeNotification, \ WebhookNotification, TeamNotification, \ TeamEmailNotification, Rule, Severity, \ Time, TimeConfig, VisualizationOptions, \ @@ -114,6 +115,14 @@ def test_victorops_valid(): assert n.options['routingKey'] == routing +def test_amazoneventbridge_valid(): + aeb_id = 'foo' + n = AmazonEventBridgeNotification(aeb_id) + + assert n.options['type'] == 'AmazonEventBridge' + assert n.options['credentialId'] == aeb_id + + def test_webhook_valid(): url = 'foo.com' secret = 'foo'