Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def search():
# {
# "order_id": 123,
# "order_status": "awaiting_delivery",
# "shipment_status": "completed",
# },
# ...
# ]
Expand All @@ -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 (<list_of_order_ids>);
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):
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ services:
depends_on:
- postgres
- motoserver
command: python3 src/main.py controller executor
command: sentinela controller executor
4 changes: 2 additions & 2 deletions docker/docker-compose-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,4 +33,4 @@ services:
- .env.secrets
depends_on:
- postgres
command: python3 src/main.py controller executor
command: sentinela controller executor
8 changes: 4 additions & 4 deletions docker/docker-compose-scalable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +45,7 @@ services:
depends_on:
- postgres
- motoserver
command: python3 src/main.py controller
command: sentinela controller

sentinela-executor:
build:
Expand All @@ -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
Expand All @@ -78,4 +78,4 @@ services:
depends_on:
- postgres
- motoserver
command: python3 src/main.py executor
command: sentinela executor
13 changes: 9 additions & 4 deletions docs/how_to_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
```
2 changes: 1 addition & 1 deletion docs/monitor_registering.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
16 changes: 13 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion resources/kubernetes_template/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion resources/kubernetes_template/executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ async def main() -> None:
)


if __name__ == "__main__":
def start() -> None:
asyncio.run(main())
17 changes: 11 additions & 6 deletions tools/get_plugins_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
28 changes: 17 additions & 11 deletions tools/health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import requests

try:
port = sys.argv[1]
except IndexError:
print("Usage: python health_check.py <port>")
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 <port>")
return

try:
requests.get(f"http://localhost:{port}/status")
except requests.ConnectionError:
print("Unable to connect to the server")
return


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion tools/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/install_tests_dependencies.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down