mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-17 06:17:40 +00:00
fix(config): support float64 env values in getDetailsFromEnv
The generic typed env reader only handled string/int/bool; any float64 key fell through to default, so CIRCUIT_FAILURE_RATIO, CIRCUIT_BACKOFF_ MULTIPLIER and RETRY_BUDGET_TOKENS_PER_SEC were silently impossible to override via environment (always the compile-time default). Add a float64 case mirroring the int one: parse the GMP_ prefixed key, then the plain key, else the default (envutil has no GetFloat). Test: extended Test_getDetailsFromEnv with float-valid and float-malformed cases.
This commit is contained in:
@@ -71,6 +71,22 @@ func getDetailsFromEnv[T any](key string, defaultValue T) T {
|
||||
return any(boolVal).(T)
|
||||
}
|
||||
return any(envutil.GetBool(key, v)).(T)
|
||||
case float64:
|
||||
// envutil has no GetFloat; handle the GMP_ prefixed and plain keys
|
||||
// directly. Previously float64 env values (CIRCUIT_FAILURE_RATIO,
|
||||
// CIRCUIT_BACKOFF_MULTIPLIER, RETRY_BUDGET_TOKENS_PER_SEC) fell into
|
||||
// default and were silently impossible to configure.
|
||||
if val, ok := os.LookupEnv(prefixedKey); ok {
|
||||
if f, err := strconv.ParseFloat(val, 64); err == nil {
|
||||
return any(f).(T)
|
||||
}
|
||||
}
|
||||
if val, ok := os.LookupEnv(key); ok {
|
||||
if f, err := strconv.ParseFloat(val, 64); err == nil {
|
||||
return any(f).(T)
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
default:
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
@@ -154,6 +154,8 @@ func (suite *Tests) Test_getDetailsFromEnv() {
|
||||
{"default", "envValue", "string value", "TEST_STRING", "envValue"},
|
||||
{0, 123, "int value", "TEST_INT", "123"},
|
||||
{false, true, "bool value", "TEST_BOOL", "true"},
|
||||
{0.5, 0.25, "float value", "TEST_FLOAT", "0.25"},
|
||||
{0.5, 0.5, "float default on malformed value", "TEST_FLOAT_BAD", "not-a-number"},
|
||||
{"default", "default", "default value", "NON_EXISTENT", ""},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user