@@ -40,84 +40,3 @@ type UsageParams struct {
4040 // ExtraParams are extra parameters for the usage db client, which are client specific.
4141 ExtraParams map [string ]string `yaml:"extraParams" json:"extraParams"`
4242}
43-
44- func (up * UsageParams ) SetDefaults () {
45- if up .HalfLifePeriod == nil {
46- // noop: disabled by default
47- }
48- if up .WindowSize == nil {
49- windowSize := time .Hour * 24 * 7
50- up .WindowSize = & windowSize
51- }
52- if up .WindowType == nil {
53- windowType := SlidingWindow
54- up .WindowType = & windowType
55- }
56- }
57-
58- // WindowType defines the type of time window for aggregating usage data
59- type WindowType string
60-
61- const (
62- // TumblingWindow represents non-overlapping, fixed-size time windows
63- // Example: 1-hour windows at 0-1h, 1-2h, 2-3h
64- TumblingWindow WindowType = "tumbling"
65-
66- // SlidingWindow represents overlapping time windows that slide forward
67- // Example: a 1-hour sliding window will consider the usage of the last 1 hour prior to the current time.
68- SlidingWindow WindowType = "sliding"
69- )
70-
71- // IsValid returns true if the WindowType is a valid value
72- func (wt WindowType ) IsValid () bool {
73- switch wt {
74- case TumblingWindow , SlidingWindow :
75- return true
76- default :
77- return false
78- }
79- }
80-
81- // GetDefaultWindowType returns the default window type (sliding)
82- func GetDefaultWindowType () WindowType {
83- return SlidingWindow
84- }
85-
86- // GetWindowTypeOrDefault returns the window type if set, otherwise returns the default (sliding)
87- func (up * UsageParams ) GetWindowTypeOrDefault () WindowType {
88- if up .WindowType == nil {
89- return GetDefaultWindowType ()
90- }
91- return * up .WindowType
92- }
93-
94- func (up * UsageParams ) GetExtraDurationParamOrDefault (key string , defaultValue time.Duration ) time.Duration {
95- if up .ExtraParams == nil {
96- return defaultValue
97- }
98-
99- value , exists := up .ExtraParams [key ]
100- if ! exists {
101- return defaultValue
102- }
103-
104- duration , err := time .ParseDuration (value )
105- if err != nil {
106- return defaultValue
107- }
108-
109- return duration
110- }
111-
112- func (up * UsageParams ) GetExtraStringParamOrDefault (key string , defaultValue string ) string {
113- if up .ExtraParams == nil {
114- return defaultValue
115- }
116-
117- value , exists := up .ExtraParams [key ]
118- if ! exists {
119- return defaultValue
120- }
121-
122- return value
123- }
0 commit comments