Skip to content

Commit e537a85

Browse files
committed
Add support for retentions setting in create_tenant, solves #7
1 parent fc39c0c commit e537a85

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

hawkular/metrics.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@
3131
from urllib2 import Request, urlopen, URLError, HTTPError, HTTPErrorProcessor, build_opener, install_opener
3232
from urllib import quote, urlencode
3333

34-
"""
35-
TODO: Search datapoints with tags.. tag datapoints.
36-
TODO: Allow changing instance's tenant?
37-
TODO: Authentication
38-
TODO: Remove HawkularMetricsConnectionError and use HawkularMetricsError only?
39-
TODO: HWKMETRICS-110 (fetching a single definition)
40-
TODO: Stats queries
41-
"""
42-
4334
class MetricType:
4435
Gauge = 'gauges'
4536
Availability = 'availability'
@@ -388,15 +379,16 @@ def query_tenants(self):
388379
"""
389380
return self._get(self._get_tenants_url())
390381

391-
def create_tenant(self, tenant_id):
382+
def create_tenant(self, tenant_id, retentions=None):
392383
"""
393384
Create a tenant. Currently nothing can be set (to be fixed after the master
394385
version of Hawkular-Metrics has fixed implementation.
395386
"""
396387
item = { 'id': tenant_id }
388+
if retentions is not None:
389+
item['retentions'] = retentions
397390

398-
tenants_url = self._get_tenants_url()
399-
self._post(tenants_url, json.dumps(item, indent=2))
391+
self._post(self._get_tenants_url(), json.dumps(item, indent=2))
400392

401393
"""
402394
Static methods

hawkular/metrics_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ def test_tenant_creation(self):
4141
expect = { 'id': tenant }
4242
self.assertIn(expect, tenants)
4343

44-
def test_tenant_creation_with_retentions_and_aggregations(self):
45-
pass
44+
def test_tenant_creation_with_retentions(self):
45+
tenant = str(uuid.uuid4())
46+
retentions = { 'gauge': 8, 'availability': 30 }
47+
self.client.create_tenant(tenant, retentions)
48+
49+
expect = { 'id': tenant, 'retentions': { 'gauge': 8, 'availability': 30 } }
50+
self.assertIn(expect, self.client.query_tenants())
4651

4752
class MetricsTestCase(TestMetricFunctionsBase):
4853
"""

0 commit comments

Comments
 (0)