Skip to content

Commit

Permalink
chore: add debug logging for updater (#1353)
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Murray <[email protected]>
  • Loading branch information
dmurray-lacework authored Aug 10, 2023
1 parent 06b851a commit f64f644
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lwupdater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/lacework/go-sdk/lwlogger"
"github.com/pkg/errors"
)

Expand All @@ -43,6 +44,8 @@ const (
DisableEnv = "LW_UPDATES_DISABLE"
)

var log = lwlogger.New("")

// Version is used to check project versions and store it into a cache file
// normally at the directory `~/.config/lacework`, to execute regular version checks
type Version struct {
Expand Down Expand Up @@ -155,6 +158,7 @@ func getGitRelease(project, version string) (*gitReleaseResponse, error) {
return err
}
if resp.StatusCode < 200 || resp.StatusCode > 299 {
logHeaders(resp)
return errors.New(resp.Status)
}
return nil
Expand All @@ -178,6 +182,14 @@ func backoffStrategy() *backoff.ExponentialBackOff {
return strategy
}

func logHeaders(resp *http.Response) {
var headers strings.Builder
for key, values := range resp.Header {
headers.WriteString(fmt.Sprintf("%s: %s\n", key, strings.Join(values, ",")))
}
log.Debug(headers.String())
}

type gitReleaseResponse struct {
ID int32 `json:"id"`
Url string `json:"url"`
Expand Down

0 comments on commit f64f644

Please sign in to comment.