| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package thanos
- import (
- "fmt"
- "sync"
- "time"
- "github.com/kubecost/cost-model/pkg/env"
- )
- var (
- lock = new(sync.Mutex)
- enabled = env.IsThanosEnabled()
- queryUrl = env.GetThanosQueryUrl()
- offset = env.GetThanosOffset()
- offsetDuration *time.Duration
- queryOffset = fmt.Sprintf(" offset %s", offset)
- )
- // IsEnabled returns true if Thanos is enabled.
- func IsEnabled() bool {
- return enabled
- }
- // QueryURL returns true if Thanos is enabled.
- func QueryURL() string {
- return queryUrl
- }
- // Offset returns the duration string for the query offset that should be applied to thanos
- func Offset() string {
- return offset
- }
- // OffsetDuration returns the Offset as a parsed duration
- func OffsetDuration() time.Duration {
- lock.Lock()
- defer lock.Unlock()
- if offsetDuration == nil {
- d, err := time.ParseDuration(offset)
- if err != nil {
- d = 0
- }
- offsetDuration = &d
- }
- return *offsetDuration
- }
- // QueryOffset returns a string in the format: " offset %s" substituting in the Offset() string.
- func QueryOffset() string {
- return queryOffset
- }
|