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"
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", }, } }
def add_config(config: Config) -> None: config.add_config(CleanupAWSLoadbalancersConfig)
def add_config(config: Config) -> None: config.add_config(VSphereConfig)
def add_config(config: Config) -> None: config.add_config(ProtectorConfig)
def add_config(config: Config) -> None: config.add_config(GithubConfig)
def add_config(config: Config) -> None: config.add_config(TagValidatorConfig)
def add_config(config: Config) -> None: """Called by resoto upon startup to populate the Config store""" config.add_config(GcpConfig)
def add_config(config: Config) -> None: config.add_config(SlackConfig)
def add_config(config: Config) -> None: config.add_config(DigitalOceanCollectorConfig)
def add_config(config: Config) -> None: config.add_config(OneloginConfig)
def add_config(config: Config) -> None: config.add_config(OnpremConfig)
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)
def add_config(config: Config) -> None: config.add_config(CleanupAWSVPCsConfig)
def add_config(config: Config) -> None: config.add_config(CleanupAWSAlarmsConfig)
def add_config(config: Config) -> None: config.add_config(ResotoWorkerConfig)
def add_config(config: Config) -> None: config.add_config(CleanupUntaggedConfig)
def add_config(config: Config) -> None: config.add_config(K8sConfig)
def add_config(config: Config) -> None: config.add_config(CleanupExpiredConfig)