def test_registry_marshall_summary(self): format_times = 10 summary_data = (({ 's_sample': '1', 's_subsample': 'b' }, range(4000, 5000, 47)), ) registry = Registry() summary = Summary("summary_test", "A summary.", {'type': "summary"}) # Add data [summary.add(i[0], s) for i in summary_data for s in i[1]] registry.register(summary) valid_result = (b'\x99\x01\n\x0csummary_test\x12\nA summary.' b'\x18\x02"{\n\r\n\x08s_sample\x12\x011\n\x10\n' b'\x0bs_subsample\x12\x01b\n\x0f\n\x04type\x12\x07' b'summary"G\x08\x16\x11\x00\x00\x00\x00\x90"\xf8@' b'\x1a\x12\t\x00\x00\x00\x00\x00\x00\xe0?\x11\x00' b'\x00\x00\x00\x00\x8b\xb0@\x1a\x12\t\xcd\xcc\xcc' b'\xcc\xcc\xcc\xec?\x11\x00\x00\x00\x00\x00v\xb1@' b'\x1a\x12\t\xaeG\xe1z\x14\xae\xef?\x11\x00\x00\x00' b'\x00\x00\xa5\xb1@') f = BinaryFormatter() # Check multiple times to ensure multiple marshalling requests for i in range(format_times): self.assertEqual(valid_result, f.marshall(registry))
def test_registry_marshall_histogram(self): """ check encode of histogram matches expected output """ metric_name = "histogram_test" metric_help = "A histogram." metric_data = (( { "h_sample": "1", "h_subsample": "b" }, { 5.0: 3, 10.0: 2, 15.0: 1, "count": 6, "sum": 46.0 }, ), ) histogram_data = (({ "h_sample": "1", "h_subsample": "b" }, (4.5, 5.0, 4.0, 9.6, 9.0, 13.9)), ) POS_INF = float("inf") histogram = Histogram( metric_name, metric_help, const_labels={"type": "histogram"}, buckets=(5.0, 10.0, 15.0, POS_INF), ) for labels, values in histogram_data: for v in values: histogram.add(labels, v) registry = Registry() registry.register(histogram) valid_result = (b"\x97\x01\n\x0ehistogram_test\x12\x0cA histogram." b'\x18\x04"u\n\r\n\x08h_sample\x12\x011\n\x10\n' b"\x0bh_subsample\x12\x01b\n\x11\n\x04type\x12\t" b"histogram:?\x08\x06\x11\x00\x00\x00\x00\x00\x00G@" b"\x1a\x0b\x08\x03\x11\x00\x00\x00\x00\x00\x00\x14@" b"\x1a\x0b\x08\x05\x11\x00\x00\x00\x00\x00\x00$@\x1a" b"\x0b\x08\x06\x11\x00\x00\x00\x00\x00\x00.@\x1a\x0b" b"\x08\x06\x11\x00\x00\x00\x00\x00\x00\xf0\x7f") f = BinaryFormatter() self.assertEqual(valid_result, f.marshall(registry))
def test_registry_marshall_gauge(self): gauge_data = (({"g_sample": "1", "g_subsample": "b"}, 800), ) gauge = Gauge("gauge_test", "A gauge.", const_labels={"type": "gauge"}) for labels, value in gauge_data: gauge.set(labels, value) registry = Registry() registry.register(gauge) valid_result = (b'U\n\ngauge_test\x12\x08A gauge.\x18\x01";' b"\n\r\n\x08g_sample\x12\x011\n\x10\n\x0bg_subsample" b"\x12\x01b\n\r\n\x04type\x12\x05gauge\x12\t\t\x00" b"\x00\x00\x00\x00\x00\x89@") f = BinaryFormatter() self.assertEqual(valid_result, f.marshall(registry))
def test_registry_marshall_counter(self): counter_data = (({"c_sample": "1", "c_subsample": "b"}, 400), ) counter = Counter("counter_test", "A counter.", const_labels={"type": "counter"}) for labels, value in counter_data: counter.set(labels, value) registry = Registry() registry.register(counter) valid_result = (b'[\n\x0ccounter_test\x12\nA counter.\x18\x00"=\n\r' b"\n\x08c_sample\x12\x011\n\x10\n\x0bc_subsample\x12" b"\x01b\n\x0f\n\x04type\x12\x07counter\x1a\t\t\x00\x00" b"\x00\x00\x00\x00y@") f = BinaryFormatter() self.assertEqual(valid_result, f.marshall(registry))
def test_registry_marshall_summary(self): metric_name = "summary_test" metric_help = "A summary." # metric_data = ( # ({'s_sample': '1', 's_subsample': 'b'}, # {0.5: 4235.0, 0.9: 4470.0, 0.99: 4517.0, 'count': 22, 'sum': 98857.0}), # ) summary_data = (({ "s_sample": "1", "s_subsample": "b" }, range(4000, 5000, 47)), ) summary = Summary(metric_name, metric_help, const_labels={"type": "summary"}) for labels, values in summary_data: for v in values: summary.add(labels, v) registry = Registry() registry.register(summary) valid_result = (b"\x99\x01\n\x0csummary_test\x12\nA summary." b'\x18\x02"{\n\r\n\x08s_sample\x12\x011\n\x10\n' b"\x0bs_subsample\x12\x01b\n\x0f\n\x04type\x12\x07" b'summary"G\x08\x16\x11\x00\x00\x00\x00\x90"\xf8@' b"\x1a\x12\t\x00\x00\x00\x00\x00\x00\xe0?\x11\x00" b"\x00\x00\x00\x00\x8b\xb0@\x1a\x12\t\xcd\xcc\xcc" b"\xcc\xcc\xcc\xec?\x11\x00\x00\x00\x00\x00v\xb1@" b"\x1a\x12\t\xaeG\xe1z\x14\xae\xef?\x11\x00\x00\x00" b"\x00\x00\xa5\xb1@") f = BinaryFormatter() self.assertEqual(valid_result, f.marshall(registry))
def test_registry_marshall_gauge(self): format_times = 10 gauge_data = (({'g_sample': '1', 'g_subsample': 'b'}, 800), ) registry = Registry() gauge = Gauge("gauge_test", "A gauge.", {'type': "gauge"}) # Add data [gauge.set(g[0], g[1]) for g in gauge_data] registry.register(gauge) valid_result = (b'U\n\ngauge_test\x12\x08A gauge.\x18\x01";' b'\n\r\n\x08g_sample\x12\x011\n\x10\n\x0bg_subsample' b'\x12\x01b\n\r\n\x04type\x12\x05gauge\x12\t\t\x00' b'\x00\x00\x00\x00\x00\x89@') f = BinaryFormatter() # Check multiple times to ensure multiple marshalling requests for i in range(format_times): self.assertEqual(valid_result, f.marshall(registry))
def test_registry_marshall_counter(self): format_times = 10 counter_data = (({'c_sample': '1', 'c_subsample': 'b'}, 400), ) registry = Registry() counter = Counter("counter_test", "A counter.", {'type': "counter"}) # Add data [counter.set(c[0], c[1]) for c in counter_data] registry.register(counter) valid_result = (b'[\n\x0ccounter_test\x12\nA counter.\x18\x00"=\n\r' b'\n\x08c_sample\x12\x011\n\x10\n\x0bc_subsample\x12' b'\x01b\n\x0f\n\x04type\x12\x07counter\x1a\t\t\x00\x00' b'\x00\x00\x00\x00y@') f = BinaryFormatter() # Check multiple times to ensure multiple marshalling requests for i in range(format_times): self.assertEqual(valid_result, f.marshall(registry))