def test_counter_without_reference(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) self.assertTrue(r.counter("test")._writer.is_empty()) r.counter("test").increment() self.assertEqual("c:test:1", r.counter("test")._writer.last_line())
def test_empty_api_methods(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) t = PercentileDistributionSummary(r, "test") self.assertEqual(0, t.count()) self.assertEqual(0, t.total_amount()) self.assertEqual(0, t.percentile(1))
def test_close(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) c = r.counter("test") c.increment() self.assertEqual("c:test:1", c._writer.last_line()) r.close() self.assertTrue(c._writer.is_empty())
def test_pct_timer(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) t = r.pct_timer("test") self.assertTrue(t._writer.is_empty()) t.record(42) self.assertEqual("T:test:42", t._writer.last_line())
def test_record(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) t = PercentileDistributionSummary(r, "test") self.assertTrue(t._pct_distsummary._writer.is_empty()) t.record(42) self.assertEqual("D:test:42", t._pct_distsummary._writer.last_line())
def test_pct_distsummary(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) d = r.pct_distribution_summary("test") self.assertTrue(d._writer.is_empty()) d.record(42) self.assertEqual("D:test:42", d._writer.last_line())
def test_monotonic_counter(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) c = r.monotonic_counter("test") self.assertTrue(c._writer.is_empty()) c.set(42) self.assertEqual("C:test:42", c._writer.last_line())
def test_age_gauge(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) g = r.age_gauge("test") self.assertTrue(g._writer.is_empty()) g.set(0) self.assertEqual("A:test:0", g._writer.last_line())
def test_gauge_ttl_seconds(self): r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) g = r.gauge("test", ttl_seconds=120) self.assertTrue(g._writer.is_empty()) g.set(42) self.assertEqual("g,120:test:42", g._writer.last_line())
def test_valid_output_location(self): config = SidecarConfig() self.assertTrue(config._valid_output_location("none")) self.assertTrue(config._valid_output_location("memory")) self.assertTrue(config._valid_output_location("stdout")) self.assertTrue(config._valid_output_location("stderr")) self.assertTrue(config._valid_output_location("file://")) self.assertTrue(config._valid_output_location("udp://"))
def test_stopwatch(self): clock = ManualClock() r = Registry(clock=clock, config=SidecarConfig( {"sidecar.output-location": "memory"})) t = PercentileTimer(r, "test") with t.stopwatch(): clock.set_monotonic_time(42) self.assertEqual("T:test:42", t._pct_timer._writer.last_line())
def test_iterate(self): """Avoid breaking the API.""" r = Registry( config=SidecarConfig({"sidecar.output-location": "memory"})) for _ in r: self.fail("registry should be empty") r.counter("counter") r.timer("timer") for _ in r: self.fail("registry no longer holds references to MeterIds")
def __init__(self, clock: Clock = SystemClock(), config: SidecarConfig = SidecarConfig()) -> None: self._clock = clock self._common_tags = config.common_tags() self._writer = SidecarWriter.create(config.output_location())
def test_invalid_output_location(self): config = SidecarConfig() self.assertFalse(config._valid_output_location(None)) self.assertFalse(config._valid_output_location("foo"))
def test_override_output_location(self): self.setup_environment() config = SidecarConfig({"sidecar.output-location": "stdout"}) self.assertEqual(self.all_expected_tags(), config.common_tags()) self.assertEqual("stdout", config.output_location()) self.clear_environment()
def test_override_common_tags(self): self.setup_environment() config = SidecarConfig({"sidecar.common-tags": {"nf.app": "foo"}}) self.assertEqual({"nf.app": "foo"}, config.common_tags()) self.assertEqual(self.default_location, config.output_location()) self.clear_environment()
def test_default_sidecar_config(self): self.setup_environment() config = SidecarConfig() self.assertEqual(self.all_expected_tags(), config.common_tags()) self.assertEqual(self.default_location, config.output_location()) self.clear_environment()