-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): default configuration and optional config via env
closes #100 Signed-off-by: Robin Opletal <[email protected]>
- Loading branch information
1 parent
670ee5e
commit 2874253
Showing
4 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/oskoperator/osko/internal/utils" | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
MimirRuleRequeuePeriod time.Duration | ||
AlertingBurnRates AlertingBurnRates | ||
} | ||
|
||
type AlertingBurnRates struct { | ||
PageShortWindow float64 | ||
PageLongWindow float64 | ||
TicketShortWindow float64 | ||
TicketLongWindow float64 | ||
} | ||
|
||
func NewConfig() Config { | ||
config := Config{ | ||
MimirRuleRequeuePeriod: utils.GetEnvAsDuration("MIMIR_RULE_REQUEUE_PERIOD", 60*time.Second), | ||
AlertingBurnRates: AlertingBurnRates{ | ||
PageShortWindow: utils.GetEnvAsFloat64("ABR_PAGE_SHORT_WINDOW", 14.4), | ||
PageLongWindow: utils.GetEnvAsFloat64("ABR_PAGE_LONG_WINDOW", 6), | ||
TicketShortWindow: utils.GetEnvAsFloat64("ABR_TICKET_SHORT_WINDOW", 3), | ||
TicketLongWindow: utils.GetEnvAsFloat64("ABR_TICKET_LONG_WINDOW", 1), | ||
}, | ||
} | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// Helper function to read an environment variable or return a default value | ||
func GetEnv(key, defaultValue string) string { | ||
if value, exists := os.LookupEnv(key); exists { | ||
return value | ||
} | ||
return defaultValue | ||
} | ||
|
||
// Helper function to read an environment variable as an integer or return a default value | ||
func GetEnvAsInt(key string, defaultValue int) int { | ||
if valueStr, exists := os.LookupEnv(key); exists { | ||
if value, err := strconv.Atoi(valueStr); err == nil { | ||
return value | ||
} | ||
} | ||
return defaultValue | ||
} | ||
|
||
// Helper function to read an environment variable as a float64 or return a default value | ||
func GetEnvAsFloat64(key string, defaultValue float64) float64 { | ||
if valueStr, exists := os.LookupEnv(key); exists { | ||
if value, err := strconv.ParseFloat(valueStr, 64); err == nil { | ||
return value | ||
} | ||
} | ||
return defaultValue | ||
} | ||
|
||
// Helper function to read an environment variable as a time.Duration or return a default value | ||
func GetEnvAsDuration(key string, defaultValue time.Duration) time.Duration { | ||
if valueStr, exists := os.LookupEnv(key); exists { | ||
if value, err := time.ParseDuration(valueStr); err == nil { | ||
return value | ||
} | ||
} | ||
return defaultValue | ||
} |