diff --git a/README.md b/README.md index 3f760b48..a2739f35 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ def search(): # { # "order_id": 123, # "order_status": "awaiting_delivery", - # "shipment_status": "completed", # }, # ... # ] @@ -59,19 +58,17 @@ def search(): return issues def update(issues): - # Refreshes order and shipment statuses for the provided order IDs + # Refreshes order status for the provided order IDs # # Example SQL: # select # orders.id as order_id, # orders.status as order_status # from orders - # left join shipments - # on shipments.order_id = orders.id # where # orders.id in (); order_ids = [issue["order_id"] for issue in issues] - updated_issues = get_orders_and_shipments_status(order_ids) + updated_issues = get_orders_status(order_ids) return updated_issues def is_solved(issue): diff --git a/docker/docker-compose-dev.yaml b/docker/docker-compose-dev.yaml index 80e582ff..ecf85281 100644 --- a/docker/docker-compose-dev.yaml +++ b/docker/docker-compose-dev.yaml @@ -45,4 +45,4 @@ services: depends_on: - postgres - motoserver - command: python3 src/main.py controller executor + command: sentinela controller executor diff --git a/docker/docker-compose-local.yaml b/docker/docker-compose-local.yaml index db739afc..148bb0f0 100644 --- a/docker/docker-compose-local.yaml +++ b/docker/docker-compose-local.yaml @@ -17,7 +17,7 @@ services: ports: - 8000:8000 healthcheck: - test: python tools/health_check.py 8000 + test: health_check 8000 interval: 10s timeout: 1s retries: 3 @@ -33,4 +33,4 @@ services: - .env.secrets depends_on: - postgres - command: python3 src/main.py controller executor + command: sentinela controller executor diff --git a/docker/docker-compose-scalable.yaml b/docker/docker-compose-scalable.yaml index c42b5e18..d49f5ac8 100644 --- a/docker/docker-compose-scalable.yaml +++ b/docker/docker-compose-scalable.yaml @@ -28,7 +28,7 @@ services: ports: - 8000:8000 healthcheck: - test: python tools/health_check.py 8000 + test: health_check 8000 interval: 10s timeout: 1s retries: 3 @@ -45,7 +45,7 @@ services: depends_on: - postgres - motoserver - command: python3 src/main.py controller + command: sentinela controller sentinela-executor: build: @@ -61,7 +61,7 @@ services: ports: - 8001-8100:8000 healthcheck: - test: python tools/health_check.py 8000 + test: health_check 8000 interval: 10s timeout: 1s retries: 3 @@ -78,4 +78,4 @@ services: depends_on: - postgres - motoserver - command: python3 src/main.py executor + command: sentinela executor diff --git a/docs/how_to_run.md b/docs/how_to_run.md index fab782f9..06c7df2f 100644 --- a/docs/how_to_run.md +++ b/docs/how_to_run.md @@ -18,8 +18,13 @@ For testing purposes, it can be useful to start a container and execute multiple ```shell make run-shell-dev ``` +2. When inside the container, the application can be run in development mode. + ```shell + sentinela controller executor + ``` + or omitting the parameters to run both the controller and executor. -The quality checks can also be run. +The quality checks can also be run using the following commands: 1. Run the tests. ```shell make test-dev @@ -106,7 +111,7 @@ The [Dockerfile](../Dockerfile) is a starting point for building the application 1. Install the dependencies for the application and enabled plugins. ```shell - poetry install --no-root --only $(python ./tools/get_plugins_list.py) + poetry install --no-root --only $(get_plugins_list) ``` ### Deploying the Application @@ -119,9 +124,9 @@ All services must have the environment variables set as specified in the [Config Controllers and executors can be run by specifying them as parameters when starting the application: 1. Run the controller. ```shell - python3 src/main.py controller + sentinela controller ``` 2. Run the executor. ```shell - python3 src/main.py executor + sentinela executor ``` diff --git a/docs/monitor_registering.md b/docs/monitor_registering.md index c407fdc5..82392f37 100644 --- a/docs/monitor_registering.md +++ b/docs/monitor_registering.md @@ -58,7 +58,7 @@ To simplify the registration process, a Python script is available in the `tools The following example demonstrates how to use the script to register a new monitor: ```bash -python tools/register_monitor.py \ +register_monitor \ my_monitor \ monitors/my_monitor/my_monitor.py \ monitors/my_monitor/search_query.sql \ diff --git a/pyproject.toml b/pyproject.toml index e11c2a79..ea8effa1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,13 +3,23 @@ name = "Sentinela" version = "0.7.0" description = "Sentinela Monitoring Platform" authors = [ - { name = "Gabriel Salla", email = "gabriel.c.salla@gmail.com" } + { name = "Gabriel Salla", email = "gabriel.c.salla@gmail.com" }, ] license = { file = "LICENSE.txt" } readme = "README.md" [tool.poetry] -package-mode = false +name = "sentinela" +packages = [ + {include = "*", from = "src"}, + {include = "tools"}, +] + +[tool.poetry.scripts] +sentinela = "main:start" +get_plugins_list = "tools.get_plugins_list:main" +health_check = "tools.health_check:main" +register_monitor = "tools.register_monitor:main" [tool.poetry.dependencies] python = "^3.12" @@ -96,9 +106,9 @@ log_format = "%(asctime)s [%(levelname)s] %(name)s.%(funcName)s.%(lineno)d: %(me # Disable botocore 'datetime.datetime.utcnow()' deprecation warning filterwarnings = [ - "error", "ignore:datetime.datetime.utcnow:DeprecationWarning:botocore", ] + [tool.coverage.run] branch = true diff --git a/resources/kubernetes_template/controller.yaml b/resources/kubernetes_template/controller.yaml index 522c46e0..c9e0ee2d 100644 --- a/resources/kubernetes_template/controller.yaml +++ b/resources/kubernetes_template/controller.yaml @@ -18,7 +18,7 @@ spec: - name: sentinela-controller image: sentinela-local:latest imagePullPolicy: Never - command: ["python3", "src/main.py", "controller"] + command: ["sentinela", "controller"] ports: - containerPort: 8000 env: diff --git a/resources/kubernetes_template/executor.yaml b/resources/kubernetes_template/executor.yaml index 6c0d1c43..26a1168f 100644 --- a/resources/kubernetes_template/executor.yaml +++ b/resources/kubernetes_template/executor.yaml @@ -18,7 +18,7 @@ spec: - name: sentinela-executor image: sentinela-local:latest imagePullPolicy: Never - command: ["python3", "src/main.py", "executor"] + command: ["sentinela", "executor"] ports: - containerPort: 8000 env: diff --git a/src/main.py b/src/main.py index 2592ce1f..4aeaa5ef 100644 --- a/src/main.py +++ b/src/main.py @@ -96,5 +96,5 @@ async def main() -> None: ) -if __name__ == "__main__": +def start() -> None: asyncio.run(main()) diff --git a/tools/get_plugins_list.py b/tools/get_plugins_list.py index 08be2680..70463d03 100644 --- a/tools/get_plugins_list.py +++ b/tools/get_plugins_list.py @@ -14,11 +14,16 @@ def _make_plugin_name(environment: str | None, plugin: str) -> str: return plugin_name -environment = sys.argv[1] if len(sys.argv) > 1 else None +def main() -> None: + environment = sys.argv[1] if len(sys.argv) > 1 else None -with open(os.environ.get("CONFIGS_FILE", "configs.yaml"), "r") as file: - configs = yaml.load(file.read(), Loader=yaml.FullLoader) + with open(os.environ.get("CONFIGS_FILE", "configs.yaml"), "r") as file: + configs = yaml.load(file.read(), Loader=yaml.FullLoader) -if configs["plugins"]: - plugins_list = [_make_plugin_name(environment, plugin) for plugin in configs["plugins"]] - print(",".join(plugins_list)) + if configs["plugins"]: + plugins_list = [_make_plugin_name(environment, plugin) for plugin in configs["plugins"]] + print(",".join(plugins_list)) + + +if __name__ == "__main__": + main() diff --git a/tools/health_check.py b/tools/health_check.py index 4fc2f81f..195777b3 100644 --- a/tools/health_check.py +++ b/tools/health_check.py @@ -2,14 +2,20 @@ import requests -try: - port = sys.argv[1] -except IndexError: - print("Usage: python health_check.py ") - sys.exit(1) - -try: - requests.get(f"http://localhost:{port}/status") -except requests.ConnectionError: - print("Unable to connect to the server") - sys.exit(1) + +def main() -> None: + try: + port = sys.argv[1] + except IndexError: + print("Usage: health_check ") + return + + try: + requests.get(f"http://localhost:{port}/status") + except requests.ConnectionError: + print("Unable to connect to the server") + return + + +if __name__ == "__main__": + main() diff --git a/tools/install_dependencies.sh b/tools/install_dependencies.sh index 6920224b..5f0ab443 100644 --- a/tools/install_dependencies.sh +++ b/tools/install_dependencies.sh @@ -1,7 +1,7 @@ pip install poetry --no-cache-dir poetry install --only main -plugins=$(python ./tools/get_plugins_list.py) +plugins=$(get_plugins_list) if ! [ "x$plugins" = "x" ]; then poetry install --only $plugins diff --git a/tools/install_tests_dependencies.sh b/tools/install_tests_dependencies.sh index 9228cbe5..292da1ef 100644 --- a/tools/install_tests_dependencies.sh +++ b/tools/install_tests_dependencies.sh @@ -1,4 +1,4 @@ -plugins=$(python ./tools/get_plugins_list.py tests) +plugins=$(get_plugins_list) poetry install --only dev if ! [ "x$plugins" = "x" ]; then