Skip to content

Commit

Permalink
datadog monitoring in place
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanCarloMachado committed Jun 25, 2024
1 parent 5a50cc1 commit 7594c0f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions python_search/search/search_ui/terminal_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
import sys
from typing import Any
import json
import time

from getch import getch

from python_search.core_entities import Entry
from python_search.search.search_ui.bm25_search import Bm25Search
from python_search.search.search_ui.search_actions import Actions
from python_search.search.search_ui.semantic_search import SemanticSearch
from python_search.search.search_ui.search_utils import statsd
from python_search.search.search_ui.search_utils import setup_datadog

from python_search.theme import get_current_theme
from python_search.host_system.system_paths import SystemPaths


start_time_script = time.time()
class SearchTerminalUi:
MAX_KEY_SIZE = 35
MAX_CONTENT_SIZE = 35
Expand All @@ -33,6 +35,7 @@ def __init__(self) -> None:
self.tdw = None
self.reloaded = False
self.first_run = True
self.statsd = setup_datadog()

self._setup_entries()

Expand All @@ -41,7 +44,7 @@ def run(self):
Rrun the application main loop
"""

statsd.increment("python_search_run_triggered")
self.statsd.increment("ps_run_triggered")
self._hide_cursor()
self.query = ""
self.selected_row = 0
Expand Down Expand Up @@ -69,8 +72,13 @@ def run(self):
current_key += 1
self.matches.append(key)

# blocking function call
if self.first_run:
end = time.time()
# get diff in milliseconds between time to start adn time to end
self.statsd.histogram("ps_time_to_render_first_run_seconds", (end - start_time_script))
c = self.get_caracter()
statsd.increment("python_search_run_get_char")
self.statsd.increment("python_search_run_get_char")
self.process_chars(self.query, c)

def search(self, query):
Expand All @@ -80,7 +88,7 @@ def search(self, query):
bm25_results = self.search_bm25.search(query)

semantic_results = []
if self.ENABLE_SEMANTIC_SEARCH and not self.first_run:
if self.ENABLE_SEMANTIC_SEARCH and not self.first_run and not self.reloaded:
semantic_results = self.search_semantic.search(query)

for i in range(self.NUMBER_ENTRIES_TO_RETURN):
Expand Down Expand Up @@ -146,6 +154,7 @@ def process_chars(self, query: str, c: str):
elif ord_c == 10:
# enter
self.actions.run_key(self.matches[self.selected_row])
self.statsd.increment("ps_run_key")
if self.query:
self._get_data_warehouse().write_event(
"python_search_typed_query", {"query": query}
Expand Down

0 comments on commit 7594c0f

Please sign in to comment.