-
Notifications
You must be signed in to change notification settings - Fork 1
/
factors.go
46 lines (36 loc) · 901 Bytes
/
factors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package static
import (
"time"
"github.com/justinsb/scaler/pkg/factors"
"k8s.io/apimachinery/pkg/util/clock"
)
type staticFactors struct {
clock clock.Clock
values map[string]float64
}
var _ factors.Interface = &staticFactors{}
type staticFactorsSnapshot struct {
timestamp time.Time
values map[string]float64
}
var _ factors.Snapshot = &staticFactorsSnapshot{}
func NewStaticFactors(clock clock.Clock, values map[string]float64) factors.Interface {
p := &staticFactors{
values: values,
clock: clock,
}
return p
}
func (k *staticFactors) Snapshot() (factors.Snapshot, error) {
return &staticFactorsSnapshot{
values: k.values,
timestamp: k.clock.Now(),
}, nil
}
func (s *staticFactorsSnapshot) Get(key string) (float64, bool, error) {
v, found := s.values[key]
return v, found, nil
}
func (s *staticFactorsSnapshot) Timestamp() time.Time {
return s.timestamp
}