Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix title inconsistency in slack and victorops #415

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 7 additions & 8 deletions senders/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/karriereat/blackfriday-slack"
slackdown "github.com/karriereat/blackfriday-slack"
"github.com/moira-alert/moira"
"github.com/moira-alert/moira/senders"
blackfriday "gopkg.in/russross/blackfriday.v2"
Expand Down Expand Up @@ -113,20 +113,19 @@ func (sender *Sender) buildDescription(trigger moira.TriggerData) string {

func (sender *Sender) buildTitle(events moira.NotificationEvents, trigger moira.TriggerData) string {
title := fmt.Sprintf("*%s*", events.GetSubjectState())

tags := trigger.GetTags()
if tags != "" {
title += " " + tags
}

triggerURI := trigger.GetTriggerURI(sender.frontURI)
if triggerURI != "" {
title += fmt.Sprintf(" <%s|%s>", triggerURI, trigger.Name)
} else if trigger.Name != "" {
title += " " + trigger.Name
}
title += "\n"

tags := trigger.GetTags()
if tags != "" {
title += " " + tags
}

title += "\n"
return title
}

Expand Down
8 changes: 4 additions & 4 deletions senders/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ some other text italic text

Convey("Print moira message with one event", func() {
actual := sender.buildMessage([]moira.NotificationEvent{event}, trigger, false)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA)```"
So(actual, ShouldResemble, expected)
})
Expand All @@ -133,21 +133,21 @@ some other text italic text
Convey("Print moira message with one event and message", func() {
event.Message = &message
actual := sender.buildMessage([]moira.NotificationEvent{event}, trigger, false)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA). This is message```"
So(actual, ShouldResemble, expected)
})

Convey("Print moira message with one event and throttled", func() {
actual := sender.buildMessage([]moira.NotificationEvent{event}, trigger, true)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA)```\nPlease, *fix your system or tune this trigger* to generate less events."
So(actual, ShouldResemble, expected)
})

Convey("Print moira message with 6 events", func() {
actual := sender.buildMessage([]moira.NotificationEvent{event, event, event, event, event, event}, trigger, false)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)```"
So(actual, ShouldResemble, expected)
})
Expand Down
5 changes: 2 additions & 3 deletions senders/victorops/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/writeas/go-strip-markdown"
stripmd "github.com/writeas/go-strip-markdown"

"github.com/moira-alert/moira"
"github.com/moira-alert/moira/senders/victorops/api"
Expand Down Expand Up @@ -72,15 +72,14 @@ func (sender *Sender) getMessageType(events moira.NotificationEvents) api.Messag

func (sender *Sender) buildTitle(events moira.NotificationEvents, trigger moira.TriggerData) string {
title := string(events.GetSubjectState())
title += " " + trigger.Name

tags := trigger.GetTags()
if tags != "" {
title += " " + tags
}

title += trigger.Name
title += "\n"

return title
}

Expand Down
31 changes: 30 additions & 1 deletion senders/victorops/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/moira-alert/moira/senders/victorops/api"

"github.com/moira-alert/moira"
"github.com/moira-alert/moira/mock/moira-alert"
mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down Expand Up @@ -120,3 +120,32 @@ func TestBuildCreateAlertRequest(t *testing.T) {
})
})
}

func TestBuildTitle(t *testing.T) {
sender := Sender{}
value := float64(123)

Convey("Build title test", t, func() {
event := moira.NotificationEvent{
TriggerID: "TriggerID",
Value: &value,
Timestamp: 150000000,
Metric: "Metric",
OldState: moira.StateOK,
State: moira.StateNODATA,
Message: nil,
}

trigger := moira.TriggerData{
Tags: []string{"tag1", "tag2"},
Name: "Name",
ID: "TriggerID",
}

Convey("Build title", func() {
actual := sender.buildTitle(moira.NotificationEvents{event}, trigger)
expected := "NODATA Name [tag1][tag2]\n"
So(actual, ShouldResemble, expected)
})
})
}