def test_basic_scoping(): lb = Label("ping", "pong") rm = RootMetrics() rm.register(lb) rm.scope("bing").register(lb) assert rm.sample() == {"ping": "pong", "bing.ping": "pong"} rm.clear()
def test_basic_registration_and_clear(): lb = Label("ping", "pong") rm = RootMetrics() rm.register(lb) assert rm.sample() == {"ping": "pong"} rm.clear() assert rm.sample() == {}
def test_basic_scoping(): lb = Label('ping', 'pong') rm = RootMetrics() rm.register(lb) rm.scope('bing').register(lb) assert rm.sample() == {'ping': 'pong', 'bing.ping': 'pong'} rm.clear()
def test_basic_registration_and_clear(): lb = Label('ping', 'pong') rm = RootMetrics() rm.register(lb) assert rm.sample() == {'ping': 'pong'} rm.clear() assert rm.sample() == {}
def test_basic_scoping(): lb = Label('ping', 'pong') rm = RootMetrics() rm.register(lb) rm.scope('bing').register(lb) assert rm.sample() == { 'ping': 'pong', 'bing.ping': 'pong' } rm.clear()
def test_nontrivial_gauges(): for label_value in ["a", 0, 2.5, [1, 2, "3"], {"a": "b"}, {"c": None}, False]: lb = Label("ping", label_value) rm = RootMetrics() rm.register(lb) assert rm.sample() == {"ping": label_value} rm.clear() assert rm.sample() == {}
def test_nontrivial_gauges(): for label_value in ['a', 0, 2.5, [1,2,"3"], {'a': 'b'}, {'c': None}, False]: lb = Label('ping', label_value) rm = RootMetrics() rm.register(lb) assert rm.sample() == {'ping': label_value} rm.clear() assert rm.sample() == {}
def register_build_properties(): if not HAS_PEX: return rm = RootMetrics().scope('build') try: build_properties = PEX().info.build_properties except PEX.NotFound: return for key, value in build_properties.items(): rm.register(Label(str(key), str(value)))
def test_nontrivial_gauges(): for label_value in [ 'a', 0, 2.5, [1, 2, "3"], { 'a': 'b' }, { 'c': None }, False ]: lb = Label('ping', label_value) rm = RootMetrics() rm.register(lb) assert rm.sample() == {'ping': label_value} rm.clear() assert rm.sample() == {}
def test_filtering_vars_filter_enabled_and_not_requested(self): rm = RootMetrics() zone = NamedGauge('alpha', "wont_be_visible") alpha = NamedGauge('zone', "smf1") rm.register(zone) rm.register(alpha) metrics = RootMetrics() vars_subsystem = VarsSubsystem() regex = vars_subsystem.compile_stats_filters(["alpha", "beta.*"]) endpoint = VarsEndpoint(period=Amount(60000, Time.MILLISECONDS), stats_filter=regex) metrics_returned = endpoint.handle_vars_json() assert "zone" in metrics_returned assert "alpha" in metrics_returned request.GET.replace('filtered', None)
def test_register_string(): rm = RootMetrics() hello_gauge = rm.register('hello') assert rm.sample() == {'hello': None} hello_gauge.write('poop') assert rm.sample() == {'hello': 'poop'} rm.clear()
def register_diagnostics(): import os, sys, time rm = RootMetrics().scope('sys') now = time.time() rm.register(LambdaGauge('uptime', lambda: time.time() - now)) rm.register(Label('argv', repr(sys.argv))) rm.register(Label('path', repr(sys.path))) rm.register(LambdaGauge('modules', lambda: ', '.join(sys.modules.keys()))) rm.register(Label('version', sys.version)) rm.register(Label('platform', sys.platform)) rm.register(Label('executable', sys.executable)) rm.register(Label('prefix', sys.prefix)) rm.register(Label('exec_prefix', sys.exec_prefix)) rm.register(Label('uname', ' '.join(os.uname())))