Add test for merging K8s annotation config with agent config
@@ -2,9 +2,9 @@ from functools import partial as p
import pytest
import yaml
-from tests.helpers.assertions import has_all_dims, has_datapoint, has_dim_key
+from tests.helpers.assertions import has_all_dims, has_datapoint, has_dim_key, has_no_datapoint
from tests.helpers.kubernetes.utils import add_pod_spec_annotations
-from tests.helpers.util import wait_for
+from tests.helpers.util import ensure_always, wait_for
from tests.paths import TEST_SERVICES_DIR
@@ -51,6 +51,41 @@ def test_config_from_annotations(k8s_cluster):
assert not has_dim_key(dp, "kubernetes_pod_uid")
+@pytest.mark.kubernetes
+def test_merges_config_from_annotations_and_agent_yaml(k8s_cluster):
+ nginx_yaml = TEST_SERVICES_DIR / "nginx/nginx-k8s.yaml"
+ nginx_with_annotations = yaml.dump_all(
+ add_pod_spec_annotations(
+ yaml.safe_load_all(nginx_yaml.read_bytes()),
+ {
+ "agent.signalfx.com/monitorType.http": "collectd/nginx",
+ "agent.signalfx.com/config.80.extraDimensions": "{source: myapp}",
+ "agent.signalfx.com/config.80.disableEndpointDimensions": "true",
+ },
+ )
+ )
+ with k8s_cluster.create_resources([nginx_with_annotations]):
+ config = f"""
+ observers:
+ - type: k8s-api
+ monitors:
+ - type: internal-metrics
+ - type: collectd/nginx
+ discoveryRule: 'kubernetes_namespace == "{k8s_cluster.test_namespace}" && port == 80 && container_spec_name == "nginx"'
+ datapointsToExclude:
+ - metricName: nginx_requests
+ """
+ with k8s_cluster.run_agent(config) as agent:
+ assert wait_for(p(has_datapoint, agent.fake_services, dimensions={"plugin": "nginx", "source": "myapp"}))
+ for dp in agent.fake_services.datapoints:
+ if not has_all_dims(dp, {"source": "myapp"}):
+ continue
+ assert not has_dim_key(dp, "kubernetes_pod_uid")
+ ensure_always(p(has_no_datapoint, agent.fake_services, metric_name="nginx_requests"), timeout_seconds=10)
+
+ wait_for(p(has_datapoint, agent.fake_services, metric_name="sfxagent.active_monitors", value=2))
+
+
@pytest.mark.kubernetes
def test_k8s_annotations_in_discovery(k8s_cluster):
nginx_yaml = TEST_SERVICES_DIR / "nginx/nginx-k8s.yaml"
