Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

feat: Add context to Keptn clients #792

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

arthurpitman
Copy link
Collaborator

Addresses #729

log "github.com/sirupsen/logrus"
)

type ActionFinishedEventHandler struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported type ActionFinishedEventHandler should have comment or be unexported

log "github.com/sirupsen/logrus"
)

type ActionFinishedEventHandler struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
type name will be used as action.ActionFinishedEventHandler by other packages, and that stutters; consider calling this FinishedEventHandler

"github.com/keptn-contrib/dynatrace-service/internal/keptn"
)

type TestFinishedEventHandler struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported type TestFinishedEventHandler should have comment or be unexported

}

// HealthEndpoint is a HTTP server that offers a health endpoint.
type HealthEndpoint struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
type name will be used as health.HealthEndpoint by other packages, and that stutters; consider calling this Endpoint

@@ -96,35 +97,35 @@ func NewDefaultClient(event event.Event) (*Client, error) {
return NewClient(kClient), nil
}

func (c *Client) GetCustomQueries(project string, stage string, service string) (*CustomQueries, error) {
func (c *Client) GetCustomQueries(ctx context.Context, project string, stage string, service string) (*CustomQueries, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method Client.GetCustomQueries should have comment or be unexported

if err != nil {
return nil, err
}

return &CustomQueries{values: customQueries}, nil
}

func (c *Client) GetShipyard() (*keptnv2.Shipyard, error) {
shipyard, err := c.client.GetShipyard()
func (c *Client) GetShipyard(ctx context.Context) (*keptnv2.Shipyard, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method Client.GetShipyard should have comment or be unexported

if err != nil {
return nil, fmt.Errorf("failed to retrieve shipyard for project %s: %v", c.client.Event.GetProject(), err)
}

return shipyard, nil
}

func (c *Client) SendCloudEvent(factory adapter.CloudEventFactoryInterface) error {
func (c *Client) SendCloudEvent(ctx context.Context, factory adapter.CloudEventFactoryInterface) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method Client.SendCloudEvent should have comment or be unexported

func (s *ServiceSynchronizer) Run() {
// Run runs the service synchronizer which does not return unless cancelled.
// Cancelling runCtx will stop any new synchronization runs, cancelling synchronizationCtx will stop an in progress synchronization.
func (s *ServiceSynchronizer) Run(runCtx context.Context, synchronizationCtx context.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch from df8981b to 5d067ac Compare May 3, 2022 12:08
cmd/main.go Outdated
return 0
}

func gotEvent(ctx context.Context, event cloudevents.Event) error {
err := event_handler.NewEventHandler(event).HandleEvent()
func gotEvent(workCtx context.Context, replyCtx context.Context, event cloudevents.Event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

}

// HandleEvent handles an action finished event.
func (eh *ActionFinishedEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

func (eh *ActionStartedEventHandler) HandleEvent() error {
pid, err := eh.eClient.FindProblemID(eh.event)
// HandleEvent handles an action started event.
func (eh *ActionStartedEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

func (eh *ActionTriggeredEventHandler) HandleEvent() error {
pid, err := eh.eClient.FindProblemID(eh.event)
// HandleEvent handles an action triggered event.
func (eh *ActionTriggeredEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

}

// HandleEvent handles a deployment finished event.
func (eh *DeploymentFinishedEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

@@ -28,7 +30,8 @@ func NewErrorHandler(err error, event cloudevents.Event, uniformClient keptn.Uni
}
}

func (eh ErrorHandler) HandleEvent() error {
// HandleEvent handles errors by sending an error event.
func (eh ErrorHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

type NoOpHandler struct {
}

func (eh NoOpHandler) HandleEvent() error {
// HandleEvent handles an event by doing nothing.
func (eh NoOpHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

func (eh ConfigureMonitoringEventHandler) HandleEvent() error {
err := eh.configureMonitoring()
// HandleEvent handles a configure monitoring event.
func (eh ConfigureMonitoringEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

@@ -37,24 +39,25 @@ type RemediationTriggeredEventData struct {
Problem RawProblem `json:"problem"`
}

func (eh ProblemEventHandler) HandleEvent() error {
// HandleEvent handles a problem event.
func (eh ProblemEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

@@ -42,13 +43,14 @@ func NewGetSLITriggeredHandler(event GetSLITriggeredAdapterInterface, dtClient d
}
}

func (eh GetSLIEventHandler) HandleEvent() error {
// HandleEvent handles a get-SLI triggered event.
func (eh GetSLIEventHandler) HandleEvent(workCtx context.Context, replyCtx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

"time"
)

func ThenWithTimeout(parent context.Context, waitCtx context.Context, timeout time.Duration) (context.Context, func()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

"time"
)

func ThenWithTimeout(parent context.Context, waitCtx context.Context, timeout time.Duration) (context.Context, func()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ThenWithTimeout should have comment or be unexported

)

// newThenWithTimeoutContext creates a new Context that is done after timeout after waitCtx is done or if parentCtx is done. It returns the new context and a function that cancels the context.
func newThenWithTimeoutContext(parentCtx context.Context, waitCtx context.Context, timeout time.Duration, name string) (context.Context, func()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch from cbcd8c7 to 714440d Compare May 4, 2022 06:50
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 14 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch from 714440d to ce669df Compare June 10, 2022 15:47
cmd/main.go Outdated
}
}

func gotEvent(workCtx context.Context, replyCtx context.Context, keptnClient *keptn.Client, event cloudevents.Event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
context.Context should be the first parameter of a function

@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch from ce669df to ca2517d Compare June 14, 2022 12:01
@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch from eae87fa to 241ec09 Compare June 28, 2022 08:49
@@ -59,7 +59,7 @@ func (eh *ConfigureMonitoringEventHandler) configureMonitoring(ctx context.Conte
keptnCredentialsCheckResult := eh.checkKeptnCredentials(ctx)
log.WithField("result", keptnCredentialsCheckResult).Info("Checked Keptn credentials")

shipyard, err := eh.shipyardReader.GetShipyard(eh.event.GetProject())
shipyard, err := eh.shipyardReader.GetShipyard(ctx, eh.event.GetProject())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golangci-lint] reported by reviewdog 🐶
eh.event.GetProject undefined (type ConfigureMonitoringAdapterInterface has no field or method GetProject) (typecheck)

@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch 2 times, most recently from 281e2f3 to 07d3499 Compare June 29, 2022 08:08
@arthurpitman arthurpitman force-pushed the feature/729/add-context-to-keptn-clients branch from 07d3499 to a2c8600 Compare June 29, 2022 08:10
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link
Contributor

The following Docker Images have been built:
keptncontrib/dynatrace-service:0.23.0-dev-PR-792,keptncontrib/dynatrace-service:0.23.0-dev-PR-792.202206290811

@arthurpitman arthurpitman marked this pull request as ready for review June 29, 2022 08:14
Copy link
Contributor

@j-poecher j-poecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@arthurpitman arthurpitman merged commit 2408c78 into master Jun 29, 2022
@arthurpitman arthurpitman deleted the feature/729/add-context-to-keptn-clients branch June 29, 2022 11:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants