Пример #1
0
def test_config():
    arg_parser = get_arg_parser()
    core_add_args(arg_parser)
    arg_parser.parse_known_args()
    cfg = Config("test")
    cfg.add_config(ConfigTest)
    cfg.init_default_config()
    assert Config.dict() == {
        "configtest": {
            "testvar1": "testing123",
            "testvar2": 12345,
            "testvar3": {
                "mydict": {
                    "foo": "bar",
                    "abc": {
                        "def": "ghi"
                    }
                },
                "myint": 0,
                "mystr": "Hello",
            },
        }
    }
    cfg2 = Config("test2")
    assert cfg.configtest.testvar1 == cfg2.configtest.testvar1
    assert cfg.configtest.testvar1 == Config.configtest.testvar1
    assert cfg.configtest.testvar2 == cfg2.configtest.testvar2
    assert cfg.configtest.testvar3 == cfg2.configtest.testvar3
    Config.configtest.testvar2 += 1
    assert cfg.configtest.testvar2 == 12346
    with pytest.raises(ConfigNotFoundError):
        Config.does_not_exist.foo = "bar"
    with pytest.raises(ConfigNotFoundError):
        cfg.does_not_exist.foo = "bar"
Пример #2
0
def test_config_override():
    arg_parser = get_arg_parser()
    core_add_args(arg_parser)
    arg_parser.parse_known_args()
    cfg = Config("test")
    cfg.add_config(ConfigTest)
    cfg.init_default_config()
    assert Config.dict() == {
        "configtest": {
            "testvar1": "testing123",
            "testvar2": 12346,
            "testvar3": {
                "mydict": {
                    "foo": "bar",
                    "abc": {
                        "def": "ghi"
                    }
                },
                "myint": 0,
                "mystr": "Hello",
            },
        }
    }
    ArgumentParser.args.config_override = [
        "configtest.testvar1=testing124",
        "configtest.testvar3.myint=1",
        "configtest.testvar3.mystr=World",
        "configtest.testvar3.mydict.foo=baz",
        "configtest.testvar3.mydict.abc.def=jkl",
    ]
    cfg.override_config(cfg.running_config)
    assert Config.dict() == {
        "configtest": {
            "testvar1": "testing124",
            "testvar2": 12346,
            "testvar3": {
                "mydict": {
                    "foo": "baz",
                    "abc": {
                        "def": "jkl"
                    }
                },
                "myint": 1,
                "mystr": "World",
            },
        }
    }
Пример #3
0
 def add_config(config: Config) -> None:
     config.add_config(CleanupAWSLoadbalancersConfig)
Пример #4
0
 def add_config(config: Config) -> None:
     config.add_config(VSphereConfig)
Пример #5
0
 def add_config(config: Config) -> None:
     config.add_config(ProtectorConfig)
Пример #6
0
 def add_config(config: Config) -> None:
     config.add_config(GithubConfig)
Пример #7
0
 def add_config(config: Config) -> None:
     config.add_config(TagValidatorConfig)
Пример #8
0
 def add_config(config: Config) -> None:
     """Called by resoto upon startup to populate the Config store"""
     config.add_config(GcpConfig)
Пример #9
0
 def add_config(config: Config) -> None:
     config.add_config(SlackConfig)
Пример #10
0
 def add_config(config: Config) -> None:
     config.add_config(DigitalOceanCollectorConfig)
Пример #11
0
 def add_config(config: Config) -> None:
     config.add_config(OneloginConfig)
Пример #12
0
 def add_config(config: Config) -> None:
     config.add_config(OnpremConfig)
Пример #13
0
def main() -> None:
    setup_logger("resotometrics")
    resotolib.proc.parent_pid = os.getpid()

    add_event_listener(EventType.SHUTDOWN, shutdown)
    arg_parser = ArgumentParser(description="resoto metrics exporter",
                                env_args_prefix="RESOTOMETRICS_")
    add_args(arg_parser)
    Config.add_args(arg_parser)
    resotocore_add_args(arg_parser)
    logging_add_args(arg_parser)
    jwt_add_args(arg_parser)
    TLSData.add_args(arg_parser)
    arg_parser.parse_args()

    try:
        wait_for_resotocore(resotocore.http_uri)
    except TimeoutError as e:
        log.fatal(f"Failed to connect to resotocore: {e}")
        sys.exit(1)

    tls_data = None
    if resotocore.is_secure:
        tls_data = TLSData(
            common_name=ArgumentParser.args.subscriber_id,
            resotocore_uri=resotocore.http_uri,
        )
        tls_data.start()
    config = Config(
        ArgumentParser.args.subscriber_id,
        resotocore_uri=resotocore.http_uri,
        tls_data=tls_data,
    )
    config.add_config(ResotoMetricsConfig)
    config.load_config()

    resotolib.proc.initializer()

    metrics = Metrics()
    graph_collector = GraphCollector(metrics)
    REGISTRY.register(graph_collector)

    resotocore_graph = Config.resotometrics.graph
    graph_uri = f"{resotocore.http_uri}/graph/{resotocore_graph}"
    search_uri = f"{graph_uri}/search/aggregate?section=reported"

    message_processor = partial(core_actions_processor, metrics, search_uri,
                                tls_data)
    core_actions = CoreActions(
        identifier=ArgumentParser.args.subscriber_id,
        resotocore_uri=resotocore.http_uri,
        resotocore_ws_uri=resotocore.ws_uri,
        actions={
            "generate_metrics": {
                "timeout": Config.resotometrics.timeout,
                "wait_for_completion": True,
            },
        },
        message_processor=message_processor,
        tls_data=tls_data,
    )
    web_server_args = {}
    if tls_data:
        web_server_args = {
            "ssl_cert": tls_data.cert_path,
            "ssl_key": tls_data.key_path,
        }
    web_server = WebServer(
        WebApp(mountpoint=Config.resotometrics.web_path),
        web_host=Config.resotometrics.web_host,
        web_port=Config.resotometrics.web_port,
        **web_server_args,
    )
    web_server.daemon = True
    web_server.start()
    core_actions.start()
    shutdown_event.wait()
    web_server.shutdown()
    core_actions.shutdown()
    resotolib.proc.kill_children(resotolib.proc.SIGTERM, ensure_death=True)
    log.info("Shutdown complete")
    sys.exit(0)
Пример #14
0
 def add_config(config: Config) -> None:
     config.add_config(CleanupAWSVPCsConfig)
Пример #15
0
 def add_config(config: Config) -> None:
     config.add_config(CleanupAWSAlarmsConfig)
Пример #16
0
def add_config(config: Config) -> None:
    config.add_config(ResotoWorkerConfig)
Пример #17
0
 def add_config(config: Config) -> None:
     config.add_config(CleanupUntaggedConfig)
Пример #18
0
 def add_config(config: Config) -> None:
     config.add_config(K8sConfig)
Пример #19
0
 def add_config(config: Config) -> None:
     config.add_config(CleanupExpiredConfig)