Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Log Enconder Config #2927

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/customized-log-encoder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Enabling new Logs Enconder Configuration parameters.

# One or more tracking issues related to the change
issues: [268]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
9 changes: 9 additions & 0 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"github.com/go-logr/logr"
"go.uber.org/zap/zapcore"

"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
Expand Down Expand Up @@ -253,3 +254,11 @@ func WithAnnotationFilters(annotationFilters []string) Option {
o.annotationsFilter = filters
}
}

func WithEncodeLevelFormat(s string) zapcore.LevelEncoder {
if s == "lowercase" {
return zapcore.LowercaseLevelEncoder
} else {
return zapcore.CapitalLevelEncoder
}
}
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/spf13/pflag"
colfeaturegate "go.opentelemetry.io/collector/featuregate"
"go.uber.org/zap/zapcore"
networkingv1 "k8s.io/api/networking/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -131,6 +132,11 @@ func main() {
annotationsFilter []string
webhookPort int
tlsOpt tlsConfig
custLogEncoder bool
encodeMessageKey string
encodeLevelKey string
encodeTimeKey string
encodeLevelFormat string
)

pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
Expand Down Expand Up @@ -163,8 +169,22 @@ func main() {
pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.")
pflag.StringVar(&tlsOpt.minVersion, "tls-min-version", "VersionTLS12", "Minimum TLS version supported. Value must match version names from https://golang.org/pkg/crypto/tls/#pkg-constants.")
pflag.StringSliceVar(&tlsOpt.cipherSuites, "tls-cipher-suites", nil, "Comma-separated list of cipher suites for the server. Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants). If omitted, the default Go cipher suites will be used")
pflag.BoolVar(&custLogEncoder, "enable-customized-log-encoder", false, "Enable the use of a customized Json Log Encoder")
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
pflag.StringVar(&encodeMessageKey, "log-message-key", "message", "The message key to be used in the customized Log Encoder")
pflag.StringVar(&encodeLevelKey, "log-level-key", "level", "The level key to be used in the customized Log Encoder")
pflag.StringVar(&encodeTimeKey, "log-time-key", "timestamp", "The time key to be used in the customized Log Encoder")
pflag.StringVar(&encodeLevelFormat, "log-level-format", "uppercase", "The level format to be used in the customized Log Encoder")
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
pflag.Parse()

if custLogEncoder {
opts.EncoderConfigOptions = append(opts.EncoderConfigOptions, func(ec *zapcore.EncoderConfig) {
ec.MessageKey = encodeMessageKey
ec.LevelKey = encodeLevelKey
ec.TimeKey = encodeTimeKey
ec.EncodeLevel = config.WithEncodeLevelFormat(encodeLevelFormat)
})
}

logger := zap.New(zap.UseFlagOptions(&opts))
ctrl.SetLogger(logger)

Expand Down Expand Up @@ -195,6 +215,11 @@ func main() {
"enable-nginx-instrumentation", enableNginxInstrumentation,
"enable-nodejs-instrumentation", enableNodeJSInstrumentation,
"enable-java-instrumentation", enableJavaInstrumentation,
"enable-customized-log-encoder", custLogEncoder,
"log-message-key", encodeMessageKey,
"log-level-key", encodeLevelKey,
"log-time-key", encodeTimeKey,
"log-level-format", encodeLevelFormat,
)

restConfig := ctrl.GetConfigOrDie()
Expand Down
Loading