From 6d9ded9999a91d1666a6801ee8ff2b366f7bbdfd Mon Sep 17 00:00:00 2001 From: Michael Skarbek Date: Tue, 18 May 2021 10:26:20 -0400 Subject: [PATCH] sources: filter on application.create messages (#2889) * filter on app.create messages too --- koku/sources/kafka_message_processor.py | 9 +++++++-- koku/sources/test/test_kafka_listener.py | 2 +- koku/sources/test/test_kafka_message_processor.py | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/koku/sources/kafka_message_processor.py b/koku/sources/kafka_message_processor.py index 42f02f8756..4c3ec84810 100644 --- a/koku/sources/kafka_message_processor.py +++ b/koku/sources/kafka_message_processor.py @@ -102,10 +102,15 @@ def msg_for_cost_mgmt(self): """Filter messages not intended for cost management.""" if self.event_type in (KAFKA_APPLICATION_DESTROY, KAFKA_SOURCE_DESTROY): return True - if self.event_type in (KAFKA_AUTHENTICATION_CREATE, KAFKA_APPLICATION_UPDATE, KAFKA_AUTHENTICATION_UPDATE): + if self.event_type in ( + KAFKA_APPLICATION_CREATE, + KAFKA_AUTHENTICATION_CREATE, + KAFKA_APPLICATION_UPDATE, + KAFKA_AUTHENTICATION_UPDATE, + ): sources_network = self.get_sources_client() return sources_network.get_application_type_is_cost_management(self.cost_mgmt_id) - return True # TODO: I wonder if this should be false? + return False def get_sources_client(self): return SourcesHTTPClient(self.auth_header, self.source_id) diff --git a/koku/sources/test/test_kafka_listener.py b/koku/sources/test/test_kafka_listener.py index 6e0dccad79..52def6f0fd 100644 --- a/koku/sources/test/test_kafka_listener.py +++ b/koku/sources/test/test_kafka_listener.py @@ -336,7 +336,7 @@ def test_listen_for_messages_aws_create_update_delete(self): def test_message_not_associated_with_cost_mgmt(self): """Test that messages not associated with cost-mgmt are not processed.""" table = [ - {"processor": ApplicationMsgProcessor, "event": KAFKA_APPLICATION_CREATE, "called": True}, + {"processor": ApplicationMsgProcessor, "event": KAFKA_APPLICATION_CREATE}, {"processor": ApplicationMsgProcessor, "event": KAFKA_APPLICATION_UPDATE}, {"processor": ApplicationMsgProcessor, "event": KAFKA_APPLICATION_DESTROY, "called": True}, {"processor": AuthenticationMsgProcessor, "event": KAFKA_AUTHENTICATION_CREATE}, diff --git a/koku/sources/test/test_kafka_message_processor.py b/koku/sources/test/test_kafka_message_processor.py index 60f2ba44c6..9a3b5b7a2d 100644 --- a/koku/sources/test/test_kafka_message_processor.py +++ b/koku/sources/test/test_kafka_message_processor.py @@ -212,11 +212,14 @@ def test_create_msg_processor_missing_header(self): def test_msg_for_cost_mgmt(self): """Test msg_for_cost_mgmt true or false.""" table = [ + {"event-type": "Source.create", "expected": False}, {"event-type": KAFKA_APPLICATION_DESTROY, "expected": True}, {"event-type": KAFKA_SOURCE_DESTROY, "expected": True}, + {"event-type": KAFKA_APPLICATION_CREATE, "expected": True, "patch": True}, {"event-type": KAFKA_AUTHENTICATION_CREATE, "expected": True, "patch": True}, {"event-type": KAFKA_APPLICATION_UPDATE, "expected": True, "patch": True}, {"event-type": KAFKA_AUTHENTICATION_UPDATE, "expected": True, "patch": True}, + {"event-type": KAFKA_APPLICATION_CREATE, "expected": False, "patch": False}, {"event-type": KAFKA_AUTHENTICATION_CREATE, "expected": False, "patch": False}, {"event-type": KAFKA_APPLICATION_UPDATE, "expected": False, "patch": False}, {"event-type": KAFKA_AUTHENTICATION_UPDATE, "expected": False, "patch": False},