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

Move fatal logs from prom2json file to main #27

Merged
merged 2 commits into from Jun 20, 2018

Conversation

nmengin
Copy link
Contributor

@nmengin nmengin commented Jun 19, 2018

This PR moves fatal logs from the prom2json functions to the main.
Indeed, the prom2json functions can be used as a library and the log.Fatal stops the program which calls it.

The modifications allow removing the fatal behavior from the prom2json and manage the errors in the main.
Thus, the current behavior of prom2json is not modified.

WDYT @beorn7 ?

Signed-off-by: nmengin <nicolas@containo.us>
@nmengin nmengin force-pushed the feature/replace-fatal-by-error-logs branch from 8a67a46 to 3cd8875 Compare June 19, 2018 18:55
Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Sure, this makes sense if using the code as a library. To my excuse, the code was never meant to be used as a library. It's really just a tool and not very sophisticated. However, if it is useful for you, I won't stand in your way.

I have a commented on a few nits. Should be easy to address, and then we are good to go.

prom2json.go Outdated
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatalf("creating GET request for URL %q failed: %s", url, err)
return fmt.Errorf("creating GET request for URL %q failed: %s", url, err)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps use %v to render err as you have done below?

prom2json.go Outdated
}
req.Header.Add("Accept", acceptHeader)
resp, err := client.Do(req)
if err != nil {
log.Fatalf("executing GET request for URL %q failed: %s", url, err)
return fmt.Errorf("executing GET request for URL %q failed: %s", url, err)
Copy link
Member

Choose a reason for hiding this comment

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

See above.

}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("GET request for URL %q returned HTTP status %s", url, resp.Status)
return fmt.Errorf("GET request for URL %q returned HTTP status %s", url, resp.Status)
Copy link
Member

Choose a reason for hiding this comment

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

See above.

Copy link
Contributor Author

@nmengin nmengin Jun 20, 2018

Choose a reason for hiding this comment

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

resp.Status returns a string.
I can replace %s by %v but not sure it makes sense here.

WDYT @beorn7?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, my bad.

Copy link
Member

Choose a reason for hiding this comment

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

(But just FYI: %v used on a string renders the string the same way as %s. I often just use %v because it is more flexible.)

dto "github.com/prometheus/client_model/go"

"github.com/prometheus/common/log"
Copy link
Member

Choose a reason for hiding this comment

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

Please don't re-arrange the import lines. The grouping in blocks follows the general Prometheus style.

(stdlib, then unnamed from other repos, then named from other repos, then unnamed from same repo, then named from same repo)

prom2json.go Outdated
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
Copy link
Member

Choose a reason for hiding this comment

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

Please leave the grouping of import lines intact. See other file.

Signed-off-by: nmengin <nicolas@containo.us>
@beorn7
Copy link
Member

beorn7 commented Jun 20, 2018

Thanks. Merging now…

@beorn7 beorn7 merged commit 7b8ed2a into prometheus:master Jun 20, 2018
@nmengin nmengin deleted the feature/replace-fatal-by-error-logs branch June 21, 2018 06:54
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.

None yet

2 participants