def test_cluster_prop_is_merged_into_existing(): with ensure_fake_backend() as fake_services: fake_services.dims["host"]["myhost"] = { "customProperties": { "os": "linux" }, "tags": ["important"] } with Agent.run( """ cluster: prod hostname: myhost writer: propertiesSendDelaySeconds: 1 """, fake_services=fake_services, # Make it ignore all platform metrics for CI environments extra_env={"SKIP_PLATFORM_HOST_DIMS": "yes"}, ): def assert_cluster_property(): dim = fake_services.dims["host"]["myhost"] assert dim["customProperties"] == { "os": "linux", "cluster": "prod" } assert dim["tags"] == ["important"] wait_for_assertion(assert_cluster_property)
def verify_expected_is_superset(agent, expected_metrics, timeout=util.DEFAULT_TIMEOUT): def test(): assert frozenset(agent.fake_services.datapoints_by_metric ) <= frozenset(expected_metrics) wait_for_assertion(test, timeout_seconds=timeout)
def test_installer_cluster(): with _run_tests("ubuntu1804", INIT_SYSTEMD, "MYTOKEN --cluster prod") as [backend, _]: def assert_cluster_property(): host = first_host_dimension(backend) assert host assert host in backend.dims["host"] dim = backend.dims["host"][host] assert dim["customProperties"] == {"cluster": "prod"} assert dim["tags"] in [None, []] wait_for_assertion(assert_cluster_property)
def test_node_metrics_and_props(k8s_cluster): config = """ monitors: - type: kubernetes-cluster extraMetrics: - kubernetes.node* """ with k8s_cluster.run_agent(agent_yaml=config) as agent: for node in k8s_cluster.client.CoreV1Api().list_node().items: for metric in [ "kubernetes.node_ready", "kubernetes.node_allocatable_cpu" ]: assert wait_for( p( has_datapoint, agent.fake_services, metric_name=metric, dimensions={ "kubernetes_node": node.metadata.name, "kubernetes_node_uid": node.metadata.uid }, ), timeout_seconds=100, ), f"timed out waiting for {metric} metric" expected_props = { k: v for k, v in node.metadata.labels.items() if len(v) > 0 } expected_props["kubernetes_node"] = node.metadata.name def has_props(node, props): assert { k.replace("/", "_").replace(".", "_"): v for k, v in props.items() }.items( ) <= agent.fake_services.dims["kubernetes_node_uid"].get( node.metadata.uid, {}).get("customProperties", {}).items() wait_for_assertion(p(has_props, node, expected_props)) assert wait_for( p( has_dim_prop, agent.fake_services, dim_name="kubernetes_node_uid", dim_value=node.metadata.uid, prop_name="node_creation_timestamp", ), timeout_seconds=100, )
def test_cluster_prop_sync_cluster_on_host_dim(): with Agent.run(""" cluster: prod hostname: myhost syncClusterOnHostDimension: true writer: propertiesSendDelaySeconds: 1 """) as agent: def assert_cluster_property(): assert "myhost" in agent.fake_services.dims["host"] dim = agent.fake_services.dims["host"]["myhost"] assert dim["customProperties"] == {"cluster": "prod"} assert dim["tags"] in [None, []] wait_for_assertion(assert_cluster_property)
def test_cluster_prop_is_added_to_host_dims(): with Agent.run( """ cluster: prod hostname: myhost writer: propertiesSendDelaySeconds: 1 """, # Make it ignore all platform metrics for CI environments extra_env={"SKIP_PLATFORM_HOST_DIMS": "yes"}, ) as agent: def assert_cluster_property(): assert "myhost" in agent.fake_services.dims["host"] dim = agent.fake_services.dims["host"]["myhost"] assert dim["customProperties"] == {"cluster": "prod"} assert dim["tags"] in [None, []] wait_for_assertion(assert_cluster_property)
def test_haproxy_enhanced_metrics_enables_filter_passthrough(): with run_service("haproxy", buildargs={"HAPROXY_VERSION": "1.9"}) as service_container: host = container_ip(service_container) assert wait_for(p(tcp_socket_open, host, 9000)), "haproxy not listening on port" with Agent.run( f""" monitors: - type: collectd/haproxy host: {host} port: 9000 enhancedMetrics: true """ ) as agent: target_metric = "gauge.tasks" assert target_metric in METADATA.nonincluded_metrics def test(): assert has_datapoint(agent.fake_services, metric_name=target_metric) wait_for_assertion(test)
def test_consul_enhanced(): with run_container("consul:1.4.4") as consul_cont: host = container_ip(consul_cont) assert wait_for(p(tcp_socket_open, host, 8500), 60), "consul service didn't start" with Agent.run(f""" monitors: - type: collectd/consul host: {host} port: 8500 enhancedMetrics: true """) as agent: target_metric = "gauge.consul.serf.events.consul:new-leader" assert target_metric in METADATA.nonincluded_metrics def test(): assert has_datapoint(agent.fake_services, metric_name=target_metric) wait_for_assertion(test)
def test_cluster_prop_platform_dim_get_priority(): with Agent.run( """ cluster: prod hostname: myhost writer: propertiesSendDelaySeconds: 1 """, extra_env={"MY_NODE_NAME": "testnode"}, ) as agent: def assert_cluster_property(): assert "testnode" in agent.fake_services.dims["kubernetes_node"] dim = agent.fake_services.dims["kubernetes_node"]["testnode"] assert dim["customProperties"] == {"cluster": "prod"} assert dim["tags"] in [None, []] # Ensure it doesn't get synced to host dim assert "myhost" not in agent.fake_services.dims["host"] wait_for_assertion(assert_cluster_property)