gcp: update logging reader for new kubernetes format (#87)

This commit is contained in:
David Dollar 2020-01-29 13:44:46 -05:00 committed by GitHub
parent 981cfc00e0
commit 14afc2dae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 18 deletions

View File

@ -101,19 +101,13 @@ Iteration:
prefix := ""
pod := entry.Labels["container.googleapis.com/pod_name"]
service := "unknown"
labels := entry.Resource.GetLabels()
if pp := strings.Split(pod, "-"); len(pp) > 2 {
service = strings.Join(pp[0:len(pp)-2], "-")
}
typ := common.CoalesceString(entry.Labels["k8s-pod/type"], "unknown")
name := common.CoalesceString(entry.Labels["k8s-pod/name"], "unknown")
if common.DefaultBool(opts.Prefix, false) {
if strings.HasSuffix(entry.LogName, "/main") {
prefix = fmt.Sprintf("%s service/%s/%s ", entry.Timestamp.Format(time.RFC3339), service, pod)
} else {
prefix = fmt.Sprintf("%s %s ", entry.Timestamp.Format(time.RFC3339), entry.Labels["stream"])
}
prefix = fmt.Sprintf("%s %s/%s/%s ", entry.Timestamp.Format(time.RFC3339), typ, name, labels["pod_name"])
}
switch t := entry.Payload.(type) {
@ -132,5 +126,11 @@ Iteration:
}
func (p *Provider) logFilters(app string) string {
return fmt.Sprintf(`labels."container.googleapis.com/namespace_name" = %q`, p.AppNamespace(app))
filters := []string{
`resource.type="k8s_container"`,
fmt.Sprintf(`resource.labels.cluster_name=%q`, p.Name),
fmt.Sprintf(`resource.labels.namespace_name=%q`, p.AppNamespace(app)),
}
return strings.Join(filters, " AND ")
}

View File

@ -6,13 +6,8 @@ resource "google_service_account_key" "api" {
service_account_id = google_service_account.api.name
}
resource "google_project_iam_member" "api-logging-viewer" {
role = "roles/logging.viewer"
member = "serviceAccount:${google_service_account.api.email}"
}
resource "google_project_iam_member" "api-logging-writer" {
role = "roles/logging.logWriter"
resource "google_project_iam_member" "api-logging-admin" {
role = "roles/logging.admin"
member = "serviceAccount:${google_service_account.api.email}"
}