Skip to content

Commit

Permalink
LOG-6296: GCP expects certain severity value strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Clee2691 authored and openshift-merge-bot[bot] committed Oct 30, 2024
1 parent 9f52978 commit a047172
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
32 changes: 31 additions & 1 deletion internal/generator/vector/output/gcl/gcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gcl

import (
"fmt"

"github.com/openshift/cluster-logging-operator/internal/api/observability"

obs "github.com/openshift/cluster-logging-operator/api/observability/v1"
Expand Down Expand Up @@ -76,21 +77,24 @@ func New(id string, o obs.OutputSpec, inputs []string, secrets observability.Sec
return []Element{}
}
componentID := vectorhelpers.MakeID(id, "log_id")
gclSeverityID := vectorhelpers.MakeID(id, "normalize_severity")
g := o.GoogleCloudLogging
gcl := &GoogleCloudLogging{
ComponentID: id,
Inputs: helpers.MakeInputs(componentID),
Inputs: helpers.MakeInputs(gclSeverityID),
LogDestination: LogDestination(g),
LogID: componentID,
SeverityKey: SeverityKey(g),
CredentialsPath: auth(g.Authentication, secrets),
RootMixin: common.NewRootMixin(nil),
}

if strategy != nil {
strategy.VisitSink(gcl)
}
return []Element{
commontemplate.TemplateRemap(componentID, inputs, o.GoogleCloudLogging.LogId, componentID, "GoogleCloudLogging LogId"),
NormalizeSeverity(gclSeverityID, []string{componentID}),
gcl,
common.NewEncoding(id, ""),
common.NewAcknowledgments(id, strategy),
Expand Down Expand Up @@ -127,3 +131,29 @@ func LogDestination(g *obs.GoogleCloudLogging) Element {
func SeverityKey(g *obs.GoogleCloudLogging) string {
return DefaultSeverityKey
}

// NormalizeSeverity normalizes log severity to conform to GCL's standard
// Accepted Severity: DEFAULT, EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG
// Ref: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity
func NormalizeSeverity(componentID string, inputs []string) Element {
var vrl = `
# Set audit log level to 'INFO'
if .log_type == "audit" {
.level = "INFO"
} else if !exists(.level) {
.level = "DEFAULT"
} else if .level == "warn" {
.level = "WARNING"
} else if .level == "trace" {
.level = "DEBUG"
} else {
.level = upcase!(.level)
}
`
return Remap{
Desc: "Normalize GCL severity levels",
ComponentID: componentID,
Inputs: vectorhelpers.MakeInputs(inputs...),
VRL: vrl,
}
}
21 changes: 20 additions & 1 deletion internal/generator/vector/output/gcl/gcl_with_custom_logid.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,28 @@ source = '''
._internal.gcl_1_log_id = "my-id" + to_string!(.log_type||"none")
'''

# Normalize GCL severity levels
[transforms.gcl_1_normalize_severity]
type = "remap"
inputs = ["gcl_1_log_id"]
source = '''
# Set audit log level to 'INFO'
if .log_type == "audit" {
.level = "INFO"
} else if !exists(.level) {
.level = "DEFAULT"
} else if .level == "warn" {
.level = "WARNING"
} else if .level == "trace" {
.level = "DEBUG"
} else {
.level = upcase!(.level)
}
'''

[sinks.gcl_1]
type = "gcp_stackdriver_logs"
inputs = ["gcl_1_log_id"]
inputs = ["gcl_1_normalize_severity"]
billing_account_id = "billing-1"
credentials_path = "/var/run/ocp-collector/secrets/gcl-1/google-application-credentials.json"
log_id = "{{ _internal.gcl_1_log_id }}"
Expand Down
21 changes: 20 additions & 1 deletion internal/generator/vector/output/gcl/gcl_with_tls.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,28 @@ source = '''
._internal.gcl_1_log_id = "vector-1"
'''

# Normalize GCL severity levels
[transforms.gcl_1_normalize_severity]
type = "remap"
inputs = ["gcl_1_log_id"]
source = '''
# Set audit log level to 'INFO'
if .log_type == "audit" {
.level = "INFO"
} else if !exists(.level) {
.level = "DEFAULT"
} else if .level == "warn" {
.level = "WARNING"
} else if .level == "trace" {
.level = "DEBUG"
} else {
.level = upcase!(.level)
}
'''

[sinks.gcl_1]
type = "gcp_stackdriver_logs"
inputs = ["gcl_1_log_id"]
inputs = ["gcl_1_normalize_severity"]
billing_account_id = "billing-1"
credentials_path = "/var/run/ocp-collector/secrets/gcl-1/google-application-credentials.json"
log_id = "{{ _internal.gcl_1_log_id }}"
Expand Down
21 changes: 20 additions & 1 deletion internal/generator/vector/output/gcl/gcl_with_token.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,28 @@ source = '''
._internal.gcl_1_log_id = "vector-1"
'''

# Normalize GCL severity levels
[transforms.gcl_1_normalize_severity]
type = "remap"
inputs = ["gcl_1_log_id"]
source = '''
# Set audit log level to 'INFO'
if .log_type == "audit" {
.level = "INFO"
} else if !exists(.level) {
.level = "DEFAULT"
} else if .level == "warn" {
.level = "WARNING"
} else if .level == "trace" {
.level = "DEBUG"
} else {
.level = upcase!(.level)
}
'''

[sinks.gcl_1]
type = "gcp_stackdriver_logs"
inputs = ["gcl_1_log_id"]
inputs = ["gcl_1_normalize_severity"]
billing_account_id = "billing-1"
credentials_path = "/var/run/ocp-collector/secrets/gcl-1/google-application-credentials.json"
log_id = "{{ _internal.gcl_1_log_id }}"
Expand Down
21 changes: 20 additions & 1 deletion internal/generator/vector/output/gcl/gcl_with_tuning.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,28 @@ source = '''
._internal.gcl_1_log_id = "vector-1"
'''

# Normalize GCL severity levels
[transforms.gcl_1_normalize_severity]
type = "remap"
inputs = ["gcl_1_log_id"]
source = '''
# Set audit log level to 'INFO'
if .log_type == "audit" {
.level = "INFO"
} else if !exists(.level) {
.level = "DEFAULT"
} else if .level == "warn" {
.level = "WARNING"
} else if .level == "trace" {
.level = "DEBUG"
} else {
.level = upcase!(.level)
}
'''

[sinks.gcl_1]
type = "gcp_stackdriver_logs"
inputs = ["gcl_1_log_id"]
inputs = ["gcl_1_normalize_severity"]
billing_account_id = "billing-1"
credentials_path = "/var/run/ocp-collector/secrets/gcl-1/google-application-credentials.json"
log_id = "{{ _internal.gcl_1_log_id }}"
Expand Down

0 comments on commit a047172

Please sign in to comment.