Exemplo n.º 1
0
def main(argv=None):
    # We import only inside the `main()` method to ensure we configure everything so that nothing from the global
    # context runs before we configure logging
    import logging
    import os
    import sys

    # Configure logging
    from bai_kafka_utils.logging import configure_logging

    logging_streams = {"stdout": sys.stdout, "stderr": sys.stderr}
    stream = logging_streams[os.environ.get("LOGGING_STREAM",
                                            "stderr").lower()]
    configure_logging(level=os.environ.get("LOGGING_LEVEL", "INFO").upper(),
                      stream=stream)

    # Start the app
    logger = logging.getLogger("metrics-pusher")

    logger.info("Starting app")

    from bai_metrics_pusher.args import get_input

    metrics_pusher_input = get_input(argv)
    logger.info("Input is %s", metrics_pusher_input)

    # Start the loop
    from bai_metrics_pusher.loop import start_loop

    start_loop(metrics_pusher_input)
Exemplo n.º 2
0
def test_get_input_with_kafka_no_custom_labels():
    expected_cfg = InputValue(
        backend="kafka",
        pod_name="pod-name",
        pod_namespace="pod-namespace",
        backend_args={
            "action_id": "123",
            "client_id": "456",
            "key": "value",
            "topic": "KAFKA_TOPIC",
            "bootstrap_servers": ["server1:9092", "server2:9092"],
            "labels": {},
        },
    )
    cfg = get_input(
        ALL_ARGS + " --backend kafka",
        environ={
            "BACKEND_ARG_ACTION_ID": "123",
            "BACKEND_ARG_CLIENT_ID": "456",
            "BACKEND_ARG_TOPIC": "KAFKA_TOPIC",
            "BACKEND_ARG_KEY": "value",
            "BACKEND_ARG_BOOTSTRAP_SERVERS": "server1:9092,server2:9092",
        },
    )
    assert cfg == expected_cfg
Exemplo n.º 3
0
def test_get_input_with_elasticsearch():
    expected_cfg = InputValue(
        backend="elasticsearch",
        pod_name="pod-name",
        pod_namespace="pod-namespace",
        backend_args={
            "action_id": "123",
            "client_id": "456",
            "hostname": "es-hostname",
            "port": 9200,
            "labels": {
                "test_label": "value"
            },
        },
    )
    cfg = get_input(
        ALL_ARGS + " --backend elasticsearch",
        environ={
            "BACKEND_ARG_ACTION_ID": "123",
            "BACKEND_ARG_CLIENT_ID": "456",
            "BACKEND_ARG_HOSTNAME": "es-hostname",
            "BACKEND_ARG_PORT": "9200",
            "CUSTOM_LABEL_TEST_LABEL": "value",
        },
    )
    assert cfg == expected_cfg
Exemplo n.º 4
0
def test_get_input_with_stdout():
    expected_cfg = InputValue(backend="stdout",
                              pod_name="pod-name",
                              pod_namespace="pod-namespace",
                              backend_args={"labels": {}})
    cfg = get_input(ALL_ARGS + " --backend stdout", environ={})
    assert cfg == expected_cfg