【问题标题】:Getting Info from GCP Data Catalog从 GCP 数据目录获取信息
【发布时间】:2022-05-11 20:05:37
【问题描述】:

我注意到,当您在 Google Cloud Platform 中查询数据目录时,它会检索表被查询次数的统计信息:

Queried (Past 30 days): 5332

这是非常有用的信息,我想知道它实际存储在哪里,是否可以为项目或数据集中的所有表检索它。

我浏览了数据目录教程并编写了一些 python 脚本,但这些只是检索表的条目名称和迭代器,这不是我想要的。

同样,我也无法在信息架构元数据中看到这些数据。

【问题讨论】:

  • 您能否详细说明您在 Data Catalog 上的何处查看/获取该信息?
  • 在数据目录的BigQuery表详情页中可用

标签: google-cloud-platform


【解决方案1】:

您可以检索任何表/数据集exporting log entries to BiqQuery 的已完成/已执行查询的数量。每个查询都会在 Stackdriver 上生成一些日志记录,因此您可以使用 advanced filters 选择您感兴趣的日志并将它们作为新表存储在 Bigquery 中。

但是,the retention period for the data access logs in GCP is 30 days,所以只能导出过去 30 天的日志。

例如,使用以下高级过滤器来获取与特定表的所有已完成作业对应的日志:

resource.type="bigquery_resource" AND
log_name="projects/<project_name>/logs/cloudaudit.googleapis.com%2Fdata_access" AND
proto_payload.method_name="jobservice.jobcompleted"
"<table_name>"

然后选择 Bigquery 作为 Sink Service,并为您的 Sink 表和将存储它的数据集指定一个名称。

在接收器建立后对该表执行的所有已完成作业都将在 BigQuery 中显示为新表。您可以查询此表以获取有关日志的信息(例如,您可以在任何列上使用 COUNT 语句来获取成功作业的总数)。

【讨论】:

  • 偶尔的投票建议在 cmets 中是可以的,但建议人们接受/支持 an 答案会更好,而不是专门针对您的答案。不过,我们宁愿不在帖子中使用它,因为它应该集中在问答材料上。谢谢!
  • 好的,很抱歉,我会考虑到它的未来。谢谢!
【解决方案2】:

此信息可在 projects.locations.entryGroups.entries/get API 中找到。它作为 UsageSignal 可用,包含 24 小时、7 天、30 天的使用信息。

示例输出:

"usageSignal": {
    "updateTime": "2021-05-23T06:59:59.971Z",
    "usageWithinTimeRange": {
      "30D": {
        "totalCompletions": 156890,
        "totalFailures": 3,
        "totalCancellations": 1,
        "totalExecutionTimeForCompletionsMillis": 6.973312e+08
      },
      "7D": {
        "totalCompletions": 44318,
        "totalFailures": 1,
        "totalExecutionTimeForCompletionsMillis": 2.0592365e+08
      },
      "24H": {
        "totalCompletions": 6302,
        "totalExecutionTimeForCompletionsMillis": 25763162
      }
    }
  }

参考:

https://cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups.entries/get

https://cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups.entries#UsageSignal

【讨论】:

    【解决方案3】:

    使用 Python 数据目录 - 您首先需要搜索数据目录,您将收到 linked_resource 作为响应。

    将此linked_resource 作为请求传递给lookup_entry,您将获取最后一次查询(30 天)

    results = dc_client.search_catalog(request=request, timeout=120.0)
    for result in results:
        linked_resource = result.linked_resource
    
        # Get the Location and number of times the table is queried in last 30 days
        table_entry = dc_client.lookup_entry(request={"linked_resource": linked_resource})
    
        queried_past_30_days = table_entry.usage_signal.usage_within_time_range.get("30D")
        if queried_past_30_days is not None:
            dc_num_queried_past_30_days = int(queried_past_30_days.total_completions)
        else:
            dc_num_queried_past_30_days = 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 2012-10-31
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      相关资源
      最近更新 更多