Skip to content

Commit

Permalink
feat(elasticsearch): add logging option for query execution
Browse files Browse the repository at this point in the history
Add a logging option to Elasticsearch query configuration. Include a
new `log` field in configuration and form schema. Log query details
when the `log` flag is enabled.
  • Loading branch information
atompie committed Aug 22, 2024
1 parent ebc3758 commit cb3eebf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import field_validator
import json
from tracardi.domain.named_entity import NamedEntity
Expand All @@ -8,6 +10,7 @@ class Config(PluginConfig):
source: NamedEntity
index: NamedEntity
query: str
log: Optional[bool] = False

@field_validator("index")
@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ async def run(self, payload: dict, in_edge=None) -> Result:
if 'size' not in query:
query["size"] = 20

if self.config.log:
self.console.log(f"Executed query {query}")

if query["size"] > 50:
self.console.warning("Fetching more then 50 records may impact the GUI performance.")

Expand Down Expand Up @@ -93,7 +96,8 @@ def register() -> Plugin:
"id": None
},
"index": None,
"query": "{\"query\":{\"match_all\":{}}}"
"query": "{\"query\":{\"match_all\":{}}}",
"log": False
},
manual="elasticsearch_query_action",
form=Form(
Expand Down Expand Up @@ -125,7 +129,13 @@ def register() -> Plugin:
name="Query",
description="Please provide Elasticsearch DSL query.",
component=FormComponent(type="json", props={"label": "DSL query"})
)
),
FormField(
id="log",
name="Log query",
description="Switch logging query body. Please disable when tests are finished.",
component=FormComponent(type="bool", props={"label": "Log query"})
),
]
)
]
Expand Down

0 comments on commit cb3eebf

Please sign in to comment.