Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ genrule(
# gazelle:exclude pkg/model/common.pb.validate.go
# gazelle:exclude pkg/model/deployment.pb.validate.go
# gazelle:exclude pkg/model/environment.pb.validate.go
# gazelle:exclude pkg/model/event.pb.validate.go
# gazelle:exclude pkg/model/imagereference.pb.validate.go
# gazelle:exclude pkg/model/insight.pb.validate.go
# gazelle:exclude pkg/model/logblock.pb.validate.go
# gazelle:exclude pkg/model/notificationevent.pb.validate.go
# gazelle:exclude pkg/model/piped.pb.validate.go
# gazelle:exclude pkg/model/piped_stats.pb.validate.go
# gazelle:exclude pkg/model/project.pb.validate.go
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type liveResourceLister interface {
}

type notifier interface {
Notify(event model.Event)
Notify(event model.NotificationEvent)
}

type sealedSecretDecrypter interface {
Expand Down
18 changes: 9 additions & 9 deletions pkg/app/piped/controller/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ func (p *planner) reportDeploymentPlanned(ctx context.Context, runningCommitHash
)

defer func() {
p.notifier.Notify(model.Event{
Type: model.EventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.EventDeploymentPlanned{
p.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.NotificationEventDeploymentPlanned{
Deployment: p.deployment,
EnvName: p.envName,
Summary: out.Summary,
Expand Down Expand Up @@ -254,9 +254,9 @@ func (p *planner) reportDeploymentFailed(ctx context.Context, reason string) err
)

defer func() {
p.notifier.Notify(model.Event{
Type: model.EventType_EVENT_DEPLOYMENT_FAILED,
Metadata: &model.EventDeploymentFailed{
p.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_FAILED,
Metadata: &model.NotificationEventDeploymentFailed{
Deployment: p.deployment,
EnvName: p.envName,
Reason: reason,
Expand Down Expand Up @@ -292,9 +292,9 @@ func (p *planner) reportDeploymentCancelled(ctx context.Context, commander, reas
)

defer func() {
p.notifier.Notify(model.Event{
Type: model.EventType_EVENT_DEPLOYMENT_CANCELLED,
Metadata: &model.EventDeploymentCancelled{
p.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_CANCELLED,
Metadata: &model.NotificationEventDeploymentCancelled{
Deployment: p.deployment,
EnvName: p.envName,
Commander: commander,
Expand Down
18 changes: 9 additions & 9 deletions pkg/app/piped/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,28 +581,28 @@ func (s *scheduler) reportDeploymentCompleted(ctx context.Context, status model.
defer func() {
switch status {
case model.DeploymentStatus_DEPLOYMENT_SUCCESS:
s.notifier.Notify(model.Event{
Type: model.EventType_EVENT_DEPLOYMENT_SUCCEEDED,
Metadata: &model.EventDeploymentSucceeded{
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED,
Metadata: &model.NotificationEventDeploymentSucceeded{
Deployment: s.deployment,
EnvName: s.envName,
},
})

case model.DeploymentStatus_DEPLOYMENT_FAILURE:
s.notifier.Notify(model.Event{
Type: model.EventType_EVENT_DEPLOYMENT_FAILED,
Metadata: &model.EventDeploymentFailed{
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_FAILED,
Metadata: &model.NotificationEventDeploymentFailed{
Deployment: s.deployment,
EnvName: s.envName,
Reason: desc,
},
})

case model.DeploymentStatus_DEPLOYMENT_CANCELLED:
s.notifier.Notify(model.Event{
Type: model.EventType_EVENT_DEPLOYMENT_CANCELLED,
Metadata: &model.EventDeploymentCancelled{
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_CANCELLED,
Metadata: &model.NotificationEventDeploymentCancelled{
Deployment: s.deployment,
EnvName: s.envName,
Commander: cancelCommander,
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/notifier/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type envNameMetadata interface {
GetEnvName() string
}

func (m *matcher) Match(event model.Event) bool {
func (m *matcher) Match(event model.NotificationEvent) bool {
if _, ok := m.ignoreEvents[event.Type.String()]; ok {
return false
}
Expand Down
54 changes: 27 additions & 27 deletions pkg/app/piped/notifier/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func TestMatch(t *testing.T) {
testcases := []struct {
name string
config config.NotificationRoute
matchings map[model.Event]bool
matchings map[model.NotificationEvent]bool
}{
{
name: "empty config",
config: config.NotificationRoute{},
matchings: map[model.Event]bool{
matchings: map[model.NotificationEvent]bool{
{}: true,
{Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED}: true,
{Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED}: true,
},
},
{
Expand All @@ -47,12 +47,12 @@ func TestMatch(t *testing.T) {
"DEPLOYMENT_ROLLING_BACK",
},
},
matchings: map[model.Event]bool{
matchings: map[model.NotificationEvent]bool{
{
Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED,
Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED,
}: true,
{
Type: model.EventType_EVENT_DEPLOYMENT_ROLLING_BACK,
Type: model.NotificationEventType_EVENT_DEPLOYMENT_ROLLING_BACK,
}: false,
},
},
Expand All @@ -66,12 +66,12 @@ func TestMatch(t *testing.T) {
"APPLICATION",
},
},
matchings: map[model.Event]bool{
matchings: map[model.NotificationEvent]bool{
{
Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED,
Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED,
}: true,
{
Type: model.EventType_EVENT_APPLICATION_SYNCED,
Type: model.NotificationEventType_EVENT_APPLICATION_SYNCED,
}: false,
},
},
Expand All @@ -85,34 +85,34 @@ func TestMatch(t *testing.T) {
"bluegreen",
},
},
matchings: map[model.Event]bool{
matchings: map[model.NotificationEvent]bool{
{
Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED,
Metadata: &model.EventDeploymentTriggered{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED,
Metadata: &model.NotificationEventDeploymentTriggered{
Deployment: &model.Deployment{
ApplicationName: "canary",
},
},
}: true,
{
Type: model.EventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.EventDeploymentTriggered{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.NotificationEventDeploymentTriggered{
Deployment: &model.Deployment{
ApplicationName: "bluegreen",
},
},
}: false,
{
Type: model.EventType_EVENT_DEPLOYMENT_SUCCEEDED,
Metadata: &model.EventDeploymentTriggered{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED,
Metadata: &model.NotificationEventDeploymentTriggered{
Deployment: &model.Deployment{
ApplicationName: "not-specified",
},
},
}: false,
{
Type: model.EventType_EVENT_PIPED_STARTED,
Metadata: &model.EventPipedStarted{},
Type: model.NotificationEventType_EVENT_PIPED_STARTED,
Metadata: &model.NotificationEventPipedStarted{},
}: true,
},
},
Expand All @@ -126,37 +126,37 @@ func TestMatch(t *testing.T) {
"dev",
},
},
matchings: map[model.Event]bool{
matchings: map[model.NotificationEvent]bool{
{
Type: model.EventType_EVENT_DEPLOYMENT_TRIGGERED,
Metadata: &model.EventDeploymentTriggered{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED,
Metadata: &model.NotificationEventDeploymentTriggered{
Deployment: &model.Deployment{
EnvId: "prod-id",
},
EnvName: "prod",
},
}: true,
{
Type: model.EventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.EventDeploymentTriggered{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.NotificationEventDeploymentTriggered{
Deployment: &model.Deployment{
EnvId: "dev-id",
},
EnvName: "dev",
},
}: false,
{
Type: model.EventType_EVENT_DEPLOYMENT_SUCCEEDED,
Metadata: &model.EventDeploymentTriggered{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED,
Metadata: &model.NotificationEventDeploymentTriggered{
Deployment: &model.Deployment{
EnvId: "not-specified",
},
EnvName: "not-specified",
},
}: false,
{
Type: model.EventType_EVENT_PIPED_STARTED,
Metadata: &model.EventPipedStarted{},
Type: model.NotificationEventType_EVENT_PIPED_STARTED,
Metadata: &model.NotificationEventPipedStarted{},
}: true,
},
},
Expand Down
16 changes: 8 additions & 8 deletions pkg/app/piped/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type handler struct {

type sender interface {
Run(ctx context.Context) error
Notify(event model.Event)
Notify(event model.NotificationEvent)
Close(ctx context.Context)
}

Expand Down Expand Up @@ -99,9 +99,9 @@ func (n *Notifier) Run(ctx context.Context) error {
}

// Send the PIPED_STARTED event.
n.Notify(model.Event{
Type: model.EventType_EVENT_PIPED_STARTED,
Metadata: &model.EventPipedStarted{
n.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_PIPED_STARTED,
Metadata: &model.NotificationEventPipedStarted{
Id: n.config.PipedID,
Version: version.Get().Version,
},
Expand All @@ -114,9 +114,9 @@ func (n *Notifier) Run(ctx context.Context) error {
}

// Send the PIPED_STOPPED event.
n.Notify(model.Event{
Type: model.EventType_EVENT_PIPED_STOPPED,
Metadata: &model.EventPipedStopped{
n.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_PIPED_STOPPED,
Metadata: &model.NotificationEventPipedStopped{
Id: n.config.PipedID,
Version: version.Get().Version,
},
Expand All @@ -136,7 +136,7 @@ func (n *Notifier) Run(ctx context.Context) error {
return nil
}

func (n *Notifier) Notify(event model.Event) {
func (n *Notifier) Notify(event model.NotificationEvent) {
if n.closed.Load() {
n.logger.Warn("ignore an event because notifier is already closed", zap.String("type", event.Type.String()))
return
Expand Down
38 changes: 19 additions & 19 deletions pkg/app/piped/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type slack struct {
config config.NotificationReceiverSlack
webURL string
httpClient *http.Client
eventCh chan model.Event
eventCh chan model.NotificationEvent
logger *zap.Logger
}

Expand All @@ -56,7 +56,7 @@ func newSlackSender(name string, cfg config.NotificationReceiverSlack, webURL st
httpClient: &http.Client{
Timeout: 5 * time.Second,
},
eventCh: make(chan model.Event, 100),
eventCh: make(chan model.NotificationEvent, 100),
logger: logger.Named("slack"),
}
}
Expand All @@ -74,7 +74,7 @@ func (s *slack) Run(ctx context.Context) error {
}
}

func (s *slack) Notify(event model.Event) {
func (s *slack) Notify(event model.NotificationEvent) {
s.eventCh <- event
}

Expand All @@ -95,7 +95,7 @@ func (s *slack) Close(ctx context.Context) {
}
}

func (s *slack) sendEvent(ctx context.Context, event model.Event) {
func (s *slack) sendEvent(ctx context.Context, event model.NotificationEvent) {
msg, ok := s.buildSlackMessage(event, s.webURL)
if !ok {
s.logger.Info(fmt.Sprintf("ignore event %s", event.Type.String()))
Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *slack) sendMessage(ctx context.Context, msg slackMessage) error {
return nil
}

func (s *slack) buildSlackMessage(event model.Event, webURL string) (slackMessage, bool) {
func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string) (slackMessage, bool) {
var (
title, link, text string
color = slackInfoColor
Expand Down Expand Up @@ -159,44 +159,44 @@ func (s *slack) buildSlackMessage(event model.Event, webURL string) (slackMessag
}

switch event.Type {
case model.EventType_EVENT_DEPLOYMENT_TRIGGERED:
md := event.Metadata.(*model.EventDeploymentTriggered)
case model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED:
md := event.Metadata.(*model.NotificationEventDeploymentTriggered)
title = fmt.Sprintf("Triggered a new deployment for %q", md.Deployment.ApplicationName)
generateDeploymentEventData(md.Deployment, md.EnvName)

case model.EventType_EVENT_DEPLOYMENT_PLANNED:
md := event.Metadata.(*model.EventDeploymentPlanned)
case model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED:
md := event.Metadata.(*model.NotificationEventDeploymentPlanned)
title = fmt.Sprintf("Deployment for %q was planned", md.Deployment.ApplicationName)
text = md.Summary
generateDeploymentEventData(md.Deployment, md.EnvName)

case model.EventType_EVENT_DEPLOYMENT_SUCCEEDED:
md := event.Metadata.(*model.EventDeploymentSucceeded)
case model.NotificationEventType_EVENT_DEPLOYMENT_SUCCEEDED:
md := event.Metadata.(*model.NotificationEventDeploymentSucceeded)
title = fmt.Sprintf("Deployment for %q was completed successfully", md.Deployment.ApplicationName)
color = slackSuccessColor
generateDeploymentEventData(md.Deployment, md.EnvName)

case model.EventType_EVENT_DEPLOYMENT_FAILED:
md := event.Metadata.(*model.EventDeploymentFailed)
case model.NotificationEventType_EVENT_DEPLOYMENT_FAILED:
md := event.Metadata.(*model.NotificationEventDeploymentFailed)
title = fmt.Sprintf("Deployment for %q was failed", md.Deployment.ApplicationName)
text = md.Reason
color = slackErrorColor
generateDeploymentEventData(md.Deployment, md.EnvName)

case model.EventType_EVENT_DEPLOYMENT_CANCELLED:
md := event.Metadata.(*model.EventDeploymentCancelled)
case model.NotificationEventType_EVENT_DEPLOYMENT_CANCELLED:
md := event.Metadata.(*model.NotificationEventDeploymentCancelled)
title = fmt.Sprintf("Deployment for %q was cancelled", md.Deployment.ApplicationName)
text = fmt.Sprintf("Cancelled by %s", md.Commander)
color = slackWarnColor
generateDeploymentEventData(md.Deployment, md.EnvName)

case model.EventType_EVENT_PIPED_STARTED:
md := event.Metadata.(*model.EventPipedStarted)
case model.NotificationEventType_EVENT_PIPED_STARTED:
md := event.Metadata.(*model.NotificationEventPipedStarted)
title = "A piped has been started"
generatePipedEventData(md.Id, md.Version)

case model.EventType_EVENT_PIPED_STOPPED:
md := event.Metadata.(*model.EventPipedStopped)
case model.NotificationEventType_EVENT_PIPED_STOPPED:
md := event.Metadata.(*model.NotificationEventPipedStopped)
title = "A piped has been stopped"
generatePipedEventData(md.Id, md.Version)

Expand Down
Loading