Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 4b94cae

Browse files
authored
Merge pull request #124 from librato/bugfix/gap_detection
Add gap_detection attribute to Stream and allow extra attributes
2 parents 133d5b8 + ce523d7 commit 4b94cae

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

librato/streams.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ def __init__(self, metric=None, source='*', composite=None,
33
name=None, type=None, id=None,
44
group_function=None, summary_function=None,
55
transform_function=None, downsample_function=None,
6-
period=None, split_axis=None,
6+
period=None, split_axis=None, gap_detection=None,
77
min=None, max=None,
88
units_short=None, units_long=None, color=None,
99
# deprecated
10-
composite_function=None
10+
composite_function=None, **kwargs
1111
):
1212
self.metric = metric
1313
self.source = source
@@ -30,6 +30,11 @@ def __init__(self, metric=None, source='*', composite=None,
3030
self.units_short = units_short
3131
self.units_long = units_long
3232
self.color = color
33+
self.gap_detection = gap_detection
34+
35+
# Pick up any attributes that are not explicitly defined
36+
for attr in kwargs:
37+
setattr(self, attr, kwargs[attr])
3338

3439
# Can't have a composite and source/metric
3540
if self.composite:

tests/test_streams.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ def test_init_units(self):
7474
self.assertEqual(Stream(units_short='req/s').units_short, 'req/s')
7575
self.assertEqual(Stream(units_long='requests per second').units_long, 'requests per second')
7676

77+
def test_init_color(self):
78+
self.assertIsNone(Stream().color)
79+
self.assertEqual(Stream(color='#f00').color, '#f00')
80+
81+
def test_init_gap_detection(self):
82+
self.assertIsNone(Stream().gap_detection)
83+
self.assertTrue(Stream(gap_detection=True).gap_detection)
84+
self.assertFalse(Stream(gap_detection=False).gap_detection)
85+
86+
# Adding this to avoid exceptions raised due to unknown Stream attributes
87+
def test_init_with_extra_attributes(self):
88+
attrs = {"color": "#f00", "something": "foo"}
89+
s = Stream(**attrs)
90+
# color is a known attribute
91+
self.assertEqual(s.color, '#f00')
92+
self.assertEqual(s.something, 'foo')
93+
94+
7795
def test_get_payload(self):
7896
self.assertEqual(Stream(metric='my.metric').get_payload(),
7997
{'metric': 'my.metric', 'source': '*'})

0 commit comments

Comments
 (0)