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

chore: use ErrorS instead of Fatalf for structured logging #638

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func main() {

if *versionInfo {
if err := version.PrintVersion(); err != nil {
klog.Fatalf("failed to print version, err: %+v", err)
klog.ErrorS(err, "failed to print version")
os.Exit(1)
}
os.Exit(0)
}
Expand All @@ -78,7 +79,8 @@ func main() {
// initialize metrics exporter before creating measurements
err := metrics.InitMetricsExporter(*metricsBackend, *prometheusPort)
if err != nil {
klog.Fatalf("failed to initialize metrics exporter, error: %+v", err)
klog.ErrorS(err, "failed to initialize metrics exporter")
os.Exit(1)
}

if *provider.ConstructPEMChain {
Expand All @@ -89,26 +91,30 @@ func main() {
}
// Add csi-secrets-store user agent to adal requests
if err := adal.AddToUserAgent(version.GetUserAgent()); err != nil {
klog.Fatalf("failed to add user agent to adal: %+v", err)
klog.ErrorS(err, "failed to add user agent to adal")
os.Exit(1)
}
// Initialize and run the gRPC server
proto, addr, err := utils.ParseEndpoint(*endpoint)
if err != nil {
klog.Fatalf("failed to parse endpoint, err: %+v", err)
klog.ErrorS(err, "failed to parse endpoint")
os.Exit(1)
}

if proto == "unix" {
if runtime.GOOS != "windows" {
addr = "/" + addr
}
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
klog.Fatalf("failed to remove %s, error: %s", addr, err.Error())
klog.ErrorS(err, "failed to remove socket", "addr", addr)
os.Exit(1)
}
}

listener, err := net.Listen(proto, addr)
if err != nil {
klog.Fatalf("failed to listen: %v", err)
klog.ErrorS(err, "failed to listen", "proto", proto, "addr", addr)
os.Exit(1)
}

opts := []grpc.ServerOption{
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const prometheusExporter = "prometheus"

func InitMetricsExporter(metricsBackend string, prometheusPort int) error {
mb := strings.ToLower(metricsBackend)
klog.Infof("metrics backend: %s", mb)
klog.InfoS("intializing metrics backend", "backend", mb)
switch mb {
// Prometheus is the only exporter for now
case prometheusExporter:
Expand Down
4 changes: 3 additions & 1 deletion pkg/server/healthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"time"

"github.com/pkg/errors"
Expand All @@ -25,7 +26,8 @@ func (h *HealthZ) Serve() {
serveMux := http.NewServeMux()
serveMux.HandleFunc(h.HealthCheckURL.EscapedPath(), h.ServeHTTP)
if err := http.ListenAndServe(h.HealthCheckURL.Host, serveMux); err != nil && errors.Is(err, http.ErrServerClosed) {
klog.Fatalf("failed to start health check server, err: %w", err)
klog.ErrorS(err, "failed to start health check server")
os.Exit(1)
}
}

Expand Down