File tree 6 files changed +21
-3
lines changed
6 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def read(fname):
12
12
13
13
setup (
14
14
name = 'netflix-spectator-py' ,
15
- version = '0.1.11 ' ,
15
+ version = '0.1.12 ' ,
16
16
description = 'Python library for reporting metrics to Atlas.' ,
17
17
long_description = read ('README.md' ),
18
18
author = 'Brian Harrington' ,
Original file line number Diff line number Diff line change @@ -46,5 +46,5 @@ def count(self):
46
46
47
47
def _measure (self ):
48
48
return {
49
- self .meterId .with_stat ('count' ): self ._count .get_and_set (0 )
49
+ self .meterId .with_default_stat ('count' ): self ._count .get_and_set (0 )
50
50
}
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ def _has_expired(self):
52
52
return (self ._clock .wall_time () - self ._last_update .get ()) > self .ttl
53
53
54
54
def _measure (self ):
55
- id = self .meterId .with_stat ('gauge' )
55
+ id = self .meterId .with_default_stat ('gauge' )
56
56
57
57
if self ._has_expired ():
58
58
v = self ._value .get_and_set (float ('nan' ))
Original file line number Diff line number Diff line change @@ -9,6 +9,12 @@ def tags(self):
9
9
def with_stat (self , v ):
10
10
return self .with_tag ('statistic' , v )
11
11
12
+ def with_default_stat (self , v ):
13
+ if 'statistic' in self ._tags :
14
+ return self
15
+ else :
16
+ return self .with_stat (v )
17
+
12
18
def with_tag (self , k , v ):
13
19
tags = self ._tags .copy ()
14
20
tags [k ] = v
Original file line number Diff line number Diff line change @@ -25,3 +25,9 @@ def test_measure(self):
25
25
self .assertEqual (len (ms ), 1 )
26
26
self .assertEqual (ms [CounterTest .tid .with_stat ('count' )], 1 )
27
27
self .assertEqual (c .count (), 0 )
28
+
29
+ def test_user_statistic (self ):
30
+ c = Counter (CounterTest .tid .with_stat ('totalTime' ))
31
+ c .increment ()
32
+ for id in c ._measure ().keys ():
33
+ self .assertEqual ('totalTime' , id .tags ()['statistic' ])
Original file line number Diff line number Diff line change @@ -33,3 +33,9 @@ def test_ttl_reset(self):
33
33
self .assertTrue (math .isnan (g .get ()))
34
34
self .assertEqual (1 , len (ms ))
35
35
self .assertEqual (42 , ms [GaugeTest .tid .with_stat ('gauge' )])
36
+
37
+ def test_user_statistic (self ):
38
+ g = Gauge (GaugeTest .tid .with_stat ('duration' ))
39
+ g .set (42 )
40
+ for id in g ._measure ().keys ():
41
+ self .assertEqual ('duration' , id .tags ()['statistic' ])
You can’t perform that action at this time.
0 commit comments