update healthcheck tests for new prometheus endpoint (#11333)

master
Harshavardhana 4 years ago committed by GitHub
parent c080f04e66
commit a35cbb3ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      mint/run/core/healthcheck/main.go
  2. 2
      mint/run/core/minio-go/go.mod

@ -38,6 +38,7 @@ const (
livenessPath = "/minio/health/live" livenessPath = "/minio/health/live"
readinessPath = "/minio/health/ready" readinessPath = "/minio/health/ready"
prometheusPath = "/minio/prometheus/metrics" prometheusPath = "/minio/prometheus/metrics"
prometheusPathV2 = "/minio/v2/metrics/cluster"
timeout = time.Duration(30 * time.Second) timeout = time.Duration(30 * time.Second)
) )
@ -196,6 +197,53 @@ func testPrometheusEndpoint(endpoint string) {
defer successLogger(function, nil, startTime).Info() defer successLogger(function, nil, startTime).Info()
} }
func testPrometheusEndpointV2(endpoint string) {
startTime := time.Now()
function := "testPrometheusEndpoint"
u, err := url.Parse(fmt.Sprintf("%s%s", endpoint, prometheusPathV2))
if err != nil {
// Could not parse URL successfully
failureLog(function, nil, startTime, "", "URL Parsing for Healthcheck Prometheus handler failed", err).Fatal()
}
jwt := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, jwtgo.StandardClaims{
ExpiresAt: time.Now().UTC().Add(defaultPrometheusJWTExpiry).Unix(),
Subject: os.Getenv("ACCESS_KEY"),
Issuer: "prometheus",
})
token, err := jwt.SignedString([]byte(os.Getenv("SECRET_KEY")))
if err != nil {
failureLog(function, nil, startTime, "", "jwt generation failed", err).Fatal()
}
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: u.Scheme == "https"},
}
client := &http.Client{Transport: tr, Timeout: timeout}
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
failureLog(function, nil, startTime, "", "Initializing GET request to Prometheus endpoint failed", err).Fatal()
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
resp, err := client.Do(req)
if err != nil {
// GET request errored
failureLog(function, nil, startTime, "", "GET request to Prometheus endpoint failed", err).Fatal()
}
if resp.StatusCode != http.StatusOK {
// Status not 200 OK
failureLog(function, nil, startTime, "", "GET /minio/prometheus/metrics returned non OK status", err).Fatal()
}
defer resp.Body.Close()
defer successLogger(function, nil, startTime).Info()
}
func main() { func main() {
endpoint := os.Getenv("SERVER_ENDPOINT") endpoint := os.Getenv("SERVER_ENDPOINT")
secure := os.Getenv("ENABLE_HTTPS") secure := os.Getenv("ENABLE_HTTPS")
@ -217,4 +265,5 @@ func main() {
testLivenessEndpoint(endpoint) testLivenessEndpoint(endpoint)
testReadinessEndpoint(endpoint) testReadinessEndpoint(endpoint)
testPrometheusEndpoint(endpoint) testPrometheusEndpoint(endpoint)
testPrometheusEndpointV2(endpoint)
} }

@ -2,4 +2,4 @@ module mint.minio.io/minio-go
go 1.14 go 1.14
require github.com/minio/minio-go/v7 v7.0.6 // indirect require github.com/minio/minio-go/v7 v7.0.7 // indirect

Loading…
Cancel
Save