Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing of StatsD metrics with Py3
When running with Py3 we compare a byte string to a unicode string when parsing StatsD metrics. This patch adds some unit tests to reproduce the bug and decodes the bytestring to make the existing comparisons valid under Py3. When backporting to Train we can use Oslo encodeutils. Clearly we could have more unit tests, but this makes a start. Change-Id: I6341f96f5c186428d2d829cabf618a6f84f40ce2 Story: 2007684 Task: 39796 (cherry picked from commit a2400fc)
- Loading branch information
1 parent
7a7e5e6
commit 63e0c66
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import mock | ||
import unittest | ||
|
||
import monasca_agent.common.metrics as metrics_pkg | ||
import monasca_agent.statsd.udp as udp | ||
|
||
|
||
class TestStatsd(unittest.TestCase): | ||
def testSubmitPacket(self): | ||
mock_aggregator = mock.Mock() | ||
srv = udp.Server(mock_aggregator, 'localhost', 1234) | ||
test_packet = b"monasca.log.out_logs_truncated_bytes:0|g|#" \ | ||
b"{'service': 'monitoring', 'component': 'monasca-log-api'}" | ||
srv.submit_packets(test_packet) | ||
mock_aggregator.submit_metric.assert_called_once_with( | ||
'monasca.log.out_logs_truncated_bytes', | ||
0, | ||
metrics_pkg.Gauge, | ||
dimensions={ | ||
'service': 'monitoring', | ||
'component': 'monasca-log-api'}, | ||
sample_rate=1) | ||
|
||
def testSubmitPackets(self): | ||
mock_aggregator = mock.Mock() | ||
srv = udp.Server(mock_aggregator, 'localhost', 1234) | ||
test_packet = b"monasca.log.out_logs_truncated_bytes:0|g|#" \ | ||
b"{'service': 'monitoring', 'component': 'monasca-log-api'}\n" \ | ||
b"application_metric:10|c|#{'service': 'workload'}" | ||
srv.submit_packets(test_packet) | ||
mock_aggregator.submit_metric.assert_has_calls([ | ||
mock.call( | ||
'monasca.log.out_logs_truncated_bytes', | ||
0, | ||
metrics_pkg.Gauge, | ||
dimensions={ | ||
'service': 'monitoring', | ||
'component': 'monasca-log-api'}, | ||
sample_rate=1 | ||
), | ||
mock.call( | ||
'application_metric', | ||
10, | ||
metrics_pkg.Counter, | ||
dimensions={ | ||
'service': 'workload'}, | ||
sample_rate=1 | ||
) | ||
]) |