-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[ws-rollout] Add prometheus init check #16000
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ package analysis | |
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/api" | ||
v1 "github.com/prometheus/client_golang/api/prometheus/v1" | ||
) | ||
|
||
type Decision int | ||
|
@@ -21,3 +25,24 @@ type Analyzer interface { | |
// repeatedly to determine whether to move forward on the rollout or not. | ||
MoveForward(ctx context.Context, clusterName string) (Decision, error) | ||
} | ||
|
||
func CheckPrometheusReachable(ctx context.Context, prometheusURL string) error { | ||
if prometheusURL == "" { | ||
return nil | ||
} | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about moving this function to |
||
|
||
client, err := api.NewClient(api.Config{ | ||
Address: prometheusURL, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
v1Client := v1.NewAPI(client) | ||
_, _, err = v1Client.Query(ctx, "up", time.Now()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could remove the error return here,
log.Fatal
will already exit the process