-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_isactive_example_test.go
More file actions
53 lines (39 loc) · 1.06 KB
/
set_isactive_example_test.go
File metadata and controls
53 lines (39 loc) · 1.06 KB
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
47
48
49
50
51
52
53
package metrics_test
import (
"fmt"
"time"
"go.withmatt.com/metrics"
)
func ExampleSetVec_SetIsActive() {
sv := metrics.NewSetVecWithTTL("id", time.Hour)
sv.SetIsActive(func(s *metrics.Set) bool {
active, _ := s.GetMetricUint64("active")
return active > 0
})
active := sv.NewUint64Vec("active")
counter := sv.NewUint64Vec("counter")
active.WithLabelValues("a").Inc()
counter.WithLabelValues("a").Add(100)
fmt.Println(active.WithLabelValues("a").Get())
fmt.Println(counter.WithLabelValues("a").Get())
// Output:
// 1
// 100
}
func ExampleSetVec_SetIsActive_multipleConditions() {
sv := metrics.NewSetVecWithTTL("id", 30*time.Minute)
sv.SetIsActive(func(s *metrics.Set) bool {
a, _ := s.GetMetricUint64("gauge_a")
b, _ := s.GetMetricUint64("gauge_b")
return a > 0 || b > 0
})
gaugeA := sv.NewUint64Vec("gauge_a")
gaugeB := sv.NewUint64Vec("gauge_b")
gaugeA.WithLabelValues("x").Inc()
gaugeB.WithLabelValues("x").Add(5)
fmt.Println(gaugeA.WithLabelValues("x").Get())
fmt.Println(gaugeB.WithLabelValues("x").Get())
// Output:
// 1
// 5
}