diff --git a/librato/__init__.py b/librato/__init__.py index fb12ce8..8592e34 100644 --- a/librato/__init__.py +++ b/librato/__init__.py @@ -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 diff --git a/librato/queue.py b/librato/queue.py index e9331b5..ffb1f9e 100644 --- a/librato/queue.py +++ b/librato/queue.py @@ -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) @@ -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 = [] diff --git a/tests/test_queue.py b/tests/test_queue.py index f434b77..c63cf7b 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -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'}) @@ -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