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

Adding prometheus and pushgateway outputs #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jgarnier
Copy link

@jgarnier jgarnier commented Aug 16, 2022

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features) see docs/README.md

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make due to this PR?)

Other information:

Copy link
Contributor

@github-actions github-actions bot 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 submitting your first PR!

Please be sure to read and follow our Code of Conduct and Contributing guide.

⭐️ Is your org or open source project using woke? If so, we'd love for you to be included in the 'Who uses woke' list at https://github.com/get-woke/woke/blob/main/docs/about.md#who-uses-woke.

Comment on lines 26 to 27
Labels map[string]string `yaml:"labels,omitempty"`
PushgatewayURL string `yaml:"pushgateway"`
Copy link
Member

Choose a reason for hiding this comment

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

As discussed over email, please don't put these output-specific configs at the top level of woke config. I would prefer something else like

outputs:
  prometheus:
    pushgateway: https://my.url/
    labels:
      repo: sample
      something: else

return &Pushgateway{
writer: w,
labels: c.Labels,
pushgatewayURL: c.PushgatewayURL,
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to validate that PushgatewayURL is supplied so you can provide an error to the user?

if err := pusher.Push(); err != nil {
fmt.Println("Could not push woke_result to Pushgateway:", err)
} else {
fmt.Printf("push woke_result to Pushgateway: %v", pusher)
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the zerolog log package for this instead of fmt to print something that's meant to be informative?

Also, using %v here doesn't provide a lot of valuable information to the user, what are you trying to tell the user here by printing out the pusher instead of the result from woke? That data can easily be written out in a human-readable format

Collector(woke_result)

if err := pusher.Push(); err != nil {
fmt.Println("Could not push woke_result to Pushgateway:", err)
Copy link
Member

Choose a reason for hiding this comment

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

Should this error be returned? If not, the log package would be preferred to fmt here too

Comment on lines +44 to +60
if len(t.labels) > 0 {
first := true
for k, v := range t.labels {
if first {
labelString += ", "
first = false
}
labelString += k + "=" + v + ", "
}
labelString = labelString[:len(labelString)-2]
}
Copy link
Member

Choose a reason for hiding this comment

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

This logic is duplicated across prometheus.go and pushgateway.go. Can they be consolidated? I would also recommend creating a test for this functionality specifically

Name: "woke_result",
Help: "Inclusive woke result",
})
pusher := push.New(t.pushgatewayURL, "woke")
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to initialize this before looping through the results?

@@ -0,0 +1,85 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

Please include exhaustive tests for this file.

@@ -67,6 +76,10 @@ func NewPrinter(f string, w io.Writer) (Printer, error) {
p = NewJSON(w)
case OutFormatSonarQube:
p = NewSonarQube(w)
case OutFormatPrometheus:
p = NewPrometheus(w, c)
Copy link
Member

Choose a reason for hiding this comment

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

Ideally you do not need to pass the entire config into these two New* functions, you should only need to pass in what is needed for the printer to run.

Comment on lines 39 to 43
// OutFormatPrometheus outputs in prometheus format
OutFormatPrometheus = "prometheus"

// OutFormatPushgateway send metrics to prometheus pushgateway
OutFormatPushgateway = "pushgateway"
Copy link
Member

Choose a reason for hiding this comment

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

These are both prometheus output formats? Why do they need to be two unique ones? Also, please include links here to prometheus format like the other formats provide

go.mod Outdated
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Copy link
Member

Choose a reason for hiding this comment

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

There are a lot of version upgrades here that I'm not sure are relevant to this PR.

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.

2 participants