Skip to content

Commit

Permalink
Add logs while making requests (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <[email protected]>
  • Loading branch information
maksim-paskal authored Jan 31, 2024
1 parent ed879b5 commit 5c55633
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,28 @@ func readEndpoint(ctx context.Context, azureResource string) (bool, error) { //n

req.Header.Add("Metadata", "true")

log.WithFields(log.Fields{
"method": req.Method,
"url": req.URL,
"headers": req.Header,
}).Debug("Doing request")

resp, err := httpClient.Do(req)
if err != nil {
return false, errors.Wrap(err, "error in client.Do(req)")
}

defer resp.Body.Close()

log.Debugf("response status: %s", resp.Status)

body, err := io.ReadAll(resp.Body)
if err != nil {
return false, errors.Wrap(err, "error in io.ReadAll")
}

log.Debugf("response body: %s", string(body))

if len(body) == 0 {
log.Warn("Events response is empty")

Expand Down
9 changes: 9 additions & 0 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/maksim-paskal/aks-node-termination-handler/pkg/metrics"
"github.com/maksim-paskal/aks-node-termination-handler/pkg/template"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

var client = &http.Client{
Expand Down Expand Up @@ -69,12 +70,20 @@ func SendWebHook(ctx context.Context, obj *template.MessageType) error {

req.Header.Set("Content-Type", *config.Get().WebHookContentType)

log.WithFields(log.Fields{
"method": req.Method,
"url": req.URL,
"headers": req.Header,
}).Infof("Doing request with body: %s", requestBody.String())

resp, err := client.Do(req)
if err != nil {
return errors.Wrap(err, "error in client.Do")
}
defer resp.Body.Close()

log.Infof("response status: %s", resp.Status)

if resp.StatusCode != http.StatusOK {
return errors.Wrap(errHTTPNotOK, fmt.Sprintf("StatusCode=%d", resp.StatusCode))
}
Expand Down

0 comments on commit 5c55633

Please sign in to comment.