cleanup: move log functions to new internal/util/log package

Moving the log functions into its own internal/util/log package makes it
possible to split out the humongous internal/util packages in further
smaller pieces. This reduces the inter-dependencies between utility
functions and components, preventing circular dependencies which are not
allowed in Go.

Updates: #852
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2021-08-24 17:03:25 +02:00
committed by mergify[bot]
parent 2036b587d7
commit 6d00b39886
41 changed files with 505 additions and 467 deletions

View File

@ -21,6 +21,7 @@ import (
"time"
"github.com/ceph/ceph-csi/internal/util"
"github.com/ceph/ceph-csi/internal/util/log"
connlib "github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
@ -39,23 +40,23 @@ func getLiveness(timeout time.Duration, csiConn *grpc.ClientConn) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
util.TraceLogMsg("Sending probe request to CSI driver")
log.TraceLogMsg("Sending probe request to CSI driver")
ready, err := rpc.Probe(ctx, csiConn)
if err != nil {
liveness.Set(0)
util.ErrorLogMsg("health check failed: %v", err)
log.ErrorLogMsg("health check failed: %v", err)
return
}
if !ready {
liveness.Set(0)
util.ErrorLogMsg("driver responded but is not ready")
log.ErrorLogMsg("driver responded but is not ready")
return
}
liveness.Set(1)
util.ExtendedLogMsg("Health check succeeded")
log.ExtendedLogMsg("Health check succeeded")
}
func recordLiveness(endpoint, drivername string, pollTime, timeout time.Duration) {
@ -63,14 +64,14 @@ func recordLiveness(endpoint, drivername string, pollTime, timeout time.Duration
// register prometheus metrics
err := prometheus.Register(liveness)
if err != nil {
util.FatalLogMsg(err.Error())
log.FatalLogMsg(err.Error())
}
csiConn, err := connlib.Connect(endpoint, liveMetricsManager)
if err != nil {
// connlib should retry forever so a returned error should mean
// the grpc client is misconfigured rather than an error on the network
util.FatalLogMsg("failed to establish connection to CSI driver: %v", err)
log.FatalLogMsg("failed to establish connection to CSI driver: %v", err)
}
// get liveness periodically
@ -83,7 +84,7 @@ func recordLiveness(endpoint, drivername string, pollTime, timeout time.Duration
// Run starts liveness collection and prometheus endpoint.
func Run(conf *util.Config) {
util.ExtendedLogMsg("Liveness Running")
log.ExtendedLogMsg("Liveness Running")
// start liveness collection
go recordLiveness(conf.Endpoint, conf.DriverName, conf.PollTime, conf.PoolTimeout)