Exemple #1
0
def test_config_from_annotations(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}",
            },
        ))
    with k8s_cluster.create_resources([nginx_with_annotations]):
        config = f"""
            observers:
             - type: k8s-api
            monitors: []
        """
        with k8s_cluster.run_agent(config) as agent:
            assert wait_for(
                p(has_datapoint,
                  agent.fake_services,
                  dimensions={
                      "plugin": "nginx",
                      "source": "myapp"
                  }))
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: mytestapp}",
                "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": "mytestapp"
                  }))
            for dp in agent.fake_services.datapoints:
                if not has_all_dims(dp, {"source": "mytestapp"}):
                    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))
def test_config_from_annotations(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",
                "agent.signalfx.com/config.80.datapointsToExclude":
                "[{metricName: nginx_connections.active}]",
            },
        ))
    with k8s_cluster.create_resources([nginx_with_annotations]):
        config = f"""
            observers:
             - type: k8s-api
            monitors: []
        """
        with k8s_cluster.run_agent(config) as agent:
            assert wait_for(
                p(has_datapoint,
                  agent.fake_services,
                  dimensions={
                      "plugin": "nginx",
                      "source": "myapp"
                  }))
            assert ensure_always(
                p(
                    has_no_datapoint,
                    agent.fake_services,
                    metric_name="nginx_connections.active",
                    dimensions={"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")