| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package env
- import (
- "time"
- "github.com/opencost/opencost/core/pkg/env"
- "github.com/opencost/opencost/core/pkg/log"
- "github.com/opencost/opencost/core/pkg/util/timeutil"
- )
- // Environment variables specific to the running of opencost
- const (
- DefaultAPIPort = 9003
- defaultOpencostNamespace = "opencost"
- )
- const (
- UTCOffsetEnvVar = "UTC_OFFSET"
- MCPQueryTimeoutSecondsEnvVar = "MCP_QUERY_TIMEOUT_SECONDS"
- )
- func GetOpencostAPIPort() int {
- return env.GetAPIPortWithDefault(DefaultAPIPort)
- }
- // GetOpencostNamespace returns the environment variable value that is set for the kubernetes namespace
- // this service is installed in.
- func GetOpencostNamespace() string {
- return env.GetInstallNamespace(defaultOpencostNamespace)
- }
- // GetUTCOffset returns the environment variable value for UTCOffset
- func GetUTCOffset() string {
- return env.Get(UTCOffsetEnvVar, "")
- }
- // GetParsedUTCOffset returns the duration of the configured UTC offset
- func GetParsedUTCOffset() time.Duration {
- offset, err := timeutil.ParseUTCOffset(GetUTCOffset())
- if err != nil {
- log.Warnf("Failed to parse UTC offset: %s", err)
- return time.Duration(0)
- }
- return offset
- }
- // GetMCPQueryTimeout returns the configured timeout for MCP query operations.
- // Default is 60 seconds, but can be configured via MCP_QUERY_TIMEOUT_SECONDS environment variable.
- // Minimum timeout is 1 second to prevent immediate timeouts.
- func GetMCPQueryTimeout() time.Duration {
- seconds := env.GetInt(MCPQueryTimeoutSecondsEnvVar, 60)
- if seconds <= 0 {
- seconds = 1
- }
- return time.Duration(seconds) * time.Second
- }
|