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

added email notification text content support #934

Merged
merged 8 commits into from
Sep 7, 2017
Merged

added email notification text content support #934

merged 8 commits into from
Sep 7, 2017

Conversation

awaragi
Copy link
Contributor

@awaragi awaragi commented Jul 31, 2017

added email notification text content support (configuration text)
added default email notification text content default value empty
converted email notification from html to multipart/alternatives with support to both html (first) and text (last)
ignore intellij IDE .idea working folder

added default email notification text content default value empty
converted email notification from html to multipart/alternatives with support to both html (first) and text (last)
ignore intellij IDE .idea working folder
@awaragi awaragi mentioned this pull request Jul 31, 2017
mxinden
mxinden previously requested changes Aug 1, 2017
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.

@awaragi I think the convention in the Prometheus organization is to not add editor specific .gitignore entries. Please add them to your global .gitignore instead.

@fabxc
Copy link
Contributor

fabxc commented Aug 2, 2017

Thanks for picking this up!

Go's standard library actually has a package for multipart: https://godoc.org/mime/multipart
It seems cleaner to use this rather than constructing everything ourselves. Could you switch to using that?

@@ -142,6 +143,7 @@ type EmailConfig struct {
AuthIdentity string `yaml:"auth_identity,omitempty" json:"auth_identity,omitempty"`
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
HTML string `yaml:"html,omitempty" json:"html,omitempty"`
TEXT string `yaml:"text,omitempty" json:"text,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Just Text as it's not an acronym.

Copy link
Contributor Author

@awaragi awaragi Aug 2, 2017

Choose a reason for hiding this comment

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

Hi @fabxc

I am not sure I understand your comment. I am not a Go dev (yet) so I need more details about what you are requesting as a change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the key here is that HTML is all caps since it it an initialism, but TEXT would be written as Text since it's just a word.

Does that make sense?
https://github.com/golang/go/wiki/CodeReviewComments#initialisms gives move info on this case

@awaragi
Copy link
Contributor Author

awaragi commented Aug 2, 2017

@fabxc The original code of email notification was constructed manually from smtp handshake to email construction. I am not at the level to rework this entire section of code. The smtp protocole is old dated and is not likely to change any time soon. may I recommend adding //TODO refactor to use standard multipart library https://godoc.org/mime/multipart?

added TODO note to refactor multipart code to use standard go library
@awaragi
Copy link
Contributor Author

awaragi commented Aug 9, 2017

Hi, any progress with this pull request? I see that the flag for changes requested is still there but I have removed the offending file (.gitignore).

@mxinden can you please mark your change request as satisfied?

@mxinden mxinden dismissed their stale review August 9, 2017 18:01

Editor specific gitignore entry removed.

@mxinden
Copy link
Member

mxinden commented Aug 9, 2017

@awaragi For sure. Thanks for the reminder.

@fabxc Can you have a second look at this?

@fabxc
Copy link
Contributor

fabxc commented Aug 10, 2017

@fabxc The original code of email notification was constructed manually from smtp handshake to email construction. I am not at the level to rework this entire section of code. The smtp protocole is old dated and is not likely to change any time soon. may I recommend adding //TODO refactor to use standard multipart library https://godoc.org/mime/multipart?

Sorry, I've to raise a very clear "NO" on this. Every new feature is a maintenance liability and already having pending TODOs when adding them is not sustainable.
The question is, who is going to refactor this? The answer is typically no one.

I hope my concern is understandable.

I'm happy to review any attempts to use the proper standard library package. If you don't feel like trying it yourself, maybe someone else who's keen on this feature wants to give it a shot.

@awaragi
Copy link
Contributor Author

awaragi commented Aug 10, 2017

@fabxc I understand your point. My liking to Go is increasing so I've attempted to use the mime/multipart library. Take another look and let me know if it works.

By the way, your original TODO about adding support text template is now removed so one less to go.

@mxinden
Copy link
Member

mxinden commented Aug 13, 2017

As far as I can tell (for documentation purposes): Fixes #290

@awaragi
Copy link
Contributor Author

awaragi commented Aug 14, 2017

Hey Guys @fabxc @mxinden , any other suggestions, modifications or can you accept this PR?

@awaragi
Copy link
Contributor Author

awaragi commented Aug 18, 2017

Any chance someone can take a look at this PR?

Copy link
Contributor

@fabxc fabxc 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 putting in the work! Looks good in general. Just a few remarks on usage of the multipart package and we should be good to go.

notify/impl.go Outdated
fmt.Fprintf(wc, "Date: %s\r\n", time.Now().Format(time.RFC1123Z))
fmt.Fprintf(wc, "Content-Type: multipart/alternative; boundary=\"%s\"\r\n", multipartWriter.Boundary())
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this can be replaced with this convenience function: https://godoc.org/mime/multipart#Writer.FormDataContentType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Fabian @fabxc, your initial thought is correct however for multipart email content, you need the multipart/alternative instead of multipart/form-data which is what the FormDataContentType return. I did however notice an additional quotes that were problematic that I took out from around the boundary string.

notify/impl.go Outdated

// TODO: Add some useful headers here, such as URL of the alertmanager
// and active/resolved.
fmt.Fprintf(wc, "\r\n")

// TODO(fabxc): do a multipart write that considers the plain template.
// Html template
multipartWriter.CreatePart(textproto.MIMEHeader{"Content-Type": {"text/html; charset=UTF-8"}})
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the documentation of CreatePart the io.Writer it returns should be used to write the output of the template into.
Same below when creating the part for the text template.

https://godoc.org/mime/multipart#Writer.CreatePart

The returned error should be checked as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabxc implemented as suggested and added basic error handling.

@awaragi
Copy link
Contributor Author

awaragi commented Aug 18, 2017

Thanks for the feedback. I will update accordingly.

Pierre Awaragi added 2 commits August 22, 2017 13:26
added error handling while creating parts
removed unnecessary quotes from boundry string
notify/impl.go Outdated
if err != nil {
return true, err
}

// closing multi-part content
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment probably isn't necessary, since the code says essentially the same thing.

notify/impl.go Outdated
// closing multi-part content
multipartWriter.Close()

// writing multipart content
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above comment.

@stuartnelson3
Copy link
Contributor

@fabxc any chance to take another look?

@awaragi
Copy link
Contributor Author

awaragi commented Sep 1, 2017

@fabxc any possibility to move forward with this pull request?

@awaragi
Copy link
Contributor Author

awaragi commented Sep 3, 2017

Anyone?

@awaragi
Copy link
Contributor Author

awaragi commented Sep 5, 2017

Any possibility of merging this pull request?

@stuartnelson3
Copy link
Contributor

Sorry for the delay, I'll try to poke @fabxc again

@fabxc
Copy link
Contributor

fabxc commented Sep 7, 2017

Thanks, LGTM! Sorry about the long delay.

@fabxc fabxc merged commit f3cd397 into prometheus:master Sep 7, 2017
iksaif pushed a commit to iksaif/alertmanager that referenced this pull request Sep 15, 2017
* added email notification text content support (configuration text)
added default email notification text content default value empty
converted email notification from html to multipart/alternatives with support to both html (first) and text (last)
ignore intellij IDE .idea working folder

* removed specific editor .gitignore entries

* renamed TEXT to Text as it's not an acronym
added TODO note to refactor multipart code to use standard go library

* refactored to use standard go mime/multipart library for text and html parts and bounderies

* use multipart createPart returned writer
added error handling while creating parts
removed unnecessary quotes from boundry string

* removed unnecessary comments
@alin-amana
Copy link
Contributor

This causes a regression.

I've built alertmanager from head and now I'm getting multipart emails with the old html content and empty text content. If your email client chooses the text format (which Gmail does for me, for some reason) then the content of the alert email is empty.

The code should check for non-empty html and/or text templates and skip the empty one, if any.

@alin-amana
Copy link
Contributor

Also, a MIME-Version: 1.0 header must be added: http://www.rfc-base.org/txt/rfc-2045.txt

@alin-amana
Copy link
Contributor

And, per RFC 2046 section 5.1.4, the parts should be in increasing preference order. Meaning text should come before HTML. This explains why I'm seeing the empty plain text version in Gmail.

Never mind, I'll submit a PR.

@stuartnelson3
Copy link
Contributor

@alin-amana Are you working on this currently? This is a big enough issue that a new release will go out when it's fixed.

@alin-amana
Copy link
Contributor

Yup, working as we speak.

@alin-amana
Copy link
Contributor

Done, PTAL at #1009.

@RichiH
Copy link
Member

RichiH commented Oct 19, 2017

Huh, missed that one. Thanks to all involved!

hh pushed a commit to ii/alertmanager that referenced this pull request May 15, 2018
* Do not rely on AArch64 CPUs to support 32-bit ARM for cross-testing.

Signed-off-by: Alexey Kopytov <akopytov@gmail.com>

* aarch64 like ppc64le reports 64k node_sockstat_TCP_mem_bytes due to 64k pages.

Signed-off-by: Alexey Kopytov <akopytov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants