Esempio n. 1
0
def registry(minikube, worker_id, request):  # pylint: disable=redefined-outer-name
    def get_registry_logs():
        cont.reload()
        return cont.logs().decode("utf-8")

    cont = None
    port = None
    k8s_container = request.config.getoption("--k8s-container")
    if not k8s_container and worker_id in ("master", "gw0"):
        minikube.start_registry()
        port = minikube.registry_port
    print("\nWaiting for registry to be ready ...")
    assert wait_for(p(container_is_running, minikube.client, "registry"),
                    timeout_seconds=60,
                    interval_seconds=2
                    ), "timed out waiting for registry container to start!"
    cont = minikube.client.containers.get("registry")
    assert wait_for(
        lambda: has_log_message(get_registry_logs(),
                                message="listening on [::]:"),
        timeout_seconds=30,
        interval_seconds=2,
    ), "timed out waiting for registry to be ready!"
    if not port:
        match = re.search(r"listening on \[::\]:(\d+)", get_registry_logs())
        assert match, "failed to determine registry port!"
        port = int(match.group(1))
    return {"container": cont, "port": port}
Esempio n. 2
0
def test_elasticsearch_with_cluster_option():
    with run_service("elasticsearch/6.4.2",
                     environment={"cluster.name":
                                  "testCluster"}) as es_container:
        host = container_ip(es_container)
        assert wait_for(
            p(http_status,
              url=f"http://{host}:9200/_nodes/_local",
              status=[200]), 180), "service didn't start"
        config = dedent(f"""
            monitors:
            - type: collectd/elasticsearch
              host: {host}
              port: 9200
              username: elastic
              password: testing123
              cluster: testCluster1
            """)
        with run_agent(config) as [backend, get_output, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "elasticsearch")), "Didn't get elasticsearch datapoints"
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin_instance",
                  "testCluster1")
            ), "Cluster name not picked from read callback"
            # make sure all plugin_instance dimensions were overridden by the cluster option
            assert not wait_for(
                p(has_datapoint_with_dim, backend, "plugin_instance",
                  "testCluster"), 10
            ), "plugin_instance dimension not overridden by cluster option"
            assert not has_log_message(get_output().lower(),
                                       "error"), "error found in agent output!"
Esempio n. 3
0
def test_elasticsearch_with_additional_metrics():
    with run_service("elasticsearch/6.2.0",
                     environment={"cluster.name":
                                  "testCluster"}) as es_container:
        host = container_ip(es_container)
        assert wait_for(
            p(http_status,
              url=f"http://{host}:9200/_nodes/_local",
              status=[200]), 180), "service didn't start"
        config = dedent(f"""
            monitors:
            - type: collectd/elasticsearch
              host: {host}
              port: 9200
              username: elastic
              password: testing123
              additionalMetrics:
               - cluster.initializing-shards
               - thread_pool.threads
            """)
        with run_agent(config) as [backend, get_output, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "elasticsearch")), "Didn't get elasticsearch datapoints"
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "gauge.cluster.initializing-shards")
            ), "Didn't get gauge.cluster.initializing-shards metric"
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "gauge.thread_pool.threads")
            ), "Didn't get gauge.thread_pool.threads metric"
            assert not has_log_message(get_output().lower(),
                                       "error"), "error found in agent output!"
Esempio n. 4
0
def test_elasticsearch_with_threadpool():
    with run_service("elasticsearch/6.2.0",
                     environment={"cluster.name":
                                  "testCluster"}) as es_container:
        host = container_ip(es_container)
        assert wait_for(
            p(http_status,
              url=f"http://{host}:9200/_nodes/_local",
              status=[200]), 180), "service didn't start"
        config = dedent(f"""
            monitors:
            - type: collectd/elasticsearch
              host: {host}
              port: 9200
              username: elastic
              password: testing123
              threadPools:
               - bulk
               - index
               - search
            """)
        with run_agent(config) as [backend, get_output, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "elasticsearch")), "Didn't get elasticsearch datapoints"
            assert wait_for(
                p(has_datapoint_with_dim, backend, "thread_pool",
                  "bulk")), "Didn't get bulk thread pool metrics"
            assert not has_log_message(get_output().lower(),
                                       "error"), "error found in agent output!"
Esempio n. 5
0
def test_basic():
    """
    See if we get datapoints from a very standard set of monitors
    """
    with run_agent(BASIC_CONFIG) as [backend, get_output, _]:
        assert wait_for(
            lambda: backend.datapoints), "Didn't get any datapoints"
        assert has_log_message(get_output(), "info")
Esempio n. 6
0
def test_cpufreq():
    with run_agent(
        """
    monitors:
      - type: collectd/cpufreq
    """
    ) as [_, get_output, _]:
        time.sleep(10)
        assert not has_log_message(get_output().lower(), "error"), "error found in agent output!"
Esempio n. 7
0
def test_basic_service_discovery():
    with run_agent(CONFIG) as [backend, get_output, _]:
        with run_service("nginx", name="nginx-discovery"):
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "nginx")), "Didn't get nginx datapoints"
        # Let nginx be removed by docker observer and collectd restart
        time.sleep(5)
        backend.datapoints.clear()
        assert ensure_always(
            lambda: not has_datapoint_with_dim(backend, "plugin", "nginx"), 10)
        assert not has_log_message(get_output(), "error")
Esempio n. 8
0
def test_vmem():
    expected_metrics = get_monitor_metrics_from_selfdescribe("collectd/vmem")
    expected_dims = get_monitor_dims_from_selfdescribe("collectd/vmem")
    with run_agent(
        """
    monitors:
      - type: collectd/vmem
    """
    ) as [backend, get_output, _]:
        assert wait_for(
            p(has_any_metric_or_dim, backend, expected_metrics, expected_dims), timeout_seconds=60
        ), "timed out waiting for metrics and/or dimensions!"
        assert not has_log_message(get_output().lower(), "error"), "error found in agent output!"
Esempio n. 9
0
def test_solr_monitor():
    with run_service("solr") as solr_container:
        host = container_ip(solr_container)
        config = dedent(f"""
        monitors:
        - type: collectd/solr
          host: {host}
          port: 8983
        """)
        assert wait_for(p(tcp_socket_open, host, 8983),
                        60), "service not listening on port"
        with run_agent(config) as [backend, get_output, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "solr")), "Didn't get solr datapoints"
            assert ensure_always(lambda: has_datapoint_with_metric_name(
                backend, "counter.solr.http_5xx_responses"))
            assert not has_log_message(get_output().lower(),
                                       "error"), "error found in agent output!"
def test_signalfx_metadata():
    expected_metrics = get_monitor_metrics_from_selfdescribe(
        "collectd/signalfx-metadata")
    expected_dims = get_monitor_dims_from_selfdescribe(
        "collectd/signalfx-metadata")
    with run_agent("""
    monitors:
      - type: collectd/signalfx-metadata
        procFSPath: /proc
        etcPath: /etc
        persistencePath: /var/run/signalfx-agent
      - type: collectd/cpu
    """) as [backend, get_output, _]:
        assert wait_for(p(has_any_metric_or_dim, backend, expected_metrics,
                          expected_dims),
                        timeout_seconds=60
                        ), "timed out waiting for metrics and/or dimensions!"
        assert not has_log_message(get_output().lower(),
                                   "error"), "error found in agent output!"
Esempio n. 11
0
def test_processes():
    with open(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "metrics.txt"), "r") as fd:
        expected_metrics = {
            m.strip()
            for m in fd.readlines() if len(m.strip()) > 0
        }
    with run_agent("""
    monitors:
      - type: collectd/processes
        procFSPath: /proc
        collectContextSwitch: true
        processMatch:
          collectd: ".*collectd.*"
    """) as [backend, get_output, _]:
        assert wait_for(p(has_any_metric_or_dim, backend, expected_metrics,
                          None),
                        timeout_seconds=60
                        ), "timed out waiting for metrics and/or dimensions!"
        assert not has_log_message(get_output().lower(),
                                   "error"), "error found in agent output!"
Esempio n. 12
0
 def has_error():
     return has_log_message(
         get_output(),
         level="error",
         message="chrony plugin: chrony_query (REQ_TRACKING) failed")
Esempio n. 13
0
def test_validation_required_log_output():
    with run_agent(CONFIG) as [_, get_output, _]:
        assert wait_for(lambda: has_log_message(
            get_output(), "error", "Validation error in field 'port': required"
        )), "Didn't get validation error message"