python-3.x - 当 bigquery 的查询结果为空(使用 pthon)时,关于如何使用 gcp stackdriver 收集日志的任何想法?
问题描述
我有一个云功能,它正在执行查询并将作业结果存储到新的 bigquery 表中。每当我得到查询作业结果为空时,我想将日志存储到堆栈驱动程序中,这意味着找不到该特定查询执行的记录。谁能建议我如何完成这项任务。
云函数代码:
def main(request):
query = "select * from `myproject.mydataset.mytable`"
client = bigquery.Client()
job_config = bigquery.QueryJobConfig()
dest_dataset = client.dataset(destination_dataset, destination_project)
dest_table = dest_dataset.table(destination_table)
job_config.destination = dest_table
job_config.create_disposition = 'CREATE_IF_NEEDED'
job_config.write_disposition = 'WRITE_APPEND'
job = client.query(query, location='US', job_config=job_config)
job.result()
解决方案
- 转到 GCP 控制台中的 Stackdriver 日志记录部分。
- 激活高级过滤器(单击过滤器字段右侧的箭头)
- 用这个填充自定义字段:
resource.type="bigquery_resource"
"device_states"
protoPayload.methodName="jobservice.getqueryresults"
NOT protoPayload.serviceData.jobGetQueryResultsResponse.totalResults>"0"
这样,您只选择等于 0 的总结果。诀窍是缺少总结果,结果为 0。使用这种语法,它可以工作。
然后,您可以创建导出到 BigQuery、Storage 或 PubSub,或创建指标。如果您这样做,那么您可以在 Stackdriver 监控和警报中使用此指标。一切都取决于你想做什么。
推荐阅读
- swift - Swift 编译器崩溃 - 有人看到了吗?
- node.js - 接受输入到节点进程的最基本、原始、准系统的方法是什么?
- macos - GDB 未知加载命令
- sql - 如何获取SQL Server列中某个单词后的值?
- java - 如何创建数组的 ArrayList
- asp.net-mvc - 基于 MVC 的应用程序出现奇怪的 IIS 403.14 问题
- ember.js - Ember 关系在测试环境中不尊重模型自定义适配器
- javascript - 使用 PUT 请求和 updateOne 更新 MongoDB 集合
- c - 使用指针算法查找数组大小时动态创建的数组 (int *arr) 和静态创建的数组 (int arr[]) 之间的区别
- javascript - 我正在尝试添加每行都有它的按钮,并在它的底部添加另一行