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

Add support for HTTP POST body content #123

Merged
merged 3 commits into from
Oct 3, 2021

Conversation

rustycl0ck
Copy link
Member

closes #69

Signed-off-by: rustyclock <rustyclock@protonmail.com>
Signed-off-by: rustyclock <rustyclock@protonmail.com>
exporter/util.go Outdated
Comment on lines 128 to 144
br := strings.NewReader(c.Body.Content)
if c.Body.Templatize {
tpl, err := template.New("base").Funcs(sprig.GenericFuncMap()).Parse(c.Body.Content)
if err != nil {

level.Error(logger).Log("msg", "Failed to create a new template from body content", "err", err, "content", c.Body.Content) //nolint:errcheck
}
var b strings.Builder
if err := tpl.Execute(&b, tplValues); err != nil {
level.Error(logger).Log("msg", "Failed to render template with values", "err", err, "tempalte", c.Body.Content) //nolint:errcheck

// `tplValues` can contain sensitive values, so log it only when in debug mode
level.Debug(logger).Log("msg", "Failed to render template with values", "err", err, "tempalte", c.Body.Content, "values", tplValues) //nolint:errcheck
}
br = strings.NewReader(b.String())
}
req, err = http.NewRequest("POST", endpoint, br)
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be a little cleaner as a separate function, rather than all inline.

Something like this:

func renderBody(c ConfigBody, tplValues url.Values) (io.Reader, error) {...}

Copy link
Member Author

Choose a reason for hiding this comment

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

I have refactored it into a separate function now.

Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

Minor nit on the cod structure, otherwise looks good.

Signed-off-by: rustyclock <rustyclock@protonmail.com>
Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM

@rustycl0ck rustycl0ck merged commit bd0852b into prometheus-community:master Oct 3, 2021
SuperQ added a commit that referenced this pull request Jan 15, 2022
* [FEATURE] Add support for HTTP POST body content #123

Signed-off-by: SuperQ <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Jan 15, 2022
rustycl0ck pushed a commit that referenced this pull request Jan 18, 2022
* [FEATURE] Add support for HTTP POST body content #123

Signed-off-by: SuperQ <superq@gmail.com>
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.

Add support for POST method
2 participants