From 8eb364afa765ba7a788071ff18a12078ec15e327 Mon Sep 17 00:00:00 2001 From: "Yusuf A. Hasan Miyan" Date: Mon, 21 Oct 2024 21:04:21 +0400 Subject: [PATCH] chore: added debug to lagoon problems --- pkg/lagoon/lagoon.go | 3 +++ pkg/lagoon/problems.go | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/lagoon/lagoon.go b/pkg/lagoon/lagoon.go index 40d29ef..773be47 100644 --- a/pkg/lagoon/lagoon.go +++ b/pkg/lagoon/lagoon.go @@ -94,6 +94,9 @@ func ProblemsToInsightsRemote(problems []Problem, serviceEndpoint string, bearer return err } + log.WithField("body", string(bodyString)). + Trace("sending problems to Lagoon Insights") + req, _ := http.NewRequest(http.MethodPost, serviceEndpoint, bytes.NewBuffer(bodyString)) req.Header.Set("Authorization", bearerToken) req.Header.Set("Content-Type", "application/json") diff --git a/pkg/lagoon/problems.go b/pkg/lagoon/problems.go index d9ab643..13daaf5 100644 --- a/pkg/lagoon/problems.go +++ b/pkg/lagoon/problems.go @@ -30,14 +30,14 @@ type Lagoon struct { InsightsRemoteEndpoint string `yaml:"insights-remote-endpoint"` // Source can be specified when pushing Problems to Lagoon. - // Default is "shipshape". + // Default is "Shipshape". Source string `yaml:"source"` Project string `yaml:"project"` Environment string `yaml:"environment"` } -var l = &Lagoon{Source: "shipshape"} +var l = &Lagoon{Source: "Shipshape"} func init() { output.Outputters["lagoon"] = l @@ -45,14 +45,27 @@ func init() { func (p *Lagoon) Output(rl *result.ResultList) ([]byte, error) { if !p.PushProblemsToInsightsRemote { + log.Debug("skipping pushing problems to Lagoon") return nil, nil } + log.WithFields(log.Fields{ + "insights-remote-endpoint": p.InsightsRemoteEndpoint, + "project": p.Project, + "environment": p.Environment, + "source": p.Source, + }).Debug("pushing problems to Lagoon") buf := bytes.Buffer{} bufW := bufio.NewWriter(&buf) problems := []Problem{} if rl.TotalBreaches == 0 { + log.WithFields(log.Fields{ + "project": p.Project, + "environment": p.Environment, + "source": p.Source, + }).Debug("cleaning up existing problems") + InitClient(p.ApiBaseUrl, p.ApiToken) err := p.DeleteProblems() if err != nil { @@ -106,6 +119,12 @@ func (p *Lagoon) Output(rl *result.ResultList) ([]byte, error) { } func (p *Lagoon) DeleteProblems() error { + log.WithFields(log.Fields{ + "project": p.Project, + "environment": p.Environment, + "source": p.Source, + }).Debug("deleting problems from Lagoon") + envId, err := GetEnvironmentId(p.Project, p.Environment) if err != nil { return err