[autotest] Change host_label_utils to use bulk_post for metadata.
bulk post is 100x faster than individual upload.
BUG=None
TEST=local run the script and check test ES server:
http://172.25.61.45:9200/_plugin/elastic-hammer/
Query string:
{ "query": {"bool": {"minimum_should_match": 2,
"should": [
{"term": {"_type": "host_labels"}},
{"term": {"time_index": "1431374045"}}
]}},
"size": 100}
Change-Id: Ibbb07b3f08c3e75428413e4954f36cd652314d9e
Reviewed-on: https://chromium-review.googlesource.com/270271
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
Trybot-Ready: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
diff --git a/site_utils/host_label_utils.py b/site_utils/host_label_utils.py
index 9ea433c..2545da5 100755
--- a/site_utils/host_label_utils.py
+++ b/site_utils/host_label_utils.py
@@ -103,12 +103,14 @@
# converted to int to make search faster.
time_index = int(time.time())
hosts = models.Host.objects.filter(invalid=False)
+ data_list = []
for host in hosts:
- info = {'hostname': host.hostname,
+ info = {'_type': _HOST_LABEL_TYPE,
+ 'hostname': host.hostname,
'labels': [label.name for label in host.labels.all()],
'time_index': time_index}
- autotest_es.post(use_http=True, type_str=_HOST_LABEL_TYPE,
- metadata=info, log_time_recorded=False)
+ data_list.append(info)
+ autotest_es.bulk_post(data_list, log_time_recorded=False)
# After all host label information is logged, save the time stamp.
autotest_es.post(use_http=True, type_str=_HOST_LABEL_TIME_INDEX_TYPE,