Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
1 change: 1 addition & 0 deletions pkg/app/piped/notifier/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/config:go_default_library",
"//pkg/git:go_default_library",
"//pkg/model:go_default_library",
"//pkg/version:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
Expand Down
20 changes: 20 additions & 0 deletions pkg/app/piped/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.uber.org/zap"

"github.com/pipe-cd/pipe/pkg/config"
"github.com/pipe-cd/pipe/pkg/git"
"github.com/pipe-cd/pipe/pkg/model"
)

Expand Down Expand Up @@ -151,6 +152,19 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
{"Started At", makeSlackDate(d.CreatedAt), true},
}
}
generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string) {
link = fmt.Sprintf("%s/applications/%s?project=%s", webURL, app.Id, app.PipedId)
Comment thread
ono-max marked this conversation as resolved.
Outdated
commitURL, err := git.MakeCommitURL(app.GitPath.Repo.Remote, hash)
if err != nil {
s.logger.Error(fmt.Sprintf("failed to get the URL for the specified commit: %v", err))
}
fields = []slackField{
{"Project", truncateText(app.ProjectId, 8), true},
{"Application", makeSlackLink(app.Name, link), true},
{"Kind", strings.ToLower(app.Kind.String()), true},
{"Commit", makeSlackLink(truncateText(msg, 8), commitURL), true},
Comment thread
ono-max marked this conversation as resolved.
Outdated
}
}
generatePipedEventData := func(id, name, version, project string) {
link = fmt.Sprintf("%s/settings/piped?project=%s", webURL, project)
fields = []slackField{
Expand Down Expand Up @@ -204,6 +218,12 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
color = slackWarnColor
generateDeploymentEventData(md.Deployment, md.EnvName, getAccountsAsString(md.MentionedAccounts))

case model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED:
md := event.Metadata.(*model.NotificationEventDeploymentTriggerFailed)
title = fmt.Sprintf("Failed to trigger a new deployment for %s", md.Application.Name)
text = md.Reason
generateDeploymentEventDataForTriggerFailed(md.Application, md.CommitHash, md.CommitMessage)

case model.NotificationEventType_EVENT_PIPED_STARTED:
md := event.Metadata.(*model.NotificationEventPipedStarted)
title = "A piped has been started"
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/trigger/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//pkg/filematcher:go_default_library",
"//pkg/git:go_default_library",
"//pkg/model:go_default_library",
"//pkg/version:go_default_library",
"@com_github_google_uuid//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
Expand Down
17 changes: 17 additions & 0 deletions pkg/app/piped/trigger/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ func (t *Trigger) triggerDeployment(
n, err := t.getNotification(app.GitPath)
if err != nil {
t.logger.Error("failed to get the list of mentions", zap.Error(err))
t.reportDeploymentFailed(app, fmt.Sprintf("failed to find the list of mentions from %s: %v", app.GitPath.GetDeploymentConfigFilePath(), err), commit)
return
}

deployment, err = buildDeployment(app, branch, commit, commander, syncStrategy, time.Now(), n)
if err != nil {
t.logger.Error("failed to build the deployment", zap.Error(err))
t.reportDeploymentFailed(app, fmt.Sprintf("failed to build the deployment: %v", err), commit)
return
}

Expand All @@ -60,10 +62,12 @@ func (t *Trigger) triggerDeployment(

defer func() {
if err != nil {
t.reportDeploymentFailed(app, fmt.Sprintf("%v", err), commit)
return
}
env, err := t.environmentLister.Get(ctx, deployment.EnvId)
if err != nil {
t.reportDeploymentFailed(app, fmt.Sprintf("%v", err), commit)
return
}
t.notifier.Notify(model.NotificationEvent{
Expand All @@ -84,6 +88,7 @@ func (t *Trigger) triggerDeployment(
}
if _, err = t.apiClient.CreateDeployment(ctx, req); err != nil {
t.logger.Error("failed to create deployment", zap.Error(err))
t.reportDeploymentFailed(app, fmt.Sprintf("failed to create deployment: %v", err), commit)
return
}

Expand Down Expand Up @@ -183,6 +188,18 @@ func buildDeployment(
return deployment, nil
}

func (t *Trigger) reportDeploymentFailed(app *model.Application, reason string, commit git.Commit) {
t.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGER_FAILED,
Metadata: &model.NotificationEventDeploymentTriggerFailed{
Application: app,
CommitHash: commit.Hash,
CommitMessage: commit.Message,
Reason: reason,
},
})
}

func (t *Trigger) getNotification(p *model.ApplicationGitPath) (*config.DeploymentNotification, error) {
// Find the application repo from pre-loaded ones.
repo, ok := t.gitRepos[p.Repo.Id]
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (t *Trigger) checkNewCommits(ctx context.Context) error {
shouldTrigger, err := d.ShouldTrigger(ctx, app)
if err != nil {
t.logger.Error(fmt.Sprintf("failed to check application: %s", app.Id), zap.Error(err))
t.reportDeploymentFailed(app, fmt.Sprintf("failed to find the list of mentions from %s: %v", app.GitPath.GetDeploymentConfigFilePath(), err), headCommit)
continue
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/model/notificationevent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum NotificationEventType {
EVENT_DEPLOYMENT_FAILED = 5;
EVENT_DEPLOYMENT_CANCELLED = 6;
EVENT_DEPLOYMENT_WAIT_APPROVAL = 7;
EVENT_DEPLOYMENT_TRIGGER_FAILED = 8;

EVENT_APPLICATION_SYNCED = 100;
EVENT_APPLICATION_OUT_OF_SYNC = 101;
Expand All @@ -39,7 +40,6 @@ enum NotificationEventType {

EVENT_PIPED_STARTED = 300;
EVENT_PIPED_STOPPED = 301;

}

enum NotificationEventGroup {
Expand Down Expand Up @@ -101,6 +101,13 @@ message NotificationEventDeploymentWaitApproval {
repeated string mentioned_accounts = 3;
}

message NotificationEventDeploymentTriggerFailed {
Application application = 1 [(validate.rules).message.required = true];
string commit_hash = 2 [(validate.rules).string.min_len = 1];
string commit_message = 3 [(validate.rules).string.min_len = 1];
string reason = 4 [(validate.rules).string.min_len = 1];
}

message NotificationEventApplicationSynced {
Application application = 1 [(validate.rules).message.required = true];
string env_name = 2 [(validate.rules).string.min_len = 1];
Expand Down