Skip to content

Commit

Permalink
Druid Intervals Issues prevents metadata pull (#526)
Browse files Browse the repository at this point in the history
* Druid Intervals Issues

* fetching druid version

* fixes

* space

* version fix

* landscape issues
  • Loading branch information
kkalyan authored and mistercrunch committed Jun 21, 2016
1 parent 485234b commit 30da408
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,14 @@ def get_datasources(self):

return json.loads(requests.get(endpoint).text)

def get_druid_version(self):
endpoint = (
"http://{obj.coordinator_host}:{obj.coordinator_port}/status"
).format(obj=self)
return json.loads(requests.get(endpoint).text)['version']

def refresh_datasources(self):
self.druid_version = self.get_druid_version()
for datasource in self.get_datasources():
if datasource not in config.get('DRUID_DATA_SOURCE_BLACKLIST'):
DruidDatasource.sync_to_db(datasource, self)
Expand Down Expand Up @@ -1028,6 +1035,13 @@ def get_metric_obj(self, metric_name):
if m.metric_name == metric_name
][0]

def version_higher(self, v1, v2):
v1nums = [int(n) for n in v1.split('.')]
v2nums = [int(n) for n in v2.split('.')]
return v1nums[0] > v2nums[0] or \
(v1nums[0] == v2nums[0] and v1nums[1] > v2nums[1]) or \
(v1nums[0] == v2nums[0] and v1nums[1] == v2nums[1] and v1nums[2] > v2nums[2])

def latest_metadata(self):
"""Returns segment metadata from the latest segment"""
client = self.cluster.get_pydruid_client()
Expand All @@ -1040,8 +1054,9 @@ def latest_metadata(self):
# we need to set this interval to more than 1 day ago to exclude
# realtime segments, which trigged a bug (fixed in druid 0.8.2).
# https://groups.google.com/forum/#!topic/druid-user/gVCqqspHqOQ
start = (0 if self.version_higher(self.cluster.druid_version, '0.8.2') else 1)
intervals = (max_time - timedelta(days=7)).isoformat() + '/'
intervals += (max_time - timedelta(days=1)).isoformat()
intervals += (max_time - timedelta(days=start)).isoformat()
segment_metadata = client.segment_metadata(
datasource=self.datasource_name,
intervals=intervals)
Expand Down
1 change: 1 addition & 0 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def test_client(self, PyDruid):

db.session.add(cluster)
cluster.get_datasources = Mock(return_value=['test_datasource'])
cluster.get_druid_version = Mock(return_value='0.9.1')
cluster.refresh_datasources()
datasource_id = cluster.datasources[0].id
db.session.commit()
Expand Down

0 comments on commit 30da408

Please sign in to comment.