From 2433a1b98190b0bfcc69a448bcef5bfe5c061e09 Mon Sep 17 00:00:00 2001 From: Stephan Preeker Date: Fri, 5 Jan 2018 11:58:33 +0100 Subject: [PATCH] minor documentation / annotation fixes --- pillar/api/search/elastic_indexing.py | 8 +++----- pillar/api/search/index.py | 7 ++++--- pillar/api/search/queries.py | 9 +++++++-- pillar/cli/elastic.py | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pillar/api/search/elastic_indexing.py b/pillar/api/search/elastic_indexing.py index c07e0ff8..603f911b 100644 --- a/pillar/api/search/elastic_indexing.py +++ b/pillar/api/search/elastic_indexing.py @@ -28,7 +28,7 @@ def push_updated_user(user_to_index: dict): if not doc: return - log.debug('index update user elasticsearch %s', doc._id) + log.debug('Index update user doc elasticsearch %s.', doc._id) doc.save() @@ -36,7 +36,6 @@ def index_node_save(node_to_index: dict): """ Push an update to the Elastic index when a node item is saved. """ - if not node_to_index: return @@ -45,7 +44,7 @@ def index_node_save(node_to_index: dict): if not doc: return - log.debug('index created node elasticsearch %s', doc._id) + log.debug('Index created node doc elasticsearch %s.', doc._id) doc.save() @@ -53,8 +52,7 @@ def index_node_delete(delete_id: str): """ Delete node document from Elastic index useing a node id """ - - log.debug('index node delete %s', delete_id) + log.debug('Index node doc delete %s', delete_id) try: doc = documents.Node.get(id=delete_id) diff --git a/pillar/api/search/index.py b/pillar/api/search/index.py index 2efff9e1..4d6cdb4b 100644 --- a/pillar/api/search/index.py +++ b/pillar/api/search/index.py @@ -14,11 +14,12 @@ log = logging.getLogger(__name__) class ResetIndexTask(object): """ Clear and build index / mapping """ - index_key = '' - """Key into the ELASTIC_INDICES dict in the app config.""" + + # Key into the ELASTIC_INDICES dict in the app config. + index_key: str = '' # List of elastic document types - doc_types = [] + doc_types: List = [] name = 'remove index' def __init__(self): diff --git a/pillar/api/search/queries.py b/pillar/api/search/queries.py index cb81e2ed..57987b85 100644 --- a/pillar/api/search/queries.py +++ b/pillar/api/search/queries.py @@ -1,7 +1,8 @@ import json +import logging + from elasticsearch import Elasticsearch from elasticsearch_dsl import Search, Q -import logging from pillar import current_app log = logging.getLogger(__name__) @@ -12,7 +13,9 @@ user_agg_terms = ['roles', ] class TheELKClient(): """ - current_app is not available when on import + Elastic-client singleton. + + `current_app` is not available when on import """ client: Elasticsearch = None @@ -23,6 +26,7 @@ class TheELKClient(): else: return self.client + elk = TheELKClient() @@ -89,6 +93,7 @@ def do_search(query: str, terms: dict) -> dict: add_aggs_to_search(search, node_agg_terms) if log.isEnabledFor(logging.DEBUG): + # logging removes readable indendation. print(json.dumps(search.to_dict(), indent=4)) response = search.execute() diff --git a/pillar/cli/elastic.py b/pillar/cli/elastic.py index 48e4ea6d..d659178f 100644 --- a/pillar/cli/elastic.py +++ b/pillar/cli/elastic.py @@ -79,7 +79,7 @@ def _reindex_nodes(): nodes_coll = nodes_coll.find({'project': {'$in': _public_project_ids()}}) node_count = nodes_coll.count() - log.debug('Reindexing nodes %d in Elastic', node_count) + log.debug('Nodes %d will be reindexed in Elastic', node_count) from pillar.celery.search_index_tasks import prepare_node_data from pillar.api.search import elastic_indexing @@ -89,7 +89,7 @@ def _reindex_nodes(): to_index = prepare_node_data('', node=node) elastic_indexing.index_node_save(to_index) except (KeyError, AttributeError): - log.exception('Field is missing for %s', node) + log.exception('%s is missing Field', node) continue