mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
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:
committed by
mergify[bot]
parent
2036b587d7
commit
6d00b39886
@ -19,7 +19,7 @@ package csicommon
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -71,7 +71,7 @@ func (cs *DefaultControllerServer) GetCapacity(
|
||||
func (cs *DefaultControllerServer) ControllerGetCapabilities(
|
||||
ctx context.Context,
|
||||
req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
|
||||
util.TraceLog(ctx, "Using default ControllerGetCapabilities")
|
||||
log.TraceLog(ctx, "Using default ControllerGetCapabilities")
|
||||
if cs.Driver == nil {
|
||||
return nil, status.Error(codes.Unimplemented, "Controller server is not enabled")
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ package csicommon
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
)
|
||||
|
||||
// CSIDriver stores driver information.
|
||||
@ -91,7 +91,7 @@ func (d *CSIDriver) AddControllerServiceCapabilities(cl []csi.ControllerServiceC
|
||||
csc := make([]*csi.ControllerServiceCapability, 0, len(cl))
|
||||
|
||||
for _, c := range cl {
|
||||
util.DefaultLog("Enabling controller service capability: %v", c.String())
|
||||
log.DefaultLog("Enabling controller service capability: %v", c.String())
|
||||
csc = append(csc, NewControllerServiceCapability(c))
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ func (d *CSIDriver) AddVolumeCapabilityAccessModes(
|
||||
vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode {
|
||||
vca := make([]*csi.VolumeCapability_AccessMode, 0, len(vc))
|
||||
for _, c := range vc {
|
||||
util.DefaultLog("Enabling volume access mode: %v", c.String())
|
||||
log.DefaultLog("Enabling volume access mode: %v", c.String())
|
||||
vca = append(vca, NewVolumeCapabilityAccessMode(c))
|
||||
}
|
||||
d.vc = vca
|
||||
|
@ -19,7 +19,7 @@ package csicommon
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -35,7 +35,7 @@ type DefaultIdentityServer struct {
|
||||
func (ids *DefaultIdentityServer) GetPluginInfo(
|
||||
ctx context.Context,
|
||||
req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
|
||||
util.TraceLog(ctx, "Using default GetPluginInfo")
|
||||
log.TraceLog(ctx, "Using default GetPluginInfo")
|
||||
|
||||
if ids.Driver.name == "" {
|
||||
return nil, status.Error(codes.Unavailable, "Driver name not configured")
|
||||
@ -60,7 +60,7 @@ func (ids *DefaultIdentityServer) Probe(ctx context.Context, req *csi.ProbeReque
|
||||
func (ids *DefaultIdentityServer) GetPluginCapabilities(
|
||||
ctx context.Context,
|
||||
req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
|
||||
util.TraceLog(ctx, "Using default capabilities")
|
||||
log.TraceLog(ctx, "Using default capabilities")
|
||||
|
||||
return &csi.GetPluginCapabilitiesResponse{
|
||||
Capabilities: []*csi.PluginCapability{
|
||||
|
@ -19,7 +19,7 @@ package csicommon
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -57,7 +57,7 @@ func (ns *DefaultNodeServer) NodeExpandVolume(
|
||||
func (ns *DefaultNodeServer) NodeGetInfo(
|
||||
ctx context.Context,
|
||||
req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
|
||||
util.TraceLog(ctx, "Using default NodeGetInfo")
|
||||
log.TraceLog(ctx, "Using default NodeGetInfo")
|
||||
|
||||
csiTopology := &csi.Topology{
|
||||
Segments: ns.Driver.topology,
|
||||
@ -73,7 +73,7 @@ func (ns *DefaultNodeServer) NodeGetInfo(
|
||||
func (ns *DefaultNodeServer) NodeGetCapabilities(
|
||||
ctx context.Context,
|
||||
req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
|
||||
util.TraceLog(ctx, "Using default NodeGetCapabilities")
|
||||
log.TraceLog(ctx, "Using default NodeGetCapabilities")
|
||||
|
||||
return &csi.NodeGetCapabilitiesResponse{
|
||||
Capabilities: []*csi.NodeServiceCapability{
|
||||
|
@ -23,6 +23,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/csi-addons/spec/lib/go/replication"
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
@ -30,8 +32,6 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"google.golang.org/grpc"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
)
|
||||
|
||||
// NonBlockingGRPCServer defines Non blocking GRPC server interfaces.
|
||||
@ -128,7 +128,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint, hstOptions string, srv Servers,
|
||||
replication.RegisterControllerServer(server, srv.RS)
|
||||
}
|
||||
|
||||
util.DefaultLog("Listening for connections on address: %#v", listener.Addr())
|
||||
log.DefaultLog("Listening for connections on address: %#v", listener.Addr())
|
||||
if metrics {
|
||||
ho := strings.Split(hstOptions, ",")
|
||||
const expectedHo = 3
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
rp "github.com/csi-addons/replication-lib-utils/protosanitizer"
|
||||
@ -160,9 +161,9 @@ func contextIDInjector(
|
||||
info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||
atomic.AddUint64(&id, 1)
|
||||
ctx = context.WithValue(ctx, util.CtxKey, id)
|
||||
ctx = context.WithValue(ctx, log.CtxKey, id)
|
||||
if reqID := getReqID(req); reqID != "" {
|
||||
ctx = context.WithValue(ctx, util.ReqID, reqID)
|
||||
ctx = context.WithValue(ctx, log.ReqID, reqID)
|
||||
}
|
||||
|
||||
return handler(ctx, req)
|
||||
@ -173,18 +174,18 @@ func logGRPC(
|
||||
req interface{},
|
||||
info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
util.ExtendedLog(ctx, "GRPC call: %s", info.FullMethod)
|
||||
log.ExtendedLog(ctx, "GRPC call: %s", info.FullMethod)
|
||||
if isReplicationRequest(req) {
|
||||
util.TraceLog(ctx, "GRPC request: %s", rp.StripReplicationSecrets(req))
|
||||
log.TraceLog(ctx, "GRPC request: %s", rp.StripReplicationSecrets(req))
|
||||
} else {
|
||||
util.TraceLog(ctx, "GRPC request: %s", protosanitizer.StripSecrets(req))
|
||||
log.TraceLog(ctx, "GRPC request: %s", protosanitizer.StripSecrets(req))
|
||||
}
|
||||
|
||||
resp, err := handler(ctx, req)
|
||||
if err != nil {
|
||||
klog.Errorf(util.Log(ctx, "GRPC error: %v"), err)
|
||||
klog.Errorf(log.Log(ctx, "GRPC error: %v"), err)
|
||||
} else {
|
||||
util.TraceLog(ctx, "GRPC response: %s", protosanitizer.StripSecrets(resp))
|
||||
log.TraceLog(ctx, "GRPC response: %s", protosanitizer.StripSecrets(resp))
|
||||
}
|
||||
|
||||
return resp, err
|
||||
@ -231,32 +232,32 @@ func FilesystemNodeGetVolumeStats(ctx context.Context, targetPath string) (*csi.
|
||||
|
||||
available, ok := (*(volMetrics.Available)).AsInt64()
|
||||
if !ok {
|
||||
util.ErrorLog(ctx, "failed to fetch available bytes")
|
||||
log.ErrorLog(ctx, "failed to fetch available bytes")
|
||||
}
|
||||
capacity, ok := (*(volMetrics.Capacity)).AsInt64()
|
||||
if !ok {
|
||||
util.ErrorLog(ctx, "failed to fetch capacity bytes")
|
||||
log.ErrorLog(ctx, "failed to fetch capacity bytes")
|
||||
|
||||
return nil, status.Error(codes.Unknown, "failed to fetch capacity bytes")
|
||||
}
|
||||
used, ok := (*(volMetrics.Used)).AsInt64()
|
||||
if !ok {
|
||||
util.ErrorLog(ctx, "failed to fetch used bytes")
|
||||
log.ErrorLog(ctx, "failed to fetch used bytes")
|
||||
}
|
||||
inodes, ok := (*(volMetrics.Inodes)).AsInt64()
|
||||
if !ok {
|
||||
util.ErrorLog(ctx, "failed to fetch available inodes")
|
||||
log.ErrorLog(ctx, "failed to fetch available inodes")
|
||||
|
||||
return nil, status.Error(codes.Unknown, "failed to fetch available inodes")
|
||||
}
|
||||
inodesFree, ok := (*(volMetrics.InodesFree)).AsInt64()
|
||||
if !ok {
|
||||
util.ErrorLog(ctx, "failed to fetch free inodes")
|
||||
log.ErrorLog(ctx, "failed to fetch free inodes")
|
||||
}
|
||||
|
||||
inodesUsed, ok := (*(volMetrics.InodesUsed)).AsInt64()
|
||||
if !ok {
|
||||
util.ErrorLog(ctx, "failed to fetch used inodes")
|
||||
log.ErrorLog(ctx, "failed to fetch used inodes")
|
||||
}
|
||||
|
||||
return &csi.NodeGetVolumeStatsResponse{
|
||||
|
Reference in New Issue
Block a user