From 378047e622f0eadea4012b36fe1efb97f0048f7c Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 9 Jul 2022 12:34:21 +0200 Subject: [PATCH] Production improvements --- great_ai/constants.py | 2 +- great_ai/deploy/routes/dashboard/create_dash_app.py | 11 +++++++++-- great_ai/parse_arguments.py | 2 +- great_ai/persistence/mongodb_driver.py | 11 +++++++++-- great_ai/remote/call_remote_great_ai_async.py | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/great_ai/constants.py b/great_ai/constants.py index 49b2dea..46be748 100644 --- a/great_ai/constants.py +++ b/great_ai/constants.py @@ -27,5 +27,5 @@ ONLINE_TAG_NAME = "online" SERVER_NAME = "GreatAI-Server" -SE4ML_WEBSITE = "https://se-ml.github.io/practices/" +SE4ML_WEBSITE = "https://se-ml.github.io/practices" LIST_ITEM_PREFIX = " 🔩 " diff --git a/great_ai/deploy/routes/dashboard/create_dash_app.py b/great_ai/deploy/routes/dashboard/create_dash_app.py index 51d2d48..8b239e4 100644 --- a/great_ai/deploy/routes/dashboard/create_dash_app.py +++ b/great_ai/deploy/routes/dashboard/create_dash_app.py @@ -80,7 +80,11 @@ def create_dash_app(function_name: str, version: str, function_docs: str) -> Fla html.Div(className="space-filler"), get_footer(), interval := dcc.Interval( - interval=4 * 1000, # in milliseconds + interval=2 * 1000, # in milliseconds + n_intervals=0, + max_intervals=1 + if get_context().is_production + else -1, # will be incremented in production upon each successful request ), ] ) @@ -113,6 +117,7 @@ def create_dash_app(function_name: str, version: str, function_docs: str) -> Fla Output(execution_time_histogram_container, "children"), Output(parallel_coordinates, "figure"), Output(parallel_coordinates, "style"), + Output(interval, "max_intervals"), Input(table, "page_current"), Input(table, "page_size"), Input(table, "sort_by"), @@ -124,7 +129,7 @@ def create_dash_app(function_name: str, version: str, function_docs: str) -> Fla page_size: int, sort_by: List[Dict[str, Union[str, int]]], filter_query: str, - n_intervals: int, + n_intervals: Optional[int], ) -> Tuple[ List[Dict[str, Any]], int, @@ -133,6 +138,7 @@ def create_dash_app(function_name: str, version: str, function_docs: str) -> Fla Any, go.Figure, Dict[str, Any], + int, ]: conjunctive_filters = ( [get_filter_from_datatable(f) for f in filter_query.split(" && ")] @@ -165,6 +171,7 @@ def create_dash_app(function_name: str, version: str, function_docs: str) -> Fla execution_time_histogram, parallel_coords_fig, style, + ((n_intervals or 0) + 1) if get_context().is_production else -1, ) return app.server diff --git a/great_ai/parse_arguments.py b/great_ai/parse_arguments.py index 60974cd..e816b6b 100644 --- a/great_ai/parse_arguments.py +++ b/great_ai/parse_arguments.py @@ -12,7 +12,7 @@ def parse_arguments() -> Namespace: help="the name of the file containing your to-be-served function such as `main.py`\n", ) - default_host = "127.0.0.1" + default_host = "0.0.0.0" parser.add_argument( "--host", type=str, diff --git a/great_ai/persistence/mongodb_driver.py b/great_ai/persistence/mongodb_driver.py index 155e6d4..9cb4e9a 100644 --- a/great_ai/persistence/mongodb_driver.py +++ b/great_ai/persistence/mongodb_driver.py @@ -1,7 +1,7 @@ from datetime import datetime from typing import Any, Dict, List, Optional, Sequence, Tuple -from pymongo import MongoClient +from pymongo import ASCENDING, DESCENDING, MongoClient from ..utilities import chunk from ..views import Filter, SortBy, Trace @@ -31,6 +31,11 @@ class MongodbDriver(TracingDatabaseDriver): "Please configure the MongoDB access options by calling MongodbDriver.configure_credentials" ) + with MongoClient[Any](self.mongo_connection_string) as client: + client[self.mongo_database].traces.create_index( + [("tags", ASCENDING), ("created", DESCENDING)], background=True + ) + @classmethod def configure_credentials( # type: ignore cls, @@ -93,11 +98,13 @@ class MongodbDriver(TracingDatabaseDriver): "filter": {}, } - and_query: List[Dict[str, Any]] = [{}] + and_query: List[Dict[str, Any]] = [] and_query.extend({"tags": tag} for tag in conjunctive_tags) and_query.extend( {f.property: {self._get_operator(f): f.value}} for f in conjunctive_filters ) + if not and_query: + and_query.append({}) if since: and_query.append({"created": {"$gte": since}}) diff --git a/great_ai/remote/call_remote_great_ai_async.py b/great_ai/remote/call_remote_great_ai_async.py index 8551772..94b7713 100644 --- a/great_ai/remote/call_remote_great_ai_async.py +++ b/great_ai/remote/call_remote_great_ai_async.py @@ -13,7 +13,7 @@ async def call_remote_great_ai_async( base_uri: str, data: Mapping[str, Any], retry_count: int = 4, - timeout_in_seconds: int = 60, + timeout_in_seconds: int = 300, model_class: Optional[Type[T]] = None, ) -> Trace[T]: