Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created May 28, 2022 22:31
Show Gist options
  • Save harshavardhana/2d00e6f909054d2d2524c71485ad02e1 to your computer and use it in GitHub Desktop.
Save harshavardhana/2d00e6f909054d2d2524c71485ad02e1 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"os"
"strconv"
"time"
)
func getHealthCheckTransport() func() *http.Transport {
// Keep TLS config.
tlsConfig := &tls.Config{
// Can't use SSLv3 because of POODLE and BEAST
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
// Can't use TLSv1.1 because of RC4 cipher usage
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: true, // FIXME: use trusted CA
}
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 2 * time.Second,
KeepAlive: 10 * time.Second,
}).DialContext,
ResponseHeaderTimeout: 5 * time.Second,
TLSHandshakeTimeout: 5 * time.Second,
ExpectContinueTimeout: 5 * time.Second,
TLSClientConfig: tlsConfig,
// Go net/http automatically unzip if content-type is
// gzip disable this feature, as we are always interested
// in raw stream.
DisableCompression: true,
}
return func() *http.Transport {
return tr
}
}
func doHealth(svcURL string) error {
endpoint := fmt.Sprintf("%s%s", svcURL, "/minio/health/cluster")
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
return err
}
httpClient := &http.Client{
Transport: getHealthCheckTransport()(),
}
resp, err := httpClient.Do(req)
if err != nil {
return err
}
drivesHealing := 0
if v := resp.Header.Get("X-Minio-Healing-Drives"); v != "" {
val, err := strconv.Atoi(v)
if err == nil {
drivesHealing = val
}
}
minDriveWrites := 0
if v := resp.Header.Get("X-Minio-Write-Quorum"); v != "" {
val, err := strconv.Atoi(v)
if err == nil {
minDriveWrites = val
}
}
fmt.Printf("drivesHealing: %d, writeQuorum: %d\n", drivesHealing, minDriveWrites)
return nil
}
func main() {
u := os.Args[1]
count := 0
maxCount := 1000
for {
doHealth(u)
time.Sleep(500*time.Millisecond)
count++
if count > maxCount {
time.Sleep(10*time.Hour)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment