From e5405eb02f48539fa87c635eb865f156ba8fa62f Mon Sep 17 00:00:00 2001 From: Arthur Pitman Date: Tue, 4 Jan 2022 14:06:10 +0100 Subject: [PATCH] fix: Remove automatic configure monitoring for new projects (#661) * Update documentation Signed-off-by: Arthur Pitman * Remove handler and adapter Signed-off-by: Arthur Pitman --- documentation/feature-overview.md | 2 +- internal/event_handler/handler.go | 4 - .../project_create_finished_adapter.go | 104 ------------------ .../project_create_finished_event_handler.go | 44 -------- 4 files changed, 1 insertion(+), 153 deletions(-) delete mode 100644 internal/monitoring/project_create_finished_adapter.go delete mode 100644 internal/monitoring/project_create_finished_event_handler.go diff --git a/documentation/feature-overview.md b/documentation/feature-overview.md index 74f2ef80d..764ecf88b 100644 --- a/documentation/feature-overview.md +++ b/documentation/feature-overview.md @@ -27,4 +27,4 @@ The dynatrace-service listens for the following events: - `sh.keptn.event.release.finished` - `sh.keptn.events.problem` - `sh.keptn.event.monitoring.configure` -- `sh.keptn.event.project.create.finished` + diff --git a/internal/event_handler/handler.go b/internal/event_handler/handler.go index f13320bca..713f17355 100644 --- a/internal/event_handler/handler.go +++ b/internal/event_handler/handler.go @@ -73,8 +73,6 @@ func NewEventHandler(event cloudevents.Event) DynatraceEventHandler { switch aType := keptnEvent.(type) { case *monitoring.ConfigureMonitoringAdapter: return monitoring.NewConfigureMonitoringEventHandler(keptnEvent.(*monitoring.ConfigureMonitoringAdapter), dtClient, kClient, keptn.NewDefaultResourceClient(), keptn.NewDefaultServiceClient()) - case *monitoring.ProjectCreateFinishedAdapter: - return monitoring.NewProjectCreateFinishedEventHandler(keptnEvent.(*monitoring.ProjectCreateFinishedAdapter), dtClient, kClient, keptn.NewDefaultResourceClient(), keptn.NewDefaultServiceClient()) case *problem.ProblemAdapter: return problem.NewProblemEventHandler(keptnEvent.(*problem.ProblemAdapter), kClient) case *problem.ActionTriggeredAdapter: @@ -104,8 +102,6 @@ func getEventAdapter(e cloudevents.Event) (adapter.EventContentAdapter, error) { switch e.Type() { case keptnevents.ConfigureMonitoringEventType: return monitoring.NewConfigureMonitoringAdapterFromEvent(e) - case keptnv2.GetFinishedEventType(keptnv2.ProjectCreateTaskName): - return monitoring.NewProjectCreateFinishedAdapterFromEvent(e) case keptnevents.ProblemEventType: return problem.NewProblemAdapterFromEvent(e) case keptnv2.GetTriggeredEventType(keptnv2.ActionTaskName): diff --git a/internal/monitoring/project_create_finished_adapter.go b/internal/monitoring/project_create_finished_adapter.go deleted file mode 100644 index ff48021cb..000000000 --- a/internal/monitoring/project_create_finished_adapter.go +++ /dev/null @@ -1,104 +0,0 @@ -package monitoring - -import ( - "encoding/base64" - "errors" - cloudevents "github.com/cloudevents/sdk-go/v2" - "github.com/keptn-contrib/dynatrace-service/internal/adapter" - keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0" - log "github.com/sirupsen/logrus" - "gopkg.in/yaml.v2" -) - -type ProjectCreateFinishedAdapterInterface interface { - adapter.EventContentAdapter - - GetShipyard() (*keptnv2.Shipyard, error) -} - -// ProjectCreateFinishedAdapter encapsulates a cloud event and its parsed payload -type ProjectCreateFinishedAdapter struct { - event keptnv2.ProjectCreateFinishedEventData - cloudEvent adapter.CloudEventAdapter -} - -// NewProjectCreateFinishedAdapterFromEvent creates a new ProjectCreateFinishedAdapter from a cloudevents Event -func NewProjectCreateFinishedAdapterFromEvent(e cloudevents.Event) (*ProjectCreateFinishedAdapter, error) { - ceAdapter := adapter.NewCloudEventAdapter(e) - - pcData := &keptnv2.ProjectCreateFinishedEventData{} - err := ceAdapter.PayloadAs(pcData) - if err != nil { - return nil, err - } - - return &ProjectCreateFinishedAdapter{ - *pcData, - ceAdapter, - }, nil -} - -// GetShKeptnContext returns the shkeptncontext -func (a ProjectCreateFinishedAdapter) GetShKeptnContext() string { - return a.cloudEvent.GetShKeptnContext() -} - -// GetSource returns the source specified in the CloudEvent context -func (a ProjectCreateFinishedAdapter) GetSource() string { - return a.cloudEvent.GetSource() -} - -// GetEvent returns the event type -func (a ProjectCreateFinishedAdapter) GetEvent() string { - return keptnv2.GetFinishedEventType(keptnv2.ProjectCreateTaskName) -} - -// GetProject returns the project -func (a ProjectCreateFinishedAdapter) GetProject() string { - return a.event.Project -} - -// GetStage returns the stage -func (a ProjectCreateFinishedAdapter) GetStage() string { - return "" -} - -// GetService returns the service -func (a ProjectCreateFinishedAdapter) GetService() string { - return "" -} - -// GetDeployment returns the name of the deployment -func (a ProjectCreateFinishedAdapter) GetDeployment() string { - return "" -} - -// GetTestStrategy returns the used test strategy -func (a ProjectCreateFinishedAdapter) GetTestStrategy() string { - return "" -} - -// GetDeploymentStrategy returns the used deployment strategy -func (a ProjectCreateFinishedAdapter) GetDeploymentStrategy() string { - return "" -} - -// GetLabels returns a map of labels -func (a ProjectCreateFinishedAdapter) GetLabels() map[string]string { - return nil -} - -func (a ProjectCreateFinishedAdapter) GetShipyard() (*keptnv2.Shipyard, error) { - shipyard := &keptnv2.Shipyard{} - decodedShipyard, err := base64.StdEncoding.DecodeString(a.event.CreatedProject.Shipyard) - if err != nil { - log.WithError(err).Error("Could not decode shipyard") - return nil, errors.New("could not decode Keptn shipyard file") - } - err = yaml.Unmarshal(decodedShipyard, shipyard) - if err != nil { - return nil, errors.New("could not unmarshal Keptn shipyard file") - } - - return shipyard, nil -} diff --git a/internal/monitoring/project_create_finished_event_handler.go b/internal/monitoring/project_create_finished_event_handler.go deleted file mode 100644 index 997c7a1e0..000000000 --- a/internal/monitoring/project_create_finished_event_handler.go +++ /dev/null @@ -1,44 +0,0 @@ -package monitoring - -import ( - log "github.com/sirupsen/logrus" - - "github.com/keptn-contrib/dynatrace-service/internal/dynatrace" - "github.com/keptn-contrib/dynatrace-service/internal/keptn" -) - -type ProjectCreateFinishedEventHandler struct { - event ProjectCreateFinishedAdapterInterface - dtClient dynatrace.ClientInterface - kClient keptn.ClientInterface - sloReader keptn.SLOResourceReaderInterface - serviceClient keptn.ServiceClientInterface -} - -// NewProjectCreateFinishedEventHandler creates a new ProjectCreateFinishedEventHandler -func NewProjectCreateFinishedEventHandler(event ProjectCreateFinishedAdapterInterface, dtClient dynatrace.ClientInterface, kClient keptn.ClientInterface, sloReader keptn.SLOResourceReaderInterface, serviceClient keptn.ServiceClientInterface) ProjectCreateFinishedEventHandler { - return ProjectCreateFinishedEventHandler{ - event: event, - dtClient: dtClient, - kClient: kClient, - sloReader: sloReader, - serviceClient: serviceClient, - } -} - -func (eh ProjectCreateFinishedEventHandler) HandleEvent() error { - shipyard, err := eh.event.GetShipyard() - if err != nil { - log.WithError(err).Error("Could not load Keptn shipyard file") - } - - cfg := NewConfiguration(eh.dtClient, eh.kClient, eh.sloReader, eh.serviceClient) - - _, err = cfg.ConfigureMonitoring(eh.event.GetProject(), shipyard) - if err != nil { - return err - } - - log.Info("Dynatrace Monitoring setup done") - return nil -}