apache_log_metrics.py: Fix "ip_addr" group match
A bug was introduced by switching to named regex match groups - the
ip_addr group was referenced as "ipaddr".
BUG=chromium:630776
TEST=added a unit test.
Change-Id: I6a51c2c18aeffc2fbda53446c5e5690ae53060cc
Reviewed-on: https://chromium-review.googlesource.com/362588
Reviewed-by: Richard Barnette <jrbarnette@google.com>
Tested-by: Paul Hobbs <phobbs@google.com>
diff --git a/apache_log_metrics.py b/apache_log_metrics.py
index 0d35d09..e94edd6 100755
--- a/apache_log_metrics.py
+++ b/apache_log_metrics.py
@@ -52,7 +52,7 @@
Args:
ip: An IPv4-formatted string.
"""
- return reduce(lambda (seed, x): seed * 2**8 + int(x),
+ return reduce(lambda seed, x: seed * 2**8 + int(x),
ip.split('.'),
0)
@@ -124,7 +124,7 @@
size, fields={
'build_config': build_config,
'milestone': milestone,
- 'in_lab': InLab(m.group('ipaddr')),
+ 'in_lab': InLab(m.group('ip_addr')),
'endpoint': filename})
diff --git a/apache_log_metrics_unittest.py b/apache_log_metrics_unittest.py
index 8e3f3df..ae73186 100755
--- a/apache_log_metrics_unittest.py
+++ b/apache_log_metrics_unittest.py
@@ -8,6 +8,7 @@
from __future__ import print_function
+import mock
import unittest
import apache_log_metrics
@@ -36,5 +37,17 @@
self.assertEqual(match.group('size'), '13805917')
+class TestEmitters(unittest.TestCase):
+ """Tests the emitter functions in apache_log_metrics."""
+
+ def testEmitStaticResponse(self):
+ match = apache_log_metrics.STATIC_GET_MATCHER.match(
+ STATIC_REQUEST_LINE)
+ # Calling the emitter should not raise any exceptions (for example, by
+ # referencing regex match groups that don't exist.
+ with mock.patch.object(apache_log_metrics, 'metrics'):
+ apache_log_metrics.EmitStaticRequestMetric(match)
+
+
if __name__ == '__main__':
unittest.main()