def test_process(processor_client): now = time.time() metrics = [ snap.Metric( namespace=[ snap.NamespaceElement(value="org"), snap.NamespaceElement(value="metric"), snap.NamespaceElement(value="foo") ], version=1, unit="some unit", description="some description", timestamp=now, ) ] config = snap.ConfigMap(foo="bar") reply = processor_client.Process( _ProcessArg(metrics=metrics, config=config).pb) assert reply.error == "" assert len(reply.metrics) == 1 for m in reply.metrics: assert "processed" in m.Tags assert m.Tags["processed"] == "true" assert "foo" in m.Tags assert m.Tags["foo"] == "bar"
def test_update_catalog(): dia = DiamondCollector("diamond", 1) # When the diamond pypi package is installed the collectors are placed # in the share dir. cfg = snap.ConfigMap( config='''{"collectors":{"CPUCollector": {}}}''', collectors_path=os.path.dirname(os.path.dirname(sys.executable)) + "/share/diamond/collectors") metrics = dia.update_catalog(cfg) assert len(metrics) > 5
def test_collect(): dia = DiamondCollector("diamond", 1) cfg = snap.ConfigMap( config='''{"collectors":{"CPUCollector": {}}}''', collectors_path=os.path.dirname(os.path.dirname(sys.executable)) + "/share/diamond/collectors") metrics_to_collect = dia.update_catalog(cfg) metrics_collected = dia.collect(metrics_to_collect) assert len(metrics_collected) == len(metrics_to_collect) assert metrics_collected[0].data is not None # time collected is less than now assert metrics_collected[0].timestamp < time.time() # it took less than a second to collect the metrics assert metrics_collected[0].timestamp > time.time() - 1
def test_publish(publisher_client): now = time.time() metrics = [ snap.Metric( namespace=[ snap.NamespaceElement(value="org"), snap.NamespaceElement(value="metric"), snap.NamespaceElement(value="foo") ], version=1, unit="some unit", description="some description", timestamp=now, ) ] config = snap.ConfigMap(foo="bar", port=911, debug=True, availability=99.9) reply = publisher_client.Publish( _PublishArg(metrics=metrics, config=config).pb) assert reply.error == ""