Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P1004
elasticsearch index freeze/close
Active
Public
Actions
Authored by
olasd
on Apr 12 2021, 10:31 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
import
datetime
import
iso8601
import
elasticsearch
today
=
datetime
.
date
.
today
()
days
=
lambda
n
:
datetime
.
timedelta
(
days
=
n
)
es
=
elasticsearch
.
Elasticsearch
(
hosts
=
[
'esnode1.internal.softwareheritage.org'
,
'esnode2.internal.softwareheritage.org'
,
'esnode3.internal.softwareheritage.org'
],
timeout
=
1200
)
for
l
in
sorted
(
es
.
cat
.
indices
(
h
=
'i,sth,status'
)
.
splitlines
()):
i
,
throttled
,
status
=
l
.
split
()
throttled
=
throttled
==
'true'
if
throttled
and
status
!=
'open'
:
continue
if
i
.
startswith
(
'.'
):
continue
date
=
i
.
split
(
'-'
)[
-
1
]
if
not
date
.
startswith
(
'20'
):
continue
date
=
date
.
replace
(
'.'
,
'-'
)
date
=
iso8601
.
parse_date
(
date
)
.
date
()
info
=
es
.
indices
.
get
(
i
)[
i
]
shards
=
int
(
info
[
'settings'
][
'index'
][
'number_of_shards'
])
if
not
throttled
and
date
<
today
-
days
(
7
):
print
(
'freezing'
,
i
)
es
.
indices
.
freeze
(
i
,
wait_for_active_shards
=
shards
)
status
=
'open'
if
status
==
'open'
and
date
<
today
-
days
(
30
):
print
(
'closing'
,
i
)
es
.
indices
.
close
(
i
)
Event Timeline
olasd
created this paste.
Apr 12 2021, 10:31 AM
2021-04-12 10:31:27 (UTC+2)
vsellier
mentioned this in
T3221: elk: automatically limit log retention
.
Apr 12 2021, 10:37 AM
2021-04-12 10:37:21 (UTC+2)
Log In to Comment