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

Support structure logging for livenessprobe container #168

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions cmd/livenessprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
"github.com/kubernetes-csi/csi-lib-utils/rpc"
logsapi "k8s.io/component-base/logs/api/v1"
json "k8s.io/component-base/logs/json"
)

const (
Expand All @@ -46,6 +48,7 @@ var (
metricsAddress = flag.String("metrics-address", "", "(deprecated) The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled. If set, `--http-endpoint` cannot be set, and the address cannot resolve to localhost + the port from `--health-port`.")
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including CSI driver health check and metrics. The default is empty string, which means the server is disabled. If set, `--health-port` and `--metrics-address` cannot be explicitly set.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
logFormatJSON = flag.Bool("log-format-json", false, "set log formatter to json")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should follow the same flag as the kubelet which is logging-format https://github.com/kubernetes/component-base/blob/v0.25.3/logs/api/v1/options.go#L185

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure i will modify this to logging-format

)

type healthProbe struct {
Expand Down Expand Up @@ -131,6 +134,11 @@ func main() {
klog.Error("only one of `--metrics-address` and `--http-endpoint` can be explicitly set.")
os.Exit(1)
}
if *logFormatJSON {
jsonFactory := json.Factory{}
logger, _ := jsonFactory.Create(logsapi.LoggingConfiguration{Format: "json"})
klog.InfoS("logging livenessprobe",logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just logging logger but not telling klog to use it for logging

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauriciopoppe ok i will re check this, if it's possible could you provide me pointer on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i will check that thanks

}
var addr string
if *httpEndpoint != "" {
addr = *httpEndpoint
Expand Down
1 change: 1 addition & 0 deletions deployment/kubernetes/livenessprobe-sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
args:
- --v=4
- --csi-address=/csi/csi.sock
- --log-format-json=true
#
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,48 @@ require (
github.com/golang/mock v1.6.0
github.com/kubernetes-csi/csi-lib-utils v0.13.0
github.com/kubernetes-csi/csi-test/v5 v5.0.0

k8s.io/component-base v0.25.2



google.golang.org/grpc v1.55.0
k8s.io/klog/v2 v2.100.1

)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect

github.com/go-logr/zapr v1.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect



github.com/golang/protobuf v1.5.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect

github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect

go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect

golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/protobuf v1.30.0 // indirect
k8s.io/apimachinery v0.27.0 // indirect
k8s.io/component-base v0.27.0 // indirect

)
80 changes: 77 additions & 3 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions vendor/github.com/go-logr/zapr/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions vendor/github.com/go-logr/zapr/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions vendor/github.com/go-logr/zapr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading