def write(sef, user, request_app, app): try: request_app.container.docker.force_pull_image = True logger.info("Forcing pull image of app {}".format(request_app.id)) except AttributeError as e: pass return request_app
def load_all_metrics_plugins( flask_application, get_plugin_logger_instance=get_plugin_logger_instance): all_metric_plugins = load_entrypoint_group( API_PLUGIN_TYPES.API_METRIC_PLUGIN.value) for entrypoint in all_metric_plugins: try: package_name = entrypoint.dist.project_name entrypoint_function = entrypoint.load() plugin_logger_instance = get_plugin_logger_instance( plugin_id=package_name) plugin_logger_instance.setLevel( getattr(logging, conf.LOGLEVEL, logging.INFO)) plugin_data = entrypoint_function(logger=plugin_logger_instance) url_prefix = f"/_cat/metrics/{package_name}" flask_application.register_blueprint(plugin_data['blueprint'], url_prefix=url_prefix) logger.info({ "msg": "Metrics plugin loaded", "plugin_entrypoint": entrypoint, "plugin_id": package_name, "mountpoint URI": url_prefix, }) except Exception as e: logger.error({ "msg": "Failed to load plugin", "plugin_entrypoint": entrypoint, "plugin_id": package_name, "traceback": traceback.format_exc(), "type": sys.exc_info()[0].__name__, })
def load_all_metrics_plugins( flask_application, get_plugin_logger_instance=get_plugin_logger_instance): all_metric_plugins = load_entrypoint_group( API_PLUGIN_TYPES.API_METRIC_PLUGIN.value) for entrypoint in all_metric_plugins: try: package_name = entrypoint.dist.project_name if package_name not in PLUGINS_LOAD_STATUS["plugins"]: PLUGINS_LOAD_STATUS["plugins"][package_name] = [] entrypoint_function = entrypoint.load() plugin_logger_instance = get_plugin_logger_instance( plugin_id=package_name) plugin_logger_instance.setLevel( getattr(logging, conf.LOGLEVEL, logging.INFO)) plugin_data = entrypoint_function(logger=plugin_logger_instance) url_prefix = f"/_cat/metrics/{package_name}" flask_application.register_blueprint(plugin_data["blueprint"], url_prefix=url_prefix) logger.info({ "msg": "Metrics plugin loaded", "plugin_entrypoint": entrypoint, "plugin_id": package_name, "mountpoint URI": url_prefix, }) PLUGINS_LOAD_STATUS["plugins"][package_name].append({ "status": "OK", "plugin_id": package_name, "entrypoint": { "module_name": entrypoint.module_name, "function_name": entrypoint.attrs[0], }, }) PLUGINS_LOAD_STATUS["stats"]["load_ok"] += 1 PLUGINS_LOAD_STATUS["stats"]["load_total"] += 1 except Exception as e: formatted_traceback = traceback.format_exc() exception_type = sys.exc_info()[0].__name__ logger.error({ "msg": "Failed to load plugin", "plugin_entrypoint": entrypoint, "plugin_id": package_name, "traceback": formatted_traceback, "type": exception_type, }) PLUGINS_LOAD_STATUS["plugins"][package_name].append({ "status": "FAIL", "exception": exception_type, "traceback": formatted_traceback, "plugin_id": package_name, "entrypoint": { "module_name": entrypoint.module_name, "function_name": entrypoint.attrs[0], }, }) PLUGINS_LOAD_STATUS["stats"]["load_failed"] += 1
def check_authentication_successful(access_token): headers = {'Authorization': "OAuth {}".format(access_token)} response = requests.get('https://www.googleapis.com/oauth2/v1/userinfo', headers=headers) if response.status_code != 200: logger.info({ "response": response.content, "status_code": response.status_code }) return None return response.json()
def check_jwt_token(jwt_token): try: payload = jwt.decode(jwt_token, key=SECRET_KEY) return _get_user_by_email(payload["user"]["email"]) except Exception as e: logger.info({ "auth": "failed", "token-type": "jwt", "error": str(e), "jwt_token": jwt_token }) return None
def check_auth_token(token): with managed(HollowmanSession) as s: user = _get_user_by_authkey(token) if not user: logger.info({ "auth": "failed", "token-type": "apikey", "error": "Key not found", "token": token }) return None return user
def after_request(response): logger.info( { "method": request.method, "status_code": response.status_code, "path": request.path, "user": (hasattr(request, "user") and request.user.tx_email) or None, "account_id": (hasattr(request, "user") and request.user.current_account.id) or None, "location": response.headers.get("Location"), "qstring": request.args, "error": _get_current_exception_if_exists(request) } ) return response
async def scale_all_apps(app: App): cloud_interface = AsgardInterface() state_checker = PeriodicStateChecker(cloud_interface) decision_maker = DecisionComponent() logger.info({"AUTOSCALER": "iniciando autoscaler"}) apps_stats = await state_checker.get_scalable_apps_stats() logger.info({"FETCH_APPS": [app.id for app in apps_stats]}) scaling_decisions = decision_maker.decide_scaling_actions(apps_stats) logger.info({"DECISIONS": DecisionConverter.all_to_dto(scaling_decisions)}) await cloud_interface.apply_decisions(scaling_decisions)