Skip to content

Commit

Permalink
[SRE-221] Reduce logs printend on the default verbosity level
Browse files Browse the repository at this point in the history
  • Loading branch information
pwilczynskiclearcode committed Jan 3, 2024
1 parent 32d49b1 commit 3b39db8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions catalyst-uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"encoding/json"
"flag"
"log"
"os"
"time"

"github.com/golang/glog"

Check failure on line 9 in catalyst-uploader.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

missing go.sum entry for module providing package github.com/golang/glog (imported by github.com/livepeer/catalyst-uploader); to add:

Check failure on line 9 in catalyst-uploader.go

View workflow job for this annotation

GitHub Actions / Build binaries for linux-arm64

missing go.sum entry for module providing package github.com/golang/glog (imported by github.com/livepeer/catalyst-uploader); to add:

Check failure on line 9 in catalyst-uploader.go

View workflow job for this annotation

GitHub Actions / Build binaries for darwin-arm64

missing go.sum entry for module providing package github.com/golang/glog (imported by github.com/livepeer/catalyst-uploader); to add:

Check failure on line 9 in catalyst-uploader.go

View workflow job for this annotation

GitHub Actions / Build binaries for linux-amd64

missing go.sum entry for module providing package github.com/golang/glog (imported by github.com/livepeer/catalyst-uploader); to add:

Check failure on line 9 in catalyst-uploader.go

View workflow job for this annotation

GitHub Actions / Build binaries for darwin-amd64

missing go.sum entry for module providing package github.com/golang/glog (imported by github.com/livepeer/catalyst-uploader); to add:
"github.com/livepeer/catalyst-uploader/core"
"github.com/livepeer/go-tools/drivers"
)
Expand All @@ -32,7 +32,7 @@ func run() int {
}

if flag.NArg() == 0 {
log.Fatal("Destination URI is not specified. See -h for usage.")
glog.Fatal("Destination URI is not specified. See -h for usage.")
return 1
}

Expand All @@ -42,20 +42,20 @@ func run() int {

uri := flag.Arg(0)
if uri == "" {
log.Fatalf("Could not parse object store URI: %s", uri)
glog.Fatalf("Could not parse object store URI: %s", uri)
return 1
}

err := core.Upload(os.Stdin, uri, WaitBetweenWrites, *timeout)
if err != nil {
log.Fatalf("Uploader failed for %s: %s", uri, err)
glog.Fatalf("Uploader failed for %s: %s", uri, err)
return 1
}

// success, write uploaded file details to stdout
err = json.NewEncoder(stdout).Encode(map[string]string{"uri": uri})
if err != nil {
log.Println(err)
glog.Println(err)
return 1
}

Expand Down
14 changes: 7 additions & 7 deletions core/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"context"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/golang/glog"
"github.com/livepeer/go-tools/drivers"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t
err = backoff.Retry(func() error {
_, err := session.SaveData(context.Background(), "", bytes.NewReader(fileContents), fields, writeTimeout)
if err != nil {
log.Printf("failed upload attempt: %s", err)
glog.Errorf("failed upload attempt: %v", err)
}
return err
}, UploadRetryBackoff())
Expand All @@ -71,7 +71,7 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t
}

if err = extractThumb(session, outputURI, fileContents); err != nil {
log.Printf("extracting thumbnail failed: %s", err)
glog.Errorf("extracting thumbnail failed: %v", err)
}
return nil
}
Expand Down Expand Up @@ -99,16 +99,16 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t
b := scanner.Bytes()
fileContents = append(fileContents, b...)
if strings.Contains(outputURI, "m3u8") {
log.Printf("Received new bytes for %s: %s", outputURI, string(b))
glog.V(5).Infof("Received new bytes for %s: %s", outputURI, string(b))
}

// Only write the latest version of the data that's been piped in if enough time has elapsed since the last write
if lastWrite.Add(waitBetweenWrites).Before(time.Now()) {
if _, err := session.SaveData(context.Background(), "", bytes.NewReader(fileContents), fields, writeTimeout); err != nil {
// Just log this error, since it'll effectively be retried after the next interval
log.Printf("Failed to write: %s", err)
glog.Errorf("Failed to write: %v", err)
} else {
log.Printf("Wrote %s to storage: %d bytes", outputURI, len(b))
glog.V(5).Infof("Wrote %s to storage: %d bytes", outputURI, len(b))
}
lastWrite = time.Now()
}
Expand All @@ -122,7 +122,7 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t
// Don't ignore this error, since there won't be any further attempts to write
return fmt.Errorf("failed to write final save: %w", err)
}

glog.Infof("Completed writing %s to storage", outputURI)
return nil
}

Expand Down

0 comments on commit 3b39db8

Please sign in to comment.