【问题标题】:How to structure container logs in Vertex AI?如何在 Vertex AI 中构建容器日志?
【发布时间】:2021-10-23 19:26:23
【问题描述】:

我在 Vertex AI 中有一个模型,从日志看来 Vertex AI 已将日志摄取到 jsonPayload 字段中的 message 字段中,但我想构造 jsonPayload 字段,以便每个键message 将是jsonPayload 中的一个字段,即:展平/提取message

【问题讨论】:

标签: google-ai-platform google-cloud-vertex-ai


【解决方案1】:

Stackdriver 中的日志遵循定义的 LogEntry 架构。 Cloud Logging 使用 structured logs,其中日志条目使用 jsonPayload 字段向其负载添加结构。

对于 Vertex AI,参数在我们在日志中看到的消息字段中传递。这些日志结构是预定义的。但是,如果您想提取消息块中存在的字段,您可以参考下面提到的解决方法:

1.创建接收器:

  • 您可以将日志导出到 Cloud Storage 存储桶、Bigquery、Pub/Sub 等。
  • 如果您使用 Bigquery 作为接收器,那么在 Bigquery 中您可以使用 JSON functions 来提取所需的数据。

2。下载日志并编写您的自定义代码:

  • 您可以下载日志文件,然后编写自定义逻辑以根据您的要求提取数据。
  • 可以参考client library(python)编写自定义逻辑和pythonJSON functions.

【讨论】:

    【解决方案2】:

    使用gcloud logging client 将结构日志写入 Vertex AI 端点:

    (确保您有一个有权将日志写入 gcloud 的服务帐户,并且,对于干净的日志,请确保您没有将任何其他日志流式传输到 stderr 或 stdout)

    import json
    import logging
    from logging import Handler, LogRecord
    import google.cloud.logging_v2 as logging_v2
    from google.api_core.client_options import ClientOptions
    from google.oauth2 import service_account
    
    data_to_write_to_endpoint = {key1: value1, ...}
    
    #Json key for a Service account permitted to write logs into the gcp 
    # project where your endpoint is
    credentials = service_account.Credentials.from_service_account_info(
                json.loads(SERVICE_ACOUNT_KEY_JSON)
            )
    client = logging_v2.client.Client(
                credentials=credentials, client_options=ClientOptions(api_endpoint="logging.googleapis.com",),
            )
    # This represent your Vertex AI endpoint
    resource = logging_v2.Resource(
                type="aiplatform.googleapis.com/Endpoint",
                labels={"endpoint_id": YOUR_ENDPOINT_ID, "location": ENDPOINT_REGION},
            )
    logger = client.logger("LOGGER NAME")
    logger.log_struct(
            info=data_to_write_to_endpoint,
            severity=severity,
            resource=resource,
        )
    

    【讨论】:

      猜你喜欢
      • 2021-11-08
      • 2021-08-07
      • 2023-02-18
      • 2022-10-06
      • 2022-01-17
      • 2021-09-28
      • 2021-12-24
      • 2021-12-24
      • 2022-10-06
      相关资源
      最近更新 更多