#NEWLINE# def Run( self ) : #NEWLINE# #INDENT# stats_collector = stats . StatsCollector ( ) #NEWLINE# stats_collector . RegisterCounterMetric ( 'sample_counter' , docstring = 'Sample counter metric.' ) #NEWLINE# stats_collector . RegisterGaugeMetric ( 'sample_gauge_value' , float , docstring = 'Sample gauge metric.' ) #NEWLINE# stats_collector . RegisterEventMetric ( 'sample_event' , docstring = 'Sample event metric.' ) #NEWLINE# with utils . Stubber ( stats , 'STATS' , stats_collector ) : #NEWLINE# #INDENT# for i in range ( 10 ) : #NEWLINE# #INDENT# with test_lib . FakeTime ( ( 42 + ( i * 60 ) ) ) : #NEWLINE# #INDENT# stats_collector . IncrementCounter ( 'sample_counter' ) #NEWLINE# stats_collector . SetGaugeValue ( 'sample_gauge_value' , ( i * 0.5 ) ) #NEWLINE# stats_collector . RecordEvent ( 'sample_event' , ( 0.42 + ( 0.5 * i ) ) ) #NEWLINE# with aff4 . FACTORY . Create ( None , 'StatsStore' , mode = 'w' , token = self . token ) as stats_store : #NEWLINE# #INDENT# stats_store . WriteStats ( process_id = 'worker_1' , sync = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . Check ( 'GET' , '/api/stats/store/WORKER/metrics/sample_counter?start=42000000&end=3600000000' ) #NEWLINE# self . Check ( 'GET' , '/api/stats/store/WORKER/metrics/sample_counter?start=42000000&end=3600000000&rate=1m' ) #NEWLINE# self . Check ( 'GET' , '/api/stats/store/WORKER/metrics/sample_gauge_value?start=42000000&end=3600000000' ) #NEWLINE# self . Check ( 'GET' , '/api/stats/store/WORKER/metrics/sample_event?start=42000000&end=3600000000' ) #NEWLINE# self . Check ( 'GET' , '/api/stats/store/WORKER/metrics/sample_event?start=42000000&end=3600000000&distribution_handling_mode=DH_COUNT' )