如何检索与BigQuery作业关联的用户和SQL代码? [英] How retrieve the user and SQL code associated with a BigQuery job?

查看:94
本文介绍了如何检索与BigQuery作业关联的用户和SQL代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了安全起见,我希望能够审核谁在某个项目中正在运行哪些查询。这可能吗?



使用命令行中的 bq ls -j 给出一些信息; bg show -j 给出更多一点。但不会显示用户或查询本身。

解决方案

在CLI中,您可以运行 bq ls -j -a 来检索项目中所有用户的作业。

然后你可以运行每个工作id a bq show -j < / code>并且为了你会选择使用json响应的更多细节:

  bq show --format = prettyjson -j job_joQEqPwOiOoBlOhDBEgKxQAlKJQ 

这将返回以下格式,其中包含您的查询,您的用户和字节处理等...

  {
配置:{
dryRun:false,
query:{
createDisposition:CREATE_IF_NEEDED,
destinationTable:{
datasetId:,
projectId:,
tableId:
},
query:,
writeDisposition:WRITE_TRUNCATE
}
},
etag:,
id:,
jobReference:{
jobId:,
projectId:
},
kind:bigquery#job,
selfLink:,
statistics:{
creationTime: 1435006022346,
endTime:1435006144730,
query:{
cacheHit:false,
totalBytesProcessed:105922683030
} ,
startTime:1435006023171,
totalBytesProcessed:105922683030
},
status:{
state:DONE
},
user_email:
}

使用API​​,您需要传递allUsers属性以列出所有用户的作业 https://cloud.google.com/bigquery/docs/reference/v2/jobs/list#allUsers


For security purposes, I'd like to be able to audit who is running what kinds of queries within a certain project. Is this possible?

Using bq ls -j from the command line gives some info; bg show -j gives a little more. But neither show the user or the query itself.

解决方案

In the CLI, you can run bq ls -j -a to retrieve jobs for all users in a project.

Then you can run for each job id a bq show -j <job_id> and in order to have more details you will choose to use the json response:

bq show --format=prettyjson -j job_joQEqPwOiOoBlOhDBEgKxQAlKJQ

this returns the following format which have your query, your user and bytesprocessed etc...

{
  "configuration": {
    "dryRun": false, 
    "query": {
      "createDisposition": "CREATE_IF_NEEDED", 
      "destinationTable": {
        "datasetId": "", 
        "projectId": "", 
        "tableId": ""
      }, 
      "query": "", 
      "writeDisposition": "WRITE_TRUNCATE"
    }
  }, 
  "etag": "", 
  "id": "", 
  "jobReference": {
    "jobId": "", 
    "projectId": ""
  }, 
  "kind": "bigquery#job", 
  "selfLink": "", 
  "statistics": {
    "creationTime": "1435006022346", 
    "endTime": "1435006144730", 
    "query": {
      "cacheHit": false, 
      "totalBytesProcessed": "105922683030"
    }, 
    "startTime": "1435006023171", 
    "totalBytesProcessed": "105922683030"
  }, 
  "status": {
    "state": "DONE"
  }, 
  "user_email": ""
}

Using the API you need to pass allUsers property to list jobs from all users https://cloud.google.com/bigquery/docs/reference/v2/jobs/list#allUsers

这篇关于如何检索与BigQuery作业关联的用户和SQL代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆