def test_http_tls_stats(): # config to get bad tls with Agent.run(f""" monitors: - type: http urls: - {URL_HTTPS_SELFSIGNED} - {URL_HTTPS_EXPIRED} """) as agent: # url should has a bad certificate check_values(agent.fake_services.datapoints, 200, cert=0) for dp in agent.fake_services.datapoints: assert has_all_dims( dp, {"original_url": URL_HTTPS_SELFSIGNED}) or has_all_dims( dp, {"original_url": URL_HTTPS_EXPIRED})
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", }, )) 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" })) 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")
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))