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

Commit

Permalink
cleaned up Q creation, added tests around inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeale committed Sep 15, 2017
1 parent 4b0cb37 commit 14d61d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
8 changes: 1 addition & 7 deletions librato/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,7 @@ def delete_chart(self, chart_id, space_id, **query_props):
# Queue
#
def new_queue(self, **kwargs):
tags = self.tags
if 'tags' in kwargs:
# Supplied tag set takes precedence
tags.update(kwargs.pop('tags'))

q = Queue(self, tags=tags, **kwargs)
return q
return Queue(self, **kwargs)

#
# misc
Expand Down
8 changes: 2 additions & 6 deletions librato/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def add_tagged(self, name, value, **query_props):

# must remove the inherit_tags key for compliance with json
inherit_tags = query_props.pop('inherit_tags', False)
if inherit_tags:
tags = query_props.get('tags', {})
tags = query_props.get('tags', {})
if inherit_tags or tags == {}:
inheritted_tags = dict(self.connection.get_tags(), **self.get_tags())
query_props['tags'] = dict(inheritted_tags, **tags)

Expand Down Expand Up @@ -140,10 +140,6 @@ def submit(self):
self.chunks = []

for chunk in self.tagged_chunks:
if 'tags' in chunk:
chunk['tags'] = dict(self.tags, **chunk['tags'])
elif self.tags:
chunk['tags'] = dict(self.tags)
self.connection._mexe("measurements", method="POST", query_props=chunk)
self.tagged_chunks = []

Expand Down
7 changes: 6 additions & 1 deletion tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def test_ignore_connection_queue_level_tags(self):
assert len(measurements) == 1
assert measurements[0].get('tags', {}) == {'hi': 'five'}

q.submit()

resp = self.conn.get_tagged('user_cpu', duration=60, tags_search="sky=blue")
assert len(resp['series']) == 0

def test_inherit_queue_connection_level_tags(self):
"""test if queue level tags are ignored when passing measurement level tags"""
conn = librato.connect('user_test', 'key_test', tags={'sky': 'blue', 'company': 'Librato'})
Expand Down Expand Up @@ -288,7 +293,7 @@ def test_md_measurement_level_tag(self):
q.set_tags({'hostname': 'web-1'})

mt1 = int(time.time()) - 5
q.add_tagged('system_cpu', 33.22, time=mt1, tags={"user": "james"})
q.add_tagged('system_cpu', 33.22, time=mt1, tags={"user": "james"}, inherit_tags=True)
q.submit()

# Ensure both tags get submitted
Expand Down

0 comments on commit 14d61d5

Please sign in to comment.