-
-
Notifications
You must be signed in to change notification settings - Fork 529
Container with Elasticsearch #2550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1521b52
updated elastic, removed kibana and fixed
drosetti dd7edb3
added elastic conf
drosetti 359e427
added persistency and tls
drosetti 8b4812b
fixed elastic docker
drosetti 7fe65cc
removed useless setting
drosetti e8a01b5
undo
drosetti 7f92bb9
remove
drosetti b2d2b46
moved to index template
drosetti 513b801
changed comment
drosetti e81429c
moved doc indexing in task instead of signal
drosetti 39838f0
added log
drosetti 2555d38
template auto create
drosetti 0707f7d
removed mock
drosetti de051be
fix
drosetti 3dd86cb
elastic support https
drosetti cc785f8
added test for elastic cronjob and a collection to mark the last upda…
drosetti c2944a2
code quality
drosetti 3896e19
print to debug ci
drosetti 0f371ad
debug ci
drosetti e554bee
fixed ci
drosetti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ compose-elk.yml | |
| .python_history | ||
| .viminfo | ||
|
|
||
| # certs | ||
| certs/ | ||
|
|
||
| # docs | ||
| docs_env/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import json | ||
| import logging | ||
|
|
||
| from django.conf import settings | ||
| from django.core.management import BaseCommand | ||
| from elasticsearch import ApiError | ||
| from elasticsearch_dsl import connections | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| # NOTE: this command is runned by uwsgi startup script | ||
|
|
||
| help = "Create or update the index templates in Elasticsearch" | ||
|
|
||
| def handle(self, *args, **options): | ||
| if settings.ELASTIC_HOST: | ||
| self.stdout.write("Creating/updating the templates...") | ||
| # push template | ||
| with open( | ||
| settings.CONFIG_ROOT / "elastic_search_mappings" / "plugin_report.json" | ||
| ) as file_content: | ||
| try: | ||
| connections.get_connection().indices.put_template( | ||
| name="plugin-report", body=json.load(file_content) | ||
| ) | ||
| success_msg = ( | ||
| "created/updated Elasticsearch's template for plugin-report" | ||
| ) | ||
| self.stdout.write(self.style.SUCCESS(success_msg)) | ||
| logger.info(success_msg) | ||
| except ApiError as error: | ||
| self.stdout.write(self.style.ERROR(error)) | ||
| logger.critical(error) | ||
| else: | ||
| self.stdout.write( | ||
| self.style.WARNING("Elasticsearch not active, templates not updated") | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| { | ||
| "index_patterns": [ | ||
| "plugin-report-*" | ||
| ], | ||
| "settings" : { | ||
| "number_of_shards" : 1, | ||
| "number_of_replicas": 0 | ||
| }, | ||
| "mappings": { | ||
| "properties": { | ||
| "config": { | ||
| "properties": { | ||
| "name": { | ||
| "type": "text", | ||
| "fields": { | ||
| "keyword": { | ||
| "type": "keyword" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "job": { | ||
| "properties": { | ||
| "id": { | ||
| "type": "long" | ||
| } | ||
| } | ||
| }, | ||
| "start_time": { | ||
| "type": "date" | ||
| }, | ||
| "end_time": { | ||
| "type": "date" | ||
| }, | ||
| "status": { | ||
| "type": "text", | ||
| "fields": { | ||
| "keyword": { | ||
| "type": "keyword", | ||
| "ignore_above": 256 | ||
| } | ||
| } | ||
| }, | ||
| "report": { | ||
| "type": "flattened" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env bash | ||
| if [ ! -f ./certs/elastic_ca/ca.crt ] && [ ! -f ./certs/elastic_ca/ca.key ] && [ ! -f ./certs/elastic_instance/instance.crt ] && [ ! -f ./certs/elastic_instance/instance.key ]; then | ||
| # start container | ||
| docker pull docker.elastic.co/elasticsearch/elasticsearch:8.15.0 && | ||
| docker run -d --name elasticsearch_cert -v ./elasticsearch_instances.yml:/usr/share/elasticsearch/elasticsearch_instances.yml -it docker.elastic.co/elasticsearch/elasticsearch:8.15.0 && | ||
| # generate ca | ||
| docker exec -ti elasticsearch_cert ./bin/elasticsearch-certutil ca --pem --out ca.zip && | ||
| docker exec -ti elasticsearch_cert unzip ca.zip && | ||
| # generate cert signed with the ca previously generate | ||
| docker exec -ti elasticsearch_cert ./bin/elasticsearch-certutil cert --in /usr/share/elasticsearch/elasticsearch_instances.yml --pem --ca-cert ./ca/ca.crt --ca-key ./ca/ca.key --silent --out cert.zip && | ||
| docker exec -ti elasticsearch_cert unzip cert.zip && | ||
| # extract files from the container | ||
| docker cp elasticsearch_cert:/usr/share/elasticsearch/ca ./certs/elastic_ca && | ||
| docker cp elasticsearch_cert:/usr/share/elasticsearch/elasticsearch ./certs/elastic_instance && | ||
| # down container | ||
| docker kill elasticsearch_cert && | ||
| docker rm elasticsearch_cert | ||
| else | ||
| echo "files already exists" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| instances: | ||
| - name: elasticsearch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timedeltas should not be calculated inside async functions but should be calculated beforehand. That is to avoid that, in case of congestion, this value changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's correct to calculate it inside the task: the alternative is to put it in the beat schedule, but this doesn't work because the function is called once when the schedule is defined and the time range would be the same for all the scheduled tasks. Am i wrong ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, you right. If I remember correctly, in another occasion we managed this case by calculating the time from an element of the database. In this way there's no way of getting this value wrong because this task would change it only at the time of execution. So, if there are any downtimes, there would be no loss of data. (I am afraid of having the sync misaligned cause we lose some data from time to time. That would make data analysis really bad)
(I would still get the time from "now" first and then, instead of doing minus 5 minutes, I would use as lower_threshold the data got from the database of the last update)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I remember what are you talking about, but I didn't find collections: I found some capped collections used to repeat a task in case of failure, it's similar, but not the same. However I found a way to do it with postgres, I proceed with the merge.