GCP:如何从标记的资源中查询日志?
GCP: How to query logs from labeled resources?
我为我的 GAE 资源添加了标签,我希望根据它们的标签有不同的日志接收器。
我找不到在没有 bigquery 的查询日志记录中过滤它们的方法。
也有办法add network tags to App Engine Instances。
我在 simple python "hello world" exaple.
上测试了这个
准备好应用程序后,只需在 app.yaml
文件中添加两行。我的文件如下所示:
runtime: python39
service: my-tagged-app
network:
instance_tag: gae-tag1
当您部署此应用程序时,运行 实例将被“标记”。但是除了在日志资源管理器中,您不会在其他任何地方看到它;
使用查询:
resource.type="gae_app"
protoPayload.serviceData.createVersion.request.version.network.instanceTag="gae-tag1"
你会得到这样的结果:
gcloud logging read "gae-tag1"
---
insertId: -oohejhdivvs
logName: projects/myproj/logs/cloudaudit.googleapis.com%2Factivity
operation:
first: true
id: 459d7914-20a1-439c-9c4d-08e96964dcb1
producer: appengine.googleapis.com/admin
protoPayload:
'@type': type.googleapis.com/google.cloud.audit.AuditLog
authenticationInfo:
principalEmail: my@mail.com
authorizationInfo:
- granted: true
permission: appengine.versions.create
resource: apps/myproj/services/czesc-2-tag/versions/2034555122t104822
resourceAttributes: {}
methodName: google.appengine.v1.Versions.CreateVersion
requestMetadata:
callerIp: 31.91.214.141
destinationAttributes: {}
requestAttributes:
auth: {}
time: '2021-01-22T10:48:27.701290Z'
resourceLocation:
currentLocations:
- us-central1
resourceName: apps/myproj/services/czesc-2-tag/versions/20210122t104822
serviceData:
'@type': type.googleapis.com/google.appengine.v1.AuditData
createVersion:
request:
parent: apps/myproj/services/czesc-2-tag
version:
entrypoint:
shell: ''
id: 20210122t104822
network:
instanceTag: gae-tag1
runtime: python39
serviceName: appengine.googleapis.com
status: {}
receiveTimestamp: '2021-01-22T10:48:28.183925224Z'
resource:
labels:
module_id: czesc-2-tag
project_id: myproj
version_id: 20210122t104822
zone: ''
type: gae_app
severity: NOTICE
timestamp: '2021-01-22T10:48:27.506516Z'
这就是您过滤日志的方法。至少使用网络标签(您也可以使用它来定义 GAE 防火墙规则)。
你可以看看讨论过的类似案例here。
我为我的 GAE 资源添加了标签,我希望根据它们的标签有不同的日志接收器。
我找不到在没有 bigquery 的查询日志记录中过滤它们的方法。
也有办法add network tags to App Engine Instances。
我在 simple python "hello world" exaple.
上测试了这个准备好应用程序后,只需在 app.yaml
文件中添加两行。我的文件如下所示:
runtime: python39
service: my-tagged-app
network:
instance_tag: gae-tag1
当您部署此应用程序时,运行 实例将被“标记”。但是除了在日志资源管理器中,您不会在其他任何地方看到它;
使用查询:
resource.type="gae_app"
protoPayload.serviceData.createVersion.request.version.network.instanceTag="gae-tag1"
你会得到这样的结果:
gcloud logging read "gae-tag1"
---
insertId: -oohejhdivvs
logName: projects/myproj/logs/cloudaudit.googleapis.com%2Factivity
operation:
first: true
id: 459d7914-20a1-439c-9c4d-08e96964dcb1
producer: appengine.googleapis.com/admin
protoPayload:
'@type': type.googleapis.com/google.cloud.audit.AuditLog
authenticationInfo:
principalEmail: my@mail.com
authorizationInfo:
- granted: true
permission: appengine.versions.create
resource: apps/myproj/services/czesc-2-tag/versions/2034555122t104822
resourceAttributes: {}
methodName: google.appengine.v1.Versions.CreateVersion
requestMetadata:
callerIp: 31.91.214.141
destinationAttributes: {}
requestAttributes:
auth: {}
time: '2021-01-22T10:48:27.701290Z'
resourceLocation:
currentLocations:
- us-central1
resourceName: apps/myproj/services/czesc-2-tag/versions/20210122t104822
serviceData:
'@type': type.googleapis.com/google.appengine.v1.AuditData
createVersion:
request:
parent: apps/myproj/services/czesc-2-tag
version:
entrypoint:
shell: ''
id: 20210122t104822
network:
instanceTag: gae-tag1
runtime: python39
serviceName: appengine.googleapis.com
status: {}
receiveTimestamp: '2021-01-22T10:48:28.183925224Z'
resource:
labels:
module_id: czesc-2-tag
project_id: myproj
version_id: 20210122t104822
zone: ''
type: gae_app
severity: NOTICE
timestamp: '2021-01-22T10:48:27.506516Z'
这就是您过滤日志的方法。至少使用网络标签(您也可以使用它来定义 GAE 防火墙规则)。
你可以看看讨论过的类似案例here。