Skip to content

Commit add46d0

Browse files
Add delete race subcommand (elastic#186)
With this commit we enhance `night-rally-admin` with a delete race subcommand which can be used to cleanup broken results from the metrics store in a consistent manner.
1 parent 07d387e commit add46d0

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ If you have made an error you can also remove specific annotations by id.
6868

6969
For more details, please issue `night-rally-admin delete annotation --help`.
7070

71+
#### Remove a race
72+
73+
Sometimes we need to redo a benchmark run and then we need to cleanup data from the prior run. In order to do so, `night-rally-admin` can delete all relevant data.
74+
75+
1. Issue `night-rally-admin list races --environment=nightly` and find the race id of the race(s) you need to delete. Note that only the 20 most recent races are shown. You can show more, by specifying `--limit=NUMBER`.
76+
2. Suppose the id of the race that we want to delete is `53f37522-b761-4e46-9a5c-e7f0d9d9258f`. Then issue `night-rally-admin delete race --id=53f37522-b761-4e46-9a5c-e7f0d9d9258f`. This will remove all data about this race from the metrics store.
77+
78+
For more details, please issue `night-rally-admin delete race --help`.
79+
7180
**Note:** The admin tool also supports a dry-run mode for all commands that would change the data store. Just append `--dry-run`.
7281

7382
#### Find logs, telemetry or heapdumps from older nightly runs

night_rally/admin.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,52 @@ def delete_annotation(es, args):
197197
raise
198198

199199

200+
def delete_race(es, args):
201+
import elasticsearch
202+
203+
def do_delete(index, body, race_id):
204+
try:
205+
return es.delete_by_query(index=index, body=body)
206+
except elasticsearch.TransportError as e:
207+
if e.status_code == 404:
208+
print("Did not find [%s]." % race_id)
209+
else:
210+
raise
211+
212+
environment = args.environment
213+
races = args.id.split(",")
214+
if args.dry_run:
215+
if len(races) == 1:
216+
print("Would delete race with id [%s] in environment [%s]." % (races[0], environment))
217+
else:
218+
print("Would delete %s races: %s in environment [%s]." % (len(races), races, environment))
219+
else:
220+
for race_id in races:
221+
selector = {
222+
"query": {
223+
"bool": {
224+
"filter": [
225+
{
226+
"term": {
227+
"environment": environment
228+
}
229+
},
230+
{
231+
"term": {
232+
"race-id": race_id
233+
}
234+
}
235+
]
236+
}
237+
}
238+
}
239+
do_delete(index="rally-races-*", body=selector, race_id=race_id)
240+
do_delete(index="rally-results-*", body=selector, race_id=race_id)
241+
do_delete(index="rally-metrics-*", body=selector, race_id=race_id)
242+
243+
print("Successfully deleted [%s] in environment [%s]." % (race_id, environment))
244+
245+
200246
def arg_parser():
201247
def positive_number(v):
202248
value = int(v)
@@ -296,7 +342,7 @@ def positive_number(v):
296342
"configuration",
297343
metavar="configuration",
298344
help="",
299-
choices=["annotation"])
345+
choices=["annotation", "race"])
300346
delete_parser.add_argument(
301347
"--dry-run",
302348
help="Just show what would be done but do not apply the operation.",
@@ -305,7 +351,7 @@ def positive_number(v):
305351
)
306352
delete_parser.add_argument(
307353
"--id",
308-
help="Id of the annotation to delete. Separate multiple ids with a comma.",
354+
help="Ids of the items to delete. Separate multiple ids with a comma.",
309355
required=True
310356
)
311357
delete_parser.add_argument(
@@ -333,6 +379,8 @@ def main():
333379
add_annotation(es, args)
334380
elif args.subcommand == "delete" and args.configuration == "annotation":
335381
delete_annotation(es, args)
382+
elif args.subcommand == "delete" and args.configuration == "race":
383+
delete_race(es, args)
336384
else:
337385
parser.print_help(file=sys.stderr)
338386
exit(1)

night_rally/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def load():
3030
http_auth = (cfg["datastore.user"], cfg["datastore.password"]) if secure else None
3131
certs = certifi.where() if secure else None
3232

33-
return elasticsearch.Elasticsearch(hosts=hosts, http_auth=http_auth, ca_certs=certs)
33+
return elasticsearch.Elasticsearch(hosts=hosts, http_auth=http_auth, ca_certs=certs, timeout=60)

0 commit comments

Comments
 (0)