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

adds name, value, SlackConfirmationField to slack action #1557

Merged
merged 9 commits into from
Oct 29, 2018

Conversation

auhlig
Copy link
Contributor

@auhlig auhlig commented Sep 20, 2018

Fixes #1556. Either URL or Name and Value need to be provided in slack action. LGTY @simonpasquier? Thanks in advance

@auhlig auhlig force-pushed the slack_message_buttons branch from b63cf76 to b3e5e16 Compare September 20, 2018 15:45
@simonpasquier
Copy link
Member

Hmm, I'm definitely baffled by the lack of consistency in the Stack documentation. https://api.slack.com/docs/interactive-message-field-guide#action_fields says that name, text and type are mandatory while https://api.slack.com/docs/message-attachments#action_fields doesn't mention name and states that url is mandatory. I'd be reluctant to merge a change without more insights on the right way.

@stuartnelson3 any thoughts on this?

@auhlig
Copy link
Contributor Author

auhlig commented Sep 21, 2018

I agree the slack API is quite confusing.
I understood, there are (at least) 2 types of buttons in slack: message and link buttons in a slack action.
The API says type, text, url are ..required when using link buttons (https://api.slack.com/docs/message-attachments#action_fields).
While message buttons as specified here need to have name, text, type.

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to add a test to notifiers_test.go similar to

func TestSlackFieldConfigValidation(t *testing.T) {

@@ -252,9 +255,13 @@ func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.Text == "" {
return fmt.Errorf("missing value in Slack text configuration")
}
if c.URL == "" {
// either URL or Name and Value need to be provided
if c.URL != "" && c.Name != "" && c.Value != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your last comment, the code should be:

if c.URL == "" && c.Name == "" {
  return fmt.Errorf("missing 'name' or 'url' in Slack action configuration")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. adjusted

@@ -252,9 +255,13 @@ func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.Text == "" {
return fmt.Errorf("missing value in Slack text configuration")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with L250, this should read "missing 'text' in Slack action configuration"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@auhlig auhlig force-pushed the slack_message_buttons branch from 1ebb855 to 56c79a0 Compare October 2, 2018 19:19
@auhlig
Copy link
Contributor Author

auhlig commented Oct 2, 2018

Done @simonpasquier.
I also added the confirmation fields to the slack action.

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort! You would need to extend the unit tests too, see there:

func TestSlackFieldConfigValidation(t *testing.T) {

@@ -232,12 +232,16 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

// SlackAction configures a single Slack action that is sent with each notification.
// Each action must contain a type, text, and url.
// See https://api.slack.com/docs/message-attachments#action_fields for more information.
// See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons
// for more information
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) missing dot at the end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added dot

}
if c.URL == "" {
return fmt.Errorf("missing value in Slack url configuration")
// either URL or Name and Value need to be provided
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added dot

}
if (c.Name == "" || c.Value == "") && c.URL == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure that it is the correct approach: AFAIU value isn't mandatory. Also what happens if the configuration defines url and name at the same time? What is the result in Slack?

Maybe do something like this instead?

if c.URL != "" {
  // Clear all message action fields.
  c.Name = ""
  c.Value = ""
  c.ConfirmField = nil
} else if c.Name != "" {
  c.URL = ""
} else {
  return fmt.Errorf("missing name or url in Slack action configuration")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using both url, name seems to be no error to slack. However, your approach ensures we're not having both as per API spec. Using that

DismissText string `yaml:"dismiss_text,omitempty" json:"dismiss_text,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface for SlackConfirmationField
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotted

config/notifiers.go Show resolved Hide resolved
@auhlig
Copy link
Contributor Author

auhlig commented Oct 4, 2018

Also extended tests. LGTY @simonpasquier?

@auhlig
Copy link
Contributor Author

auhlig commented Oct 8, 2018

Anything else that needs to be done @simonpasquier?

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConfirmField is declared in the configuration but not used by the receiver AFAICT

@@ -250,10 +254,39 @@ func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
return fmt.Errorf("missing type in Slack action configuration")
}
if c.Text == "" {
return fmt.Errorf("missing value in Slack text configuration")
return fmt.Errorf("missing text value in Slack text configuration")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"missing text in Slack action configuration"

return err
}
if c.Text == "" {
return fmt.Errorf("missing text in slack action confirm")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"missing text in slack configuration configuration"

notify/impl.go Show resolved Hide resolved
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM though SlackConfirmationField fields could be templated too for consistency.

@auhlig
Copy link
Contributor Author

auhlig commented Oct 14, 2018

uses tmplText() on SlackConfirmationField. LGTY @simonpasquier?

@auhlig auhlig changed the title adds name, value to slack action adds name, value, SlackConfirmationField to slack action Oct 16, 2018
@auhlig
Copy link
Contributor Author

auhlig commented Oct 16, 2018

Thanks a lot for all the helpful guidance!
Anything else I need to do on this @simonpasquier?

@simonpasquier
Copy link
Member

Thanks for your patience @auhlig. I'll give it a try as I happen to have access to a Slack instance...
Once it is merged, the documentation would need updates too.

notify/impl.go Outdated
@@ -747,6 +747,14 @@ func (n *Slack) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
Text: tmplText(action.Text),
URL: tmplText(action.URL),
Style: tmplText(action.Style),
Name: tmplText(action.Name),
Value: tmplText(action.Value),
ConfirmField: &config.SlackConfirmationField{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to test if action.ConfirmField is nil otherwise it will panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@auhlig
Copy link
Contributor Author

auhlig commented Oct 18, 2018

Added check and opened PR for docs @simonpasquier

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
@auhlig auhlig force-pushed the slack_message_buttons branch from c073c3c to 8a4f363 Compare October 19, 2018 18:18
@auhlig
Copy link
Contributor Author

auhlig commented Oct 19, 2018

Rebased after conflicts.

Did slack attachments ever work @simonpasquier? While trying this I slack told me the callback_id for attachments is mandatory: https://api.slack.com/docs/interactive-message-field-guide#attachment_fields
Anyway works perfectly now

@auhlig auhlig force-pushed the slack_message_buttons branch from 1e7a462 to ac52517 Compare October 19, 2018 18:31
@auhlig auhlig force-pushed the slack_message_buttons branch from ac52517 to f61c50d Compare October 19, 2018 19:02
@auhlig
Copy link
Contributor Author

auhlig commented Oct 19, 2018

Not sure why (only) travis complains. Do I need to run make assets here?
Works on my mac.

@auhlig
Copy link
Contributor Author

auhlig commented Oct 22, 2018

Tested with slack. Works for me (TM).
Will update prometheus/docs#1196 today.
Would you mind taking another look @simonpasquier?

@auhlig
Copy link
Contributor Author

auhlig commented Oct 22, 2018

Tested with slack. Works for me (TM).
Will update prometheus/docs#1196 today.
Would you mind taking another look and consider merging @simonpasquier? ❤️

1 similar comment
@auhlig
Copy link
Contributor Author

auhlig commented Oct 22, 2018

Tested with slack. Works for me (TM).
Will update prometheus/docs#1196 today.
Would you mind taking another look and consider merging @simonpasquier? ❤️

@simonpasquier
Copy link
Member

Did slack attachments ever work?

They surely did. TBH Slack is terrible at dealing with backward compatibility: things that used to work at time T may break at time T+N for some users and continue to work for the others. I wouldn't include f61c50d in this PR as it is unrelated. If it is broken with the current master, please file an issue with all relevant details and it should be addressed separately.

@auhlig auhlig force-pushed the slack_message_buttons branch from db2cdc3 to 958197a Compare October 22, 2018 16:21
@auhlig
Copy link
Contributor Author

auhlig commented Oct 22, 2018

Ewww slack -.-
Extracted the callback_id to #1592 and reset this PR to the last approved commit. Sorry for the back- and forth. Is this good to go @simonpasquier?

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nit and this is ok for me.

@@ -247,12 +247,16 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

// SlackAction configures a single Slack action that is sent with each notification.
// Each action must contain a type, text, and url.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the comment is outdated. Just remove it please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's gone

Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
@simonpasquier
Copy link
Member

👍 cc @mxinden @stuartnelson3

@auhlig
Copy link
Contributor Author

auhlig commented Oct 24, 2018

Not pushing. Just want to know whether anything else needs to be done to get this merged? @mxinden @stuartnelson3

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and bearing with us!

@mxinden mxinden merged commit b63b560 into prometheus:master Oct 29, 2018
@simonpasquier
Copy link
Member

Yes thanks for the work @auhlig. That was more involved than expected!

@auhlig auhlig deleted the slack_message_buttons branch October 29, 2018 19:50
@auhlig
Copy link
Contributor Author

auhlig commented Oct 29, 2018

Thanks guys ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants