def get(self, request, label):
data = set()
futures = []
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
for host in models.Shard.objects.filter(proxy=True):
futures.append(executor.submit(util.get, '{}/api/v1/label/{}/values'.format(host.url, label), headers=self.headers))
for future in concurrent.futures.as_completed(futures):
try:
result = future.result()
# Need to try to decode the json BEFORE we raise_for_status
# so that we can pass back the error message from Prometheus
_json = result.json()
result.raise_for_status()
logger.debug('Appending data from %s', result.request.url)
data.update(_json['data'])
except:
logger.exception('Error with response')
_json['promgen_proxy_request'] = result.request.url
return JsonResponse(_json, status=result.status_code)
return JsonResponse({
'status': 'success',
'data': sorted(data)
})
评论列表
文章目录