-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Use keptn/go-utils to access Keptn APIs #767
Changes from all commits
da8b5ec
5431667
b6f1b2c
ff183e8
71525ce
16a9993
c66e7ae
0163882
e7b5355
d079738
9408229
4c13909
efe2b0a
88c48ac
3ff8b54
a3b3d15
1a10843
f7b14ac
c3bd94a
ed26f1e
9fc9cda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ import ( | |
"github.com/keptn/go-utils/pkg/lib/keptn" | ||
) | ||
|
||
const KEPTNSBRIDGE_LABEL = "Keptns Bridge" | ||
const BridgeLabel = "Keptns Bridge" | ||
const ProblemURLLabel = "Problem URL" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golint] reported by reviewdog 🐶 |
||
|
||
// ShipyardControllerURLEnvironmentVariableName is the name of the environment variable for specifying the shipyard controller URL. | ||
const ShipyardControllerURLEnvironmentVariableName = "SHIPYARD_CONTROLLER" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,10 @@ type DynatraceConfigProvider interface { | |
} | ||
|
||
type DynatraceConfigGetter struct { | ||
resourceClient keptn.DynatraceConfigResourceClientInterface | ||
resourceClient keptn.DynatraceConfigReaderInterface | ||
} | ||
|
||
func NewDynatraceConfigGetter(client keptn.DynatraceConfigResourceClientInterface) *DynatraceConfigGetter { | ||
func NewDynatraceConfigGetter(client keptn.DynatraceConfigReaderInterface) *DynatraceConfigGetter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golint] reported by reviewdog 🐶 |
||
return &DynatraceConfigGetter{ | ||
resourceClient: client, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,19 @@ import ( | |
"github.com/keptn-contrib/dynatrace-service/internal/sli" | ||
) | ||
|
||
// ErrorHandler handles errors by trying to send them to Keptn Uniform. | ||
type ErrorHandler struct { | ||
err error | ||
evt cloudevents.Event | ||
err error | ||
evt cloudevents.Event | ||
uniformClient keptn.UniformClientInterface | ||
} | ||
|
||
func NewErrorHandler(err error, event cloudevents.Event) *ErrorHandler { | ||
// NewErrorHandler creates a new ErrorHandler for the specified error, event and UniformClientInterface. | ||
func NewErrorHandler(err error, event cloudevents.Event, uniformClient keptn.UniformClientInterface) *ErrorHandler { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golint] reported by reviewdog 🐶 |
||
return &ErrorHandler{ | ||
err: err, | ||
evt: event, | ||
err: err, | ||
evt: event, | ||
uniformClient: uniformClient, | ||
} | ||
} | ||
|
||
|
@@ -59,8 +63,7 @@ func (eh ErrorHandler) sendErroredGetSLIFinishedEvent(keptnClient *keptn.Client) | |
} | ||
|
||
func (eh ErrorHandler) sendErrorEvent(keptnClient *keptn.Client) error { | ||
uniformClient := keptn.NewDefaultUniformClient() | ||
integrationID, err := uniformClient.GetIntegrationIDFor(event.GetEventSource()) | ||
integrationID, err := eh.uniformClient.GetIntegrationIDByName(event.GetEventSource()) | ||
if err != nil { | ||
log.WithError(err).Error("Could not retrieve integration ID from Keptn Uniform") | ||
// no need to continue here, message will not show up in Uniform | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,13 @@ import ( | |
"fmt" | ||
|
||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
api "github.com/keptn/go-utils/pkg/api/utils" | ||
keptnevents "github.com/keptn/go-utils/pkg/lib" | ||
keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/keptn-contrib/dynatrace-service/internal/adapter" | ||
"github.com/keptn-contrib/dynatrace-service/internal/common" | ||
"github.com/keptn-contrib/dynatrace-service/internal/config" | ||
"github.com/keptn-contrib/dynatrace-service/internal/credentials" | ||
"github.com/keptn-contrib/dynatrace-service/internal/deployment" | ||
|
@@ -20,22 +22,29 @@ import ( | |
"github.com/keptn-contrib/dynatrace-service/internal/sli" | ||
) | ||
|
||
// DynatraceEventHandler is the common interface for all event handlers. | ||
type DynatraceEventHandler interface { | ||
HandleEvent() error | ||
} | ||
|
||
func NewEventHandler(event cloudevents.Event) DynatraceEventHandler { | ||
eventHandler, err := getEventHandler(event) | ||
// NewEventHandler creates a new DynatraceEventHandler for the specified event or returns an error. | ||
func NewEventHandler(event cloudevents.Event) (DynatraceEventHandler, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golint] reported by reviewdog 🐶 |
||
keptnAPISet, err := api.New(common.GetShipyardControllerURL()) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create Keptn API set: %w", err) | ||
} | ||
|
||
eventHandler, err := getEventHandler(event, *keptnAPISet) | ||
if err != nil { | ||
err = fmt.Errorf("cannot handle event: %w", err) | ||
log.Error(err.Error()) | ||
return NewErrorHandler(err, event) | ||
return NewErrorHandler(err, event, keptn.NewUniformClient(keptnAPISet.UniformV1())), nil | ||
} | ||
|
||
return eventHandler | ||
return eventHandler, nil | ||
} | ||
|
||
func getEventHandler(event cloudevents.Event) (DynatraceEventHandler, error) { | ||
func getEventHandler(event cloudevents.Event, keptnAPISet api.APISet) (DynatraceEventHandler, error) { | ||
log.WithField("eventType", event.Type()).Debug("Received event") | ||
|
||
keptnEvent, err := getEventAdapter(event) | ||
|
@@ -52,7 +61,7 @@ func getEventHandler(event cloudevents.Event) (DynatraceEventHandler, error) { | |
return nil, errors.New("event has no project") | ||
} | ||
|
||
dynatraceConfigGetter := config.NewDynatraceConfigGetter(keptn.NewDefaultResourceClient()) | ||
dynatraceConfigGetter := config.NewDynatraceConfigGetter(keptn.NewConfigClient(keptn.NewResourceClient(keptnAPISet.ResourcesV1()))) | ||
dynatraceConfig, err := dynatraceConfigGetter.GetDynatraceConfig(keptnEvent) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not get configuration: %w", err) | ||
|
@@ -77,29 +86,29 @@ func getEventHandler(event cloudevents.Event) (DynatraceEventHandler, error) { | |
|
||
switch aType := keptnEvent.(type) { | ||
case *monitoring.ConfigureMonitoringAdapter: | ||
return monitoring.NewConfigureMonitoringEventHandler(keptnEvent.(*monitoring.ConfigureMonitoringAdapter), dtClient, kClient, keptn.NewDefaultResourceClient(), keptn.NewDefaultServiceClient()), nil | ||
return monitoring.NewConfigureMonitoringEventHandler(keptnEvent.(*monitoring.ConfigureMonitoringAdapter), dtClient, kClient, keptn.NewConfigClient(keptn.NewResourceClient(keptnAPISet.ResourcesV1())), keptn.NewServiceClient(keptnAPISet.ServicesV1(), keptnAPISet.APIV1())), nil | ||
case *problem.ProblemAdapter: | ||
return problem.NewProblemEventHandler(keptnEvent.(*problem.ProblemAdapter), kClient), nil | ||
case *problem.ActionTriggeredAdapter: | ||
return problem.NewActionTriggeredEventHandler(keptnEvent.(*problem.ActionTriggeredAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return problem.NewActionTriggeredEventHandler(keptnEvent.(*problem.ActionTriggeredAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
case *problem.ActionStartedAdapter: | ||
return problem.NewActionStartedEventHandler(keptnEvent.(*problem.ActionStartedAdapter), dtClient, keptn.NewDefaultEventClient()), nil | ||
return problem.NewActionStartedEventHandler(keptnEvent.(*problem.ActionStartedAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1())), nil | ||
case *problem.ActionFinishedAdapter: | ||
return problem.NewActionFinishedEventHandler(keptnEvent.(*problem.ActionFinishedAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return problem.NewActionFinishedEventHandler(keptnEvent.(*problem.ActionFinishedAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
case *sli.GetSLITriggeredAdapter: | ||
return sli.NewGetSLITriggeredHandler(keptnEvent.(*sli.GetSLITriggeredAdapter), dtClient, kClient, keptn.NewDefaultResourceClient(), dynatraceConfig.DtCreds, dynatraceConfig.Dashboard), nil | ||
return sli.NewGetSLITriggeredHandler(keptnEvent.(*sli.GetSLITriggeredAdapter), dtClient, kClient, keptn.NewConfigClient(keptn.NewResourceClient(keptnAPISet.ResourcesV1())), dynatraceConfig.DtCreds, dynatraceConfig.Dashboard), nil | ||
case *deployment.DeploymentFinishedAdapter: | ||
return deployment.NewDeploymentFinishedEventHandler(keptnEvent.(*deployment.DeploymentFinishedAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return deployment.NewDeploymentFinishedEventHandler(keptnEvent.(*deployment.DeploymentFinishedAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
case *deployment.TestTriggeredAdapter: | ||
return deployment.NewTestTriggeredEventHandler(keptnEvent.(*deployment.TestTriggeredAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return deployment.NewTestTriggeredEventHandler(keptnEvent.(*deployment.TestTriggeredAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
case *deployment.TestFinishedAdapter: | ||
return deployment.NewTestFinishedEventHandler(keptnEvent.(*deployment.TestFinishedAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return deployment.NewTestFinishedEventHandler(keptnEvent.(*deployment.TestFinishedAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
case *deployment.EvaluationFinishedAdapter: | ||
return deployment.NewEvaluationFinishedEventHandler(keptnEvent.(*deployment.EvaluationFinishedAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return deployment.NewEvaluationFinishedEventHandler(keptnEvent.(*deployment.EvaluationFinishedAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
case *deployment.ReleaseTriggeredAdapter: | ||
return deployment.NewReleaseTriggeredEventHandler(keptnEvent.(*deployment.ReleaseTriggeredAdapter), dtClient, keptn.NewDefaultEventClient(), dynatraceConfig.AttachRules), nil | ||
return deployment.NewReleaseTriggeredEventHandler(keptnEvent.(*deployment.ReleaseTriggeredAdapter), dtClient, keptn.NewEventClient(keptnAPISet.EventsV1()), dynatraceConfig.AttachRules), nil | ||
default: | ||
return NewErrorHandler(fmt.Errorf("this should not have happened, we are missing an implementation for: %T", aType), event), nil | ||
return NewErrorHandler(fmt.Errorf("this should not have happened, we are missing an implementation for: %T", aType), event, keptn.NewUniformClient(keptnAPISet.UniformV1())), nil | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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 const BridgeLabel should have comment or be unexported