Skip to content

Commit

Permalink
chore: remove unnecessary logrus dependency (#1214)
Browse files Browse the repository at this point in the history
The troubleshoot project uses klog logging library. There is room for
only one library unfortunately. Sorry logrus :)
  • Loading branch information
banjoh authored Jun 8, 2023
1 parent 0a855f2 commit 08a1075
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851
github.com/segmentio/ksuid v1.0.4
github.com/shirou/gopsutil/v3 v3.23.5
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
Expand Down Expand Up @@ -70,6 +69,7 @@ require (
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sylabs/sif/v2 v2.11.1 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
Expand Down
14 changes: 7 additions & 7 deletions pkg/longhorn/types/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"

v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"

"github.com/replicatedhq/troubleshoot/pkg/longhorn/util"
)
Expand Down Expand Up @@ -941,7 +941,7 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {

// `yaml.Unmarshal()` can return a partial result. We shouldn't allow it
if err := yaml.Unmarshal(data, &defaultSettings); err != nil {
logrus.Errorf("Failed to unmarshal customized default settings from yaml data %v, will give up using them: %v", string(data), err)
klog.Errorf("Failed to unmarshal customized default settings from yaml data %v, will give up using them: %v", string(data), err)
defaultSettings = map[string]string{}
}
}
Expand All @@ -951,7 +951,7 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
value = strings.Trim(value, " ")
definition, exist := SettingDefinitions[SettingName(name)]
if !exist {
logrus.Errorf("Customized settings are invalid, will give up using them: undefined setting %v", name)
klog.Errorf("Customized settings are invalid, will give up using them: undefined setting %v", name)
defaultSettings = map[string]string{}
break
}
Expand All @@ -963,14 +963,14 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
if definition.Type == SettingTypeBool {
result, err := strconv.ParseBool(value)
if err != nil {
logrus.Errorf("Invalid value %v for the boolean setting %v: %v", value, name, err)
klog.Errorf("Invalid value %v for the boolean setting %v: %v", value, name, err)
defaultSettings = map[string]string{}
break
}
value = strconv.FormatBool(result)
}
if err := ValidateInitSetting(name, value); err != nil {
logrus.Errorf("Customized settings are invalid, will give up using them: the value of customized setting %v is invalid: %v", name, err)
klog.Errorf("Customized settings are invalid, will give up using them: the value of customized setting %v is invalid: %v", name, err)
defaultSettings = map[string]string{}
break
}
Expand All @@ -986,15 +986,15 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
guaranteedReplicaManagerCPU = defaultSettings[string(SettingNameGuaranteedReplicaManagerCPU)]
}
if err := ValidateCPUReservationValues(guaranteedEngineManagerCPU, guaranteedReplicaManagerCPU); err != nil {
logrus.Errorf("Customized settings GuaranteedEngineManagerCPU and GuaranteedReplicaManagerCPU are invalid, will give up using them: %v", err)
klog.Errorf("Customized settings GuaranteedEngineManagerCPU and GuaranteedReplicaManagerCPU are invalid, will give up using them: %v", err)
defaultSettings = map[string]string{}
}

return defaultSettings, nil
}

func OverwriteBuiltInSettingsWithCustomizedValues() error {
logrus.Infof("Start overwriting built-in settings with customized values")
klog.V(2).Info("Start overwriting built-in settings with customized values")
customizedDefaultSettings, err := GetCustomizedDefaultSettings()
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions pkg/longhorn/util/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/klog/v2"

iscsi_util "github.com/longhorn/go-iscsi-helper/util"
)
Expand Down Expand Up @@ -58,7 +58,7 @@ func RemoveHostDirectoryContent(directory string) (err error) {
}
// check if the directory already deleted
if _, err := nsExec.Execute("ls", []string{dir}); err != nil {
logrus.Warnf("cannot find host directory %v for removal", dir)
klog.Warningf("cannot find host directory %v for removal", dir)
return nil
}
if _, err := nsExec.Execute("rm", []string{"-rf", dir}); err != nil {
Expand Down Expand Up @@ -92,7 +92,7 @@ func CopyHostDirectoryContent(src, dest string) (err error) {

// There can be no src directory, hence returning nil is fine.
if _, err := nsExec.Execute("bash", []string{"-c", fmt.Sprintf("ls %s", filepath.Join(srcDir, "*"))}); err != nil {
logrus.Infof("cannot list the content of the src directory %v for the copy, will do nothing: %v", srcDir, err)
klog.V(2).Infof("cannot list the content of the src directory %v for the copy, will do nothing: %v", srcDir, err)
return nil
}
// Check if the dest directory exists.
Expand Down Expand Up @@ -164,7 +164,7 @@ func ExpandFileSystem(volumeName string) (err error) {
mountPoint := ""
mountRes, err := nsExec.Execute("bash", []string{"-c", "mount | grep \"/" + volumeName + " \" | awk '{print $3}'"})
if err != nil {
logrus.Warnf("failed to use command mount to get the mount info of volume %v, consider the volume as unmounted: %v", volumeName, err)
klog.Warningf("failed to use command mount to get the mount info of volume %v, consider the volume as unmounted: %v", volumeName, err)
} else {
// For empty `mountRes`, `mountPoints` is [""]
mountPoints := strings.Split(strings.TrimSpace(mountRes), "\n")
Expand All @@ -178,13 +178,13 @@ func ExpandFileSystem(volumeName string) (err error) {
}
}
if tmpMountNeeded {
logrus.Errorf("BUG: Found mount point records %v for volume %v but there is no valid(non-empty) mount point", mountRes, volumeName)
klog.Errorf("BUG: Found mount point records %v for volume %v but there is no valid(non-empty) mount point", mountRes, volumeName)
}
}
}
if tmpMountNeeded {
mountPoint = filepath.Join(TemporaryMountPointDirectory, volumeName)
logrus.Infof("The volume %v is unmounted, hence it will be temporarily mounted on %v for file system expansion", volumeName, mountPoint)
klog.V(2).Infof("The volume %v is unmounted, hence it will be temporarily mounted on %v for file system expansion", volumeName, mountPoint)
if _, err := nsExec.Execute("mkdir", []string{"-p", mountPoint}); err != nil {
return errors.Wrapf(err, "failed to create a temporary mount point %v before file system expansion", mountPoint)
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/longhorn/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/google/uuid"
"github.com/gorilla/handlers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -36,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/version"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
)

const (
Expand Down Expand Up @@ -222,16 +222,16 @@ func ExecuteWithTimeout(timeout time.Duration, envs []string, binary string, arg
case <-time.After(timeout):
if cmd.Process != nil {
if err := cmd.Process.Kill(); err != nil {
logrus.Warnf("Problem killing process pid=%v: %s", cmd.Process.Pid, err)
klog.Warningf("Problem killing process pid=%v: %s", cmd.Process.Pid, err)
}

}
return "", fmt.Errorf("Timeout executing: %v %v, output %s, stderr, %s, error %v",
return "", fmt.Errorf("timeout executing: %v %v, output %s, stderr, %s, error %v",
binary, args, output.String(), stderr.String(), err)
}

if err != nil {
return "", fmt.Errorf("Failed to execute: %v %v, output %s, stderr, %s, error %v",
return "", fmt.Errorf("failed to execute: %v %v, output %s, stderr, %s, error %v",
binary, args, output.String(), stderr.String(), err)
}
return output.String(), nil
Expand All @@ -256,7 +256,7 @@ func TimestampAfterTimeout(ts string, timeout time.Duration) bool {
now := time.Now()
t, err := time.Parse(time.RFC3339, ts)
if err != nil {
logrus.Errorf("Cannot parse time %v", ts)
klog.Errorf("Cannot parse time %v", ts)
return false
}
deadline := t.Add(timeout)
Expand All @@ -266,7 +266,7 @@ func TimestampAfterTimeout(ts string, timeout time.Duration) bool {
func TimestampWithinLimit(latest time.Time, ts string, limit time.Duration) bool {
t, err := time.Parse(time.RFC3339, ts)
if err != nil {
logrus.Errorf("Cannot parse time %v", ts)
klog.Errorf("Cannot parse time %v", ts)
return false
}
deadline := t.Add(limit)
Expand Down Expand Up @@ -329,7 +329,7 @@ func RegisterShutdownChannel(done chan struct{}) {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
logrus.Infof("Receive %v to exit", sig)
klog.V(2).Infof("Receive %v to exit", sig)
close(done)
}()
}
Expand Down Expand Up @@ -367,14 +367,14 @@ func GetSortedKeysFromMap(maps interface{}) []string {
func AutoCorrectName(name string, maxLength int) string {
newName := strings.ToLower(name)
if len(name) > maxLength {
logrus.Warnf("Name %v is too long, auto-correct to fit %v characters", name, maxLength)
klog.Warningf("Name %v is too long, auto-correct to fit %v characters", name, maxLength)
checksum := GetStringChecksum(name)
newNameSuffix := "-" + checksum[:8]
newNamePrefix := strings.TrimRight(newName[:maxLength-len(newNameSuffix)], "-")
newName = newNamePrefix + newNameSuffix
}
if newName != name {
logrus.Warnf("Name auto-corrected from %v to %v", name, newName)
klog.Warningf("Name auto-corrected from %v to %v", name, newName)
}
return newName
}
Expand Down

0 comments on commit 08a1075

Please sign in to comment.