Skip to content

Commit 199cd73

Browse files
portantendokos
authored andcommitted
Fix indexing work to improve error handling
We fix the default "read timeout" to be very large so that we don't timeout prematurely and retry needlessly for template operations. We have enhanced the error handling so that we don't always assume we get a response object, and we dump out error messages that are unexpected for now. Further we also: * add support for counting the number of times we retry a bulk request * add the new es_put_template wrapper which properly handles the retries * pull the print() function calls out of es_index() so that the caller can decide what they want to emit, not have that inside the library * fix the missing "math" library module reference * fix how we mock out the timestamps to avoid global vs. local variable namespace conflicts * move the changes to the urllib3 and elasticsearch1 logging libraries to the code path were we actually use Elasticsearch
1 parent 956075d commit 199cd73

File tree

11 files changed

+173
-53
lines changed

11 files changed

+173
-53
lines changed

server/pbench/bin/gold/test-7.10.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.10
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 514, duplicates: 0, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.result-data.2018-02-02 5
47
Index: pbench-unittests.run.2018-02 47
58
Index: pbench-unittests.tool-data-iostat.2018-02-02 120
@@ -7511,6 +7514,7 @@ len(actions) = 50
75117514
"_type": "pbench-tool-data-pidstat"
75127515
}
75137516
]
7517+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 514, duplicates: 0, failures: 0, retries: 0)
75147518
--- Finished indexing for test-7.10 (status=0)
75157519
+++ pbench tree state
75167520
/var/tmp/pbench-test-server/pbench

server/pbench/bin/gold/test-7.11.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.11
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 46, duplicates: 0, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.result-data.2018-02-01 3
47
Index: pbench-unittests.run.2018-02 28
58
Index: pbench-unittests.tool-data-iostat.2018-02-01 15
@@ -3846,6 +3849,7 @@ len(actions) = 33
38463849
"_type": "pbench-tool-data-iostat"
38473850
}
38483851
]
3852+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 46, duplicates: 0, failures: 0, retries: 0)
38493853
--- Finished indexing for test-7.11 (status=0)
38503854
+++ pbench tree state
38513855
/var/tmp/pbench-test-server/pbench

server/pbench/bin/gold/test-7.12.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.12
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 42397, duplicates: 2254, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.run.2018-02 56
47
Index: pbench-unittests.tool-data-iostat.2018-02-05 36
58
Index: pbench-unittests.tool-data-pidstat.2018-02-05 1554
@@ -2948,6 +2951,7 @@ len(actions) = 60
29482951
"_type": "pbench-tool-data-iostat"
29492952
}
29502953
]
2954+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 42397, duplicates: 2254, failures: 0, retries: 0)
29512955
--- Finished indexing for test-7.12 (status=0)
29522956
+++ pbench tree state
29532957
/var/tmp/pbench-test-server/pbench

server/pbench/bin/gold/test-7.4.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
+++ Running indexing for test-7.4
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
26
Bad hostname in sosreport: The sosreport did not collect a hostname other than 'localhost'
37
--- Finished indexing for test-7.4 (status=10)
48
+++ pbench tree state

server/pbench/bin/gold/test-7.5.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
+++ Running indexing for test-7.5
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
26
Bad hostname in sosreport: The sosreport did not collect a hostname other than 'localhost'
37
--- Finished indexing for test-7.5 (status=10)
48
+++ pbench tree state

server/pbench/bin/gold/test-7.6.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.6
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 5, duplicates: 0, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.run.2015-09 5
47
len(actions) = 5
58
[
@@ -120,6 +123,7 @@ len(actions) = 5
120123
"_type": "pbench-run-toc-entry"
121124
}
122125
]
126+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 5, duplicates: 0, failures: 0, retries: 0)
123127
--- Finished indexing for test-7.6 (status=0)
124128
+++ pbench tree state
125129
/var/tmp/pbench-test-server/pbench

server/pbench/bin/gold/test-7.7.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.7
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 5, duplicates: 0, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.run.2015-09 5
47
len(actions) = 5
58
[
@@ -120,6 +123,7 @@ len(actions) = 5
120123
"_type": "pbench-run-toc-entry"
121124
}
122125
]
126+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 5, duplicates: 0, failures: 0, retries: 0)
123127
--- Finished indexing for test-7.7 (status=0)
124128
+++ pbench tree state
125129
/var/tmp/pbench-test-server/pbench

server/pbench/bin/gold/test-7.8.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.8
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 11778, duplicates: 0, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.result-data.2016-10-06 3
47
Index: pbench-unittests.run.2016-10 63
58
Index: pbench-unittests.tool-data-iostat.2016-10-06 27
@@ -45803,6 +45806,7 @@ len(actions) = 48
4580345806
"_type": "pbench-tool-data-iostat"
4580445807
}
4580545808
]
45809+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 11778, duplicates: 0, failures: 0, retries: 0)
4580645810
--- Finished indexing for test-7.8 (status=0)
4580745811
+++ pbench tree state
4580845812
/var/tmp/pbench-test-server/pbench

server/pbench/bin/gold/test-7.9.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
+++ Running indexing for test-7.9
2-
done (end ts: 1900-01-01T00:00:00-UTC, duration: 0.00s, success: 3144, duplicates: 0, failures: 0)
2+
Template: pbench-unittests.run
3+
Template: pbench-unittests.tool-data-iostat
4+
Template: pbench-unittests.tool-data-pidstat
5+
done templates (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3, retries: 0)
36
Index: pbench-unittests.run.2017-04 24
47
Index: pbench-unittests.tool-data-iostat.2017-04-21 60
58
Index: pbench-unittests.tool-data-pidstat.2017-04-21 3060
@@ -1726,6 +1729,7 @@ len(actions) = 45
17261729
"_type": "pbench-tool-data-pidstat"
17271730
}
17281731
]
1732+
done indexing (end ts: 1970-01-01T00:00:00-UTC, duration: 0.00s, successes: 3144, duplicates: 0, failures: 0, retries: 0)
17291733
--- Finished indexing for test-7.9 (status=0)
17301734
+++ pbench tree state
17311735
/var/tmp/pbench-test-server/pbench

server/pbench/bin/index-pbench

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ try:
2323
except ImportError:
2424
from elasticsearch import VERSION as es_VERSION, Elasticsearch
2525

26-
from pbench import es_index
26+
from pbench import tstos, es_index, es_put_template
2727

2828

2929
_VERSION_ = "0.2.0.0"
@@ -33,8 +33,10 @@ _DEBUG = 0
3333
# global - defaults to normal dict, ordered dict for unittests
3434
_dict_const = dict
3535

36-
# 30 second timeout talking to Elasticsearch
37-
_read_timeout = 30
36+
# 100,000 minute timeout talking to Elasticsearch; basically we just don't
37+
# want to timeout waiting for Elasticsearch and then have to retry, as that
38+
# can add undue burden to the Elasticsearch cluster.
39+
_read_timeout = 100000*60
3840

3941
# All indexing uses "create" (instead of "index") to avoid updating
4042
# existing records, allowing us to detect duplicates.
@@ -112,16 +114,12 @@ def fetch_mapping(mapping_fn):
112114
raise MappingFileError("Invalid mapping file: %s" % mapping_fn)
113115
return keys[0], mapping
114116

115-
def es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config):
117+
def es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config, dbg=0):
116118
"""Load the various Elasticsearch index templates required by pbench.
117119
118120
We first load the pbench-run index templates, and then we construct and
119121
load the templates for each tool data index.
120122
"""
121-
if not es:
122-
# Don't do anything if we don't have an Elasticsearch client object.
123-
return
124-
125123
index_settings = _dict_const(
126124
gateway=_dict_const(
127125
local=_dict_const(
@@ -181,7 +179,7 @@ def es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config):
181179
for toolname,frag in tool_mapping_frags.items():
182180
tool_skel = copy.deepcopy(skel)
183181
tool_skel['properties'][toolname] = frag
184-
tool_mapping = _dict_const(("pbench-tool-data-%s" % toolname, tool_skel))
182+
tool_mapping = _dict_const([("pbench-tool-data-%s" % toolname, tool_skel)])
185183
tool_template_body = _dict_const(
186184
template='%s.tool-data-%s.*' % (INDEX_PREFIX, toolname),
187185
settings=index_settings,
@@ -192,7 +190,7 @@ def es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config):
192190
results_mappings = _dict_const()
193191
for mapping_fn in glob.iglob(os.path.join(MAPPING_DIR, "result-*.json")):
194192
key, mapping = fetch_mapping(mapping_fn)
195-
if options.debug_unittest:
193+
if dbg > 0:
196194
print("fetch_mapping: {}".format(key))
197195
from pprint import pprint;
198196
pprint(mapping)
@@ -204,25 +202,26 @@ def es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config):
204202
settings=index_settings,
205203
mappings=results_mappings)
206204

207-
if not es:
208-
# Don't do anything if we don't have an Elasticsearch client object.
209-
print(run_template_name, json.dumps(run_template_body, indent=4, sort_keys=True))
210-
for name, body in tool_templates:
211-
print(name, json.dumps(body, indent=4, sort_keys=True))
212-
return
213-
214205
# FIXME: We should query to see if a template exists, and only
215206
# create it if it does not, or if the version of it is older than
216207
# expected.
217208
try:
218209
# Pbench Run template
219-
res = es.indices.put_template(name=run_template_name, body=run_template_body)
210+
beg, end, retries = es_put_template(es, name=run_template_name, body=run_template_body)
211+
successes = 1
220212
# Pbench Tool Data templates
221213
for name, body in tool_templates:
222214
tool_template_name = '%s.tool-data-%s' % (INDEX_PREFIX,name)
223-
res = es.indices.put_template(name=tool_template_name, body=body)
215+
_, end, retry_count = es_put_template(es, name=tool_template_name, body=body)
216+
retries += retry_count
217+
successes += 1
224218
except Exception as e:
225219
raise TemplateError(e)
220+
else:
221+
print("\tdone templates (end ts: %s, duration: %.2fs,"
222+
" successes: %d, retries: %d)" % (
223+
tstos(end), end - beg, successes, retries))
224+
sys.stdout.flush()
226225

227226

228227
###########################################################################
@@ -1821,7 +1820,7 @@ def main(options, args):
18211820

18221821
# Create the various index templates
18231822
if options.debug_time_operations: ts("es_template")
1824-
es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config)
1823+
es_template(es, options, INDEX_PREFIX, INDEX_VERSION, config, dbg=_DEBUG)
18251824

18261825
# returns 0 or 1
18271826
if options.indexing_errors:
@@ -1831,6 +1830,12 @@ def main(options, args):
18311830
with open(ie_filename, "w") as fp:
18321831
if options.debug_time_operations: ts("es_index")
18331832
res = es_index(es, actions, fp, dbg=_DEBUG)
1833+
beg, end, successes, duplicates, failures, retries = res
1834+
print("\tdone indexing (end ts: %s, duration: %.2fs,"
1835+
" successes: %d, duplicates: %d, failures: %d, retries: %d)" % (
1836+
tstos(end), end - beg, successes, duplicates, failures, retries))
1837+
sys.stdout.flush()
1838+
res = 1 if failures > 0 else 0
18341839

18351840
except ConfigFileNotSpecified as e:
18361841
print(e, file=sys.stderr)

0 commit comments

Comments
 (0)