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

Observability and Debuggability OSS Project Code #190

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ spec:
- --leader-elect
image: controller:latest
name: manager
volumeMounts:
- name: varlog
mountPath: /var/log
securityContext:
allowPrivilegeEscalation: false
# TODO(user): uncomment for common cases that do not require escalating privileges
Expand All @@ -63,5 +66,24 @@ spec:
requests:
cpu: 10m
memory: 64Mi
- name: filebeat
image: elastic/filebeat:7.16.3
args:
- -c
- /etc/filebeat/conf.yaml
- -e
securityContext:
runAsUser: 9999
volumeMounts:
- name: filebeat-config
mountPath: /etc/filebeat
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
emptyDir: {}
- name: filebeat-config
configMap:
name: filebeat-config
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
22 changes: 22 additions & 0 deletions filebeat.cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
namespace: ndb-operator-system
labels:
component: filebeat
data:
conf.yaml: |
filebeat.inputs:
- type: log
paths:
- '/var/log/*.log'
output.elasticsearch:
hosts: ["https://quickstart-es-http.default.svc.cluster.local:9200"]
username: "elastic"
password:
valueFrom:
secretKeyRef:
name: quickstart-es-elastic-user
key: elastic
ssl.verification_mode: none
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
29 changes: 29 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ package main

import (
"flag"
"io"
"os"
"time"

"gopkg.in/natefinch/lumberjack.v2"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -64,9 +68,34 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

// Set the log file path
logFilePath := "/var/log/ndb-operator.log"
logRotateDuration := (1 * time.Minute)

// Create a file for logging with log rotation
logFile := &lumberjack.Logger{
Filename: logFilePath,
MaxSize: 10, // Max size in megabytes before log rolling (change as needed)
MaxBackups: 5, // Max number of old log files to keep
MaxAge: 0, // Max number of days to retain old log files
Compress: false, // Whether to compress old log files
}

// Use a ticker to trigger log rotation every timestep of logRoationDuration
ticker := time.NewTicker(logRotateDuration)
go func() {
for range ticker.C {
logFile.Rotate()
}
}()

mwriter := io.MultiWriter(logFile, os.Stderr)

opts := zap.Options{
Development: true,
TimeEncoder: zapcore.RFC3339TimeEncoder,
DestWriter: mwriter, // Configure Zap options to write into a multiwriter
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
Expand Down