Skip to content

Commit

Permalink
chore: added debug to lagoon problems
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufhm committed Oct 22, 2024
1 parent 85b56d3 commit 8eb364a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/lagoon/lagoon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 21 additions & 2 deletions pkg/lagoon/problems.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,42 @@ 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
}

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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8eb364a

Please sign in to comment.