From e0909852e92261fd1fc6a6cc2621c300b6075af3 Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Mon, 20 May 2024 11:19:34 +0300 Subject: [PATCH] minor clean up Signed-off-by: Bella Khizgiyaev --- cmd/virt-v2v-monitor/BUILD.bazel | 1 - cmd/virt-v2v-monitor/virt-v2v-monitor.go | 49 ++++++------------------ virt-v2v/cold/entrypoint.go | 5 +-- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/cmd/virt-v2v-monitor/BUILD.bazel b/cmd/virt-v2v-monitor/BUILD.bazel index 2963bbc3f..f5ab459f1 100644 --- a/cmd/virt-v2v-monitor/BUILD.bazel +++ b/cmd/virt-v2v-monitor/BUILD.bazel @@ -15,6 +15,5 @@ go_library( "//vendor/github.com/prometheus/client_golang/prometheus", "//vendor/github.com/prometheus/client_golang/prometheus/promhttp", "//vendor/github.com/prometheus/client_model/go", - "//vendor/k8s.io/klog/v2:klog", ], ) diff --git a/cmd/virt-v2v-monitor/virt-v2v-monitor.go b/cmd/virt-v2v-monitor/virt-v2v-monitor.go index d72543162..43b4dd45e 100644 --- a/cmd/virt-v2v-monitor/virt-v2v-monitor.go +++ b/cmd/virt-v2v-monitor/virt-v2v-monitor.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "flag" "fmt" "net/http" "os" @@ -12,7 +11,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" dto "github.com/prometheus/client_model/go" - "k8s.io/klog/v2" ) var COPY_DISK_RE = regexp.MustCompile(`^.*Copying disk (\d+)/(\d+)`) @@ -52,28 +50,15 @@ func updateProgress(progressCounter *prometheus.CounterVec, disk, progress uint6 change := float64(progress) - previous_progress if change > 0 { - klog.Infof("Progress changed for disk %d about %v", disk, change) + fmt.Printf("virt-v2v monitoring: Progress changed for disk %d about %v\n", disk, change) progressCounter.WithLabelValues(label).Add(change) } return } -func NewBufferedScanner(r *bufio.Reader, bufferSize int) *bufio.Scanner { - scanner := bufio.NewScanner(r) - buf := make([]byte, bufferSize) - scanner.Buffer(buf, bufferSize) - scanner.Split(LimitedScanLines) - return scanner -} - func main() { - klog.InitFlags(nil) - defer klog.Flush() - flag.Parse() - // Start prometheus metrics HTTP handler - klog.Info("Setting up prometheus endpoint :2112/metrics") - klog.Info("this is Bella test") + fmt.Println("virt-v2v monitoring: Setting up prometheus endpoint :2112/metrics") http.Handle("/metrics", promhttp.Handler()) go http.ListenAndServe(":2112", nil) @@ -88,62 +73,52 @@ func main() { if err := prometheus.Register(progressCounter); err != nil { // Exit gracefully if we fail here. We don't need monitoring // failures to hinder guest conversion. - klog.Error("Prometheus progress counter not registered:", err) + fmt.Println("virt-v2v monitoring: Prometheus progress counter not registered:", err) return } - klog.Info("Prometheus progress counter registered.") + fmt.Println("virt-v2v monitoring: Prometheus progress counter registered.") var diskNumber uint64 = 0 var disks uint64 = 0 var progress uint64 = 0 - reader := bufio.NewReader(os.Stdin) - scanner := NewBufferedScanner(reader, 1*1024*1024) - fmt.Println("Arik") + scanner := bufio.NewScanner(os.Stdin) + scanner.Split(LimitedScanLines) for scanner.Scan() { line := scanner.Bytes() os.Stdout.Write(line) os.Stdout.Write([]byte("\n")) err := scanner.Err() if err != nil { - klog.Fatal("Output monitoring failed! ", err) + fmt.Println("virt-v2v monitoring: Output monitoring failed! ", err) } - //fmt.Println("this is the line we scanning now ", string(line)) - if match := COPY_DISK_RE.FindSubmatch(line); match != nil { diskNumber, _ = strconv.ParseUint(string(match[1]), 10, 0) disks, _ = strconv.ParseUint(string(match[2]), 10, 0) - //klog.Infof("Copying disk %d out of %d", diskNumber, disks) - fmt.Printf("Copying disk %d out of %d", diskNumber, disks) + fmt.Printf("virt-v2v monitoring: Copying disk %d out of %d\n", diskNumber, disks) progress = 0 err = updateProgress(progressCounter, diskNumber, progress) } else if match := DISK_PROGRESS_RE.FindSubmatch(line); match != nil { - //klog.Info("we are here at progress ", line) - fmt.Printf("we are here at progress line=%s match-0=%s match-1=%s\n", string(line), string(match[0]), string(match[1])) progress, _ = strconv.ParseUint(string(match[1]), 10, 0) - //klog.Infof("Progress update, completed %d %%", progress) - fmt.Printf("Progress update, completed %d %%\n", progress) + fmt.Printf("virt-v2v monitoring: Progress update, completed %d %%\n", progress) err = updateProgress(progressCounter, diskNumber, progress) } else if match := FINISHED_RE.Find(line); match != nil { // Make sure we flag conversion as finished. This is // just in case we miss the last progress update for some reason. - //klog.Infof("Finished") - fmt.Printf("Finished\n") + fmt.Println("virt-v2v monitoring: Finished") for disk := uint64(0); disk < disks; disk++ { err = updateProgress(progressCounter, disk, 100) } - } else { - klog.Infof("Ignoring line: ", string(line)) } if err != nil { // Don't make processing errors fatal. - klog.Error("Error updating progress: ", err) + fmt.Println("virt-v2v monitoring: Error updating progress: ", err) err = nil } } err := scanner.Err() if err != nil { - klog.Fatal("Output monitoring failed! ", err) + fmt.Println("virt-v2v monitoring: Output monitoring failed! ", err) } } diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index 21e6a4e69..be2a37667 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -198,6 +198,7 @@ func executeVirtV2v(source string, args []string) (err error) { virtV2vCmd.Stdout = w virtV2vCmd.Stderr = w + fmt.Println("exec ", virtV2vCmd) if err = virtV2vCmd.Start(); err != nil { fmt.Printf("Error executing command: %v\n", err) return @@ -205,8 +206,6 @@ func executeVirtV2v(source string, args []string) (err error) { virtV2vMonitorCmd := exec.Command("/usr/local/bin/virt-v2v-monitor") virtV2vMonitorCmd.Stdin = r - //k, _ := virtV2vMonitorCmd.StderrPipe() - //r2 := io.TeeReader(k, os.Stderr) virtV2vMonitorCmd.Stdout = os.Stdout if err = virtV2vMonitorCmd.Start(); err != nil { @@ -215,7 +214,7 @@ func executeVirtV2v(source string, args []string) (err error) { } if source == OVA { - scanner := bufio.NewScanner(nil) + scanner := bufio.NewScanner(r) const maxCapacity = 1024 * 1024 buf := make([]byte, 0, 64*1024) scanner.Buffer(buf, maxCapacity)