tessg22 / lightweight-curator Goto Github PK
View Code? Open in Web Editor NEWLightweight job to delete old Elasticsearch indices from logging based on percentage
License: Apache License 2.0
Lightweight job to delete old Elasticsearch indices from logging based on percentage
License: Apache License 2.0
Where:
index_name_prefixes = os.getenv("INDEX_NAME_PREFIXES", "infra-,app-,audit-")
What:
Indices in this example with cluster version 4.4.16 don't have "infra-,app-,audit-" prefix convention.
green open project.snow-poker-feature-aloha-potatoes-tree.a41c5e5a1-0c45-4274-a426-7bfc539c6be.2020.09.23 k8pwmycmRkGnYWrbx2OLMw 3 1 30 0 706.3kb 353.1kb
green open project.aloha-cherry.b03e1dfd4-fade-4771-be54-74dd11eb619.2020.09.23 5aXlxOh5TYSq51En78YLbA 3 1 7 0 171kb 85.5kb
Where:
IF size_counter < max_allowed_size condition
What:
I tried to write down simple array of sizes [10, 10, 10, 10, 10] with threshold limit lets say 45.
When I go through first 4 items, condition would look like 40 < 45 which is CORRECT.
WRONG is that same condition would allow me to whitelist also last item:
Where:
indices_to_delete = []
indices_size_counter = 0
for index in sorted(indices, key=lambda x: x.creation_date, reverse=True):
indices_smaller_then_max_allowed_size(index, max_allowed_size, indices_size_counter, indices_to_delete)
What:
Value of indices_size_counter is constantly 0 and not getting incremented inside of indices_smaller_then_max_allowed_size function.
Proposed changes:
indices_to_delete = []
indices_size_counter = 0
for index in sorted(indices, key=lambda x: x.creation_date, reverse=True):
indices_to_delete, indices_size_counter = indices_smaller_then_max_allowed_size(index, max_allowed_size, indices_size_counter, indices_to_delete)
def indices_smaller_then_max_allowed_size(index, limit, indices_size_counter, indices_to_delete):
"""
Returns list of indices which are above threshold limit.
"""
expected_size = index.size + indices_size_counter
if indices_size_counter < limit and expected_size < limit:
indices_size_counter += index.size
logger.info(f"Do not add into actionable list: {index.name}, summed disk usage is {indices_size_counter} B and disk limit is {limit} B")
else:
logger.warning(f"Add into actionable list: {index.name}, summed disk usage is {indices_size_counter} B and disk limit is {limit} B")
indices_to_delete.append(index.name)
return indices_to_delete, indices_size_counter
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.