Skip to content

Commit

Permalink
feat: slack dashboard uri
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Oct 3, 2023
1 parent 9d16931 commit 085f650
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ func newSlackLoader(cfg *config.Config, envs map[string]string) (*slack.SlackLoa
return nil, err
}

return slack.NewSlackLoader(slackTemplate, slackConfig, cfg.TestkubeClusterName, testkube.AllEventTypes, envs), nil
return slack.NewSlackLoader(slackTemplate, slackConfig, cfg.TestkubeClusterName, cfg.TestkubeDashboardURI,
testkube.AllEventTypes, envs), nil
}

// getMongoSSLConfig builds the necessary SSL connection info from the settings in the environment variables
Expand Down
37 changes: 36 additions & 1 deletion config/slack-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,43 @@
"text": "`kubectl testkube get execution {{ .ExecutionName }} `\n"
}
},
{{ if eq .TestType "Test Suite" }}
{
"type": "button",
"text": {
"type": "mrkdwn",
"text": "Test Suite URI"
},
"url": "{{ .DashboardURI }}/test-suites/{{ .TestName }}"
},
{
"type": "button",
"text": {
"type": "mrkdwn",
"text": "Test Suite Execution URI"
},
"url": "{{ .DashboardURI }}/test-suites/{{ .TestName }}/executions/{{ .ExecutionID }}"
},
{{ else }}
{
"type": "button",
"text": {
"type": "mrkdwn",
"text": "Test URI"
},
"url": "{{ .DashboardURI }}/tests/{{ .TestName }}"
},
{
"type": "button",
"text": {
"type": "mrkdwn",
"text": "Test Execution URI"
},
"url": "{{ .DashboardURI }}/tests/{{ .TestName }}/executions/{{ .ExecutionID }}"
},
{{ end }}
{
"type": "divider"
}
]
}
}
5 changes: 3 additions & 2 deletions pkg/event/kind/slack/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (

var _ common.ListenerLoader = (*SlackLoader)(nil)

func NewSlackLoader(messageTemplate, configString, clusterName string, events []testkube.EventType, envs map[string]string) *SlackLoader {
func NewSlackLoader(messageTemplate, configString, clusterName, dashboardURI string,
events []testkube.EventType, envs map[string]string) *SlackLoader {
var config []slack.NotificationsConfig
if err := json.Unmarshal([]byte(configString), &config); err != nil {
log.DefaultLogger.Errorw("error unmarshalling slack config", "error", err)
}
slackNotifier := slack.NewNotifier(messageTemplate, clusterName, config, envs)
slackNotifier := slack.NewNotifier(messageTemplate, clusterName, dashboardURI, config, envs)
return &SlackLoader{
Log: log.DefaultLogger,
events: events,
Expand Down
2 changes: 1 addition & 1 deletion pkg/event/kind/slack/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestSlackLoader_Load(t *testing.T) {
t.Parallel()
// given
// default slack notifier is not ready by default
l := NewSlackLoader("", "", "", testkube.AllEventTypes, nil)
l := NewSlackLoader("", "", "", "", testkube.AllEventTypes, nil)

// when
listeners, err := l.Load()
Expand Down
9 changes: 7 additions & 2 deletions pkg/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type MessageArgs struct {
EndTime string
Duration string
ClusterName string
DashboardURI string
Envs map[string]string
}

Expand All @@ -36,12 +37,14 @@ type Notifier struct {
Ready bool
messageTemplate string
clusterName string
dashboardURI string
config *Config
envs map[string]string
}

func NewNotifier(template, clusterName string, config []NotificationsConfig, envs map[string]string) *Notifier {
notifier := Notifier{messageTemplate: template, clusterName: clusterName, config: NewConfig(config), envs: envs}
func NewNotifier(template, clusterName, dashboardURI string, config []NotificationsConfig, envs map[string]string) *Notifier {
notifier := Notifier{messageTemplate: template, clusterName: clusterName, dashboardURI: dashboardURI,
config: NewConfig(config), envs: envs}
notifier.timestamps = make(map[string]string)
if token, ok := os.LookupEnv("SLACK_TOKEN"); ok {
log.DefaultLogger.Infow("initializing slack client", "SLACK_TOKEN", token)
Expand Down Expand Up @@ -187,6 +190,7 @@ func (s *Notifier) composeTestsuiteMessage(execution *testkube.TestSuiteExecutio
TotalSteps: len(execution.ExecuteStepResults),
FailedSteps: execution.FailedStepsCount(),
ClusterName: s.clusterName,
DashboardURI: s.dashboardURI,
Envs: s.envs,
}

Expand Down Expand Up @@ -223,6 +227,7 @@ func (s *Notifier) composeTestMessage(execution *testkube.Execution, eventType t
TotalSteps: len(execution.ExecutionResult.Steps),
FailedSteps: execution.ExecutionResult.FailedStepsCount(),
ClusterName: s.clusterName,
DashboardURI: s.dashboardURI,
Envs: s.envs,
}

Expand Down

0 comments on commit 085f650

Please sign in to comment.