oauth-2.0 在哪里检查Airflow中webserver_config.py的日志?

u59ebvdq  于 2022-10-31  发布在  其他
关注(0)|答案(1)|浏览(201)
import os
  import logging
  from flask.appbuilder.security.manager import AUTH_OAUTH
  from airflow.www.security import AirflowSecurityManager

  AUTH_TYPE = AUTH_OAUTH
  AUTH_ROLES_SYNC_AT_LOGIN = True
  AUTH_USER_REGISTRATION = True

  log = logging.getLogger(__name__)
  log.setLevel(os.getenv("AIRFLOW__LOGGING__FAB_LOGGING_LEVEL", "INFO"))

  OAUTH_PROVIDERS = [
      {
          "name": "egast",
          "icon": "fa-address-card",
          "token_key": "access_token",
          "remote_app": {
              "client_id": "<id>",
              "client_secret": "<secret>",
              "client_kwargs": {
                  "scope": "<scope>",
                  "grant_type": "authorization_code",
              },
              "access_token_method": "POST",
              "access_token_params": {
                  "client_id": "<id>",
              },
              "request_token_url": None,
              "api_base_url": "<url>",
              "access_token_url": "<url>/token.oauth2",
              "authorize_url": "<url>/authorization.oauth2"
          }
      }
  ]

  class CustomSecurityManager(AirflowSecurityManager):

      def oauth_user_info(sm, provider, response=None):
          if provider == "egast":
              me = sm.oauth_remote[provider].get("userinfo")
              log.debug(me.data)
              logging.info(me.data)
              logging.debug(me.data)
              print(me.data)
          else:
              log.debug("Nothing!!")
              logging.info("Nothing!!")
              logging.debug("Nothing!!")
              print("Nothing!!")

  SECURITY_MANAGER_CLASS = CustomSecurityManager
  AUTH_ROLES_MAPPING = {
      "FAB_USERS": ['User'],
      "FAB_ADMINS": ['Admin']
  }

我尝试在Airflow中集成oauth,我有一个类CustomSecurityManager,我在其中打印或记录一些语句以进行调试。在/home/airflow/airflow/下生成了几个日志文件,如airflow.cfg、webserver.log、webserver.out、scheduler.log等。但它们都不包含这些webserver_config.py日志。因此,启动Airflow Web服务器和调度程序后,我可以在哪里找到这些日志?

fkaflof6

fkaflof61#

能否添加以下内容:

import logging
  from airflow.utils.log.logging_mixin import RedirectStdHandler

  logger = logging.getLogger(__name__)
  handler = RedirectStdHandler(stream='stdout')
  logger.addHandler(handler)
  logger.info("hello-world")

与其他日志语句相比,日志格式是关闭的,但我现在得到了以下内容:

____________       _____________
 ____    |__( )_________  __/__  /________      __
____  /| |_  /__  ___/_  /_ __  /_  __ \_ | /| / /
___  ___ |  / _  /   _  __/ _  / / /_/ /_ |/ |/ /
 _/_/  |_/_/  /_/    /_/    /_/  \____/____/|__/
[2022-08-17 12:40:22,554] {webserver_config.py:16} INFO - hello-world

缺省情况下,Web服务器的日志被写入stdout,因此在kubernetes中,可以通过kubectl logs命令获取这些日志
(我使用的是Kubernetes executor设置,但我不希望这有什么影响,只需转到设置中stdout所在的位置即可)

相关问题