Skip to content

Commit

Permalink
Use version from report as output message version
Browse files Browse the repository at this point in the history
  • Loading branch information
epapbak committed May 28, 2024
1 parent 6f7df9e commit 19d04ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ccx_messaging/publishers/rule_processing_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class RuleProcessingPublisher(KafkaPublisher):
def __init__(self, outgoing_topic, kafka_broker_config=None, **kwargs):
"""Construct a new `RuleProcessingPublisher` given `kwargs` from the config YAML."""
super().__init__(outgoing_topic, kafka_broker_config, **kwargs)
self.outdata_schema_version = 2

def validate_timestamp_rfc3339(self, timestamp):
"""Check if the timestamp matches RFC3339 format."""
Expand Down Expand Up @@ -107,13 +106,14 @@ def publish(self, input_msg, report):

try:
msg_timestamp = input_msg["timestamp"]
msg_version = report.pop("version", 1)
output_msg = {
"OrgID": org_id,
"AccountNumber": account_number,
"ClusterName": input_msg["cluster_name"],
"Report": report,
"LastChecked": msg_timestamp,
"Version": self.outdata_schema_version,
"Version": msg_version,
"RequestId": input_msg.get("request_id"),
"Metadata": {"gathering_time": self.get_gathering_time(input_msg)},
}
Expand Down
34 changes: 25 additions & 9 deletions test/publishers/rule_processing_publisher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
Expand All @@ -174,7 +174,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
Expand All @@ -201,7 +201,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
Expand All @@ -227,7 +227,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
Expand All @@ -254,7 +254,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2023-08-14T09:31:46Z"},
},
Expand All @@ -281,7 +281,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2023-08-14T09:31:46Z"},
},
Expand All @@ -308,7 +308,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
Expand All @@ -335,7 +335,7 @@ def test_publish_bad_argument(wrong_input_msg):
"ClusterName": "uuid",
"Report": {"reports": []},
"LastChecked": "a timestamp",
"Version": 2,
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
Expand Down Expand Up @@ -402,7 +402,23 @@ def test_error(input, output):
"OrgID": 10,
"AccountNumber": 1,
"ClusterName": "uuid",
"Report": {"version": 1, "reports": [], "pass": [], "info": []},
"Report": {"reports": [], "pass": [], "info": []},
"LastChecked": "a timestamp",
"Version": 1,
"RequestId": "a request id",
"Metadata": {"gathering_time": "2012-01-14T00:00:00Z"},
},
id="valid_report",
),
pytest.param(
json.dumps(
{"version": 2, "reports": [], "pass": [], "info": [], "workload_recommendations": []}
),
{
"OrgID": 10,
"AccountNumber": 1,
"ClusterName": "uuid",
"Report": {"reports": [], "pass": [], "info": []},
"LastChecked": "a timestamp",
"Version": 2,
"RequestId": "a request id",
Expand Down

0 comments on commit 19d04ab

Please sign in to comment.