Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cmd/fishymetrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var (
driveModExclude = a.Flag("collector.drives.modules-exclude", "regex of drive module(s) to exclude from the scrape").Default("").Envar("COLLECTOR_DRIVES_MODULE_EXCLUDE").String()
firmwareModExclude = a.Flag("collector.firmware.modules-exclude", "regex of firmware module(s) to exclude from the scrape").Default("").Envar("COLLECTOR_FIRMWARE_MODULE_EXCLUDE").String()
urlExtraParams = a.Flag("url.extra-params", `extra parameter(s) to parse from the URL. --url.extra-params="param1:alias1,param2:alias2"`).Default("").Envar("URL_EXTRA_PARAMS").String()
disable404Retry = a.Flag("disable-404-retry", "Skip retrying on HTTP 404 (no 404 retry loop).").Default("false").Envar("FISHYMETRICS_DISABLE_404_RETRY").Bool()
_ = common.CredentialProf(a.Flag("credentials.profiles",
`profile(s) with all necessary parameters to obtain BMC credential from secrets backend, i.e.
--credentials.profiles="
Expand Down Expand Up @@ -155,11 +156,12 @@ func main() {
}

c := &config.Config{
BMCScheme: *bmcScheme,
BMCTimeout: *bmcTimeout,
SSLVerify: *insecureSkipVerify,
User: *username,
Pass: *password,
BMCScheme: *bmcScheme,
BMCTimeout: *bmcTimeout,
SSLVerify: *insecureSkipVerify,
User: *username,
Pass: *password,
Disable404Retry: *disable404Retry,
}

config.NewConfig(c)
Expand Down
17 changes: 10 additions & 7 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ func Fetch(uri, host, profile string, client *retryablehttp.Client) func() ([]by
return nil, err
}
defer EmptyAndCloseBody(resp)
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
if resp.StatusCode == http.StatusNotFound {
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
switch resp.StatusCode {
case http.StatusNotFound:
// When --disable-404-retry or FISHYMETRICS_DISABLE_404_RETRY=1, skip retries.
if config.GetConfig().Disable404Retry {
return nil, fmt.Errorf("HTTP status %d", http.StatusNotFound)
}
for retryCount < 3 && resp.StatusCode == http.StatusNotFound {
time.Sleep(client.RetryWaitMin)
resp, err = DoRequest(client, req)
Expand All @@ -63,12 +68,10 @@ func Fetch(uri, host, profile string, client *retryablehttp.Client) func() ([]by
defer EmptyAndCloseBody(resp)
retryCount++
}
if err != nil {
return nil, err
} else if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
} else if resp.StatusCode == http.StatusUnauthorized {
case http.StatusUnauthorized:
if ChassisCreds.Vault != nil {
// Credentials may have rotated, clear cache, go to vault and get the latest
ChassisCreds.mu.Lock()
Expand Down Expand Up @@ -103,7 +106,7 @@ func Fetch(uri, host, profile string, client *retryablehttp.Client) func() ([]by
if resp.StatusCode == http.StatusUnauthorized {
return nil, ErrInvalidCredential
}
} else {
default:
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
}
Expand Down
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
)

type Config struct {
BMCScheme string
BMCTimeout time.Duration
SSLVerify bool
User string
Pass string
BMCScheme string
BMCTimeout time.Duration
SSLVerify bool
User string
Pass string
Disable404Retry bool
}

var (
Expand Down
Loading