Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Enhances release monitor script #5242

Merged
merged 12 commits into from
Jan 24, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ Untitled*
services/**/settings-schema.json

tests/public-api/osparc_python_wheels/*

# osparc-config repo files
repo.config
15 changes: 15 additions & 0 deletions scripts/release/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.DEFAULT_GOAL := help

SHELL := /bin/bash


help: ## help on rule's targets
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)


.PHONY: install install-dev
install install-dev: ## installation and check
# installation
@pip install $(if $(findstring -dev, $@),-e,) .
# check executable runs
monitor-release --help
20 changes: 11 additions & 9 deletions scripts/release/monitor/README.md → scripts/release/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Helper for monitoring of release
`pip install .`
`monitor-release --help`
# release-monitor

Check current status of containers
`monitor-release master containers`
Check running sidecars:
`monitor-release master sidecars`

# Create .env file
```
Helper for monitoring of release. Here some one-liner examples:

- Installation: `pip install .; monitor-release --help` or simply `make install-ci` or `make install-dev`
- Check current status of containers in `master` deployment: `monitor-release containers master` containers.
- Check running sidecars in `master` deployment: `monitor-release sidecar master`


## Create .env file
pcrespov marked this conversation as resolved.
Show resolved Hide resolved

```.env
MASTER_PORTAINER_URL=
MASTER_PORTAINER_USERNAME=
MASTER_PORTAINER_PASSWORD=
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/monitor/Makefile

This file was deleted.

31 changes: 0 additions & 31 deletions scripts/release/monitor/monitor_release/cli.py

This file was deleted.

112 changes: 0 additions & 112 deletions scripts/release/monitor/monitor_release/settings.py

This file was deleted.

54 changes: 54 additions & 0 deletions scripts/release/monitor_release/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from pathlib import Path
from typing import Annotated

import typer
from monitor_release.models import Deployment
from monitor_release.portainer import check_containers_deploys, check_running_sidecars
from monitor_release.settings import get_legacy_settings, get_release_settings
from rich.console import Console

app = typer.Typer()
console = Console()


EnvFileOption = typer.Option(
exists=True,
file_okay=True,
dir_okay=False,
writable=False,
readable=True,
resolve_path=True,
help="Path to .env file",
)


@app.command()
def settings(
env_file: Annotated[Path, EnvFileOption] = Path("repo.config"),
):
settings_ = get_release_settings(env_file)
console.print(settings_.model_dump_json(indent=1))


@app.command()
def containers(
deployment: Deployment,
env_file: Annotated[Path, EnvFileOption] = Path(".env"),
):
settings_ = get_legacy_settings(f"{env_file}", deployment)
console.print(f"Deployment: {deployment}")
console.print("Action: containers")

check_containers_deploys(settings_, deployment)


@app.command()
def sidecars(
deployment: Deployment,
env_file: Annotated[Path, EnvFileOption] = Path(".env"),
):
settings_ = get_legacy_settings(f"{env_file}", deployment)
console.print(f"Deployment: {deployment}")
console.print("Action: sidecars")

check_running_sidecars(settings_, deployment)
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ def check_containers_deploys(settings, deployment):
container_git_sha = None
for task in item["tasks"]:
oldest_running_task_timestamp = None
if task["status"] == "running":
if (
oldest_running_task_timestamp is None
or oldest_running_task_timestamp > task["timestamp"]
):
container_status = f"[green]{task['status']}[/green]"
container_timestamp = f"{task['timestamp']}"
container_git_sha = task["git_sha"]
if task["status"] == "running" and (
oldest_running_task_timestamp is None
or oldest_running_task_timestamp > task["timestamp"]
):
container_status = f"[green]{task['status']}[/green]"
container_timestamp = f"{task['timestamp']}"
container_git_sha = task["git_sha"]

oldest_running_task_timestamp = task["timestamp"]
oldest_running_task_timestamp = task["timestamp"]
if task["status"] == "starting":
container_status = f"[blue]{task['status']}[/blue]"
container_timestamp = f"{task['timestamp']}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import arrow
import requests
from monitor_release.models import RunningSidecar
from monitor_release.settings import Settings
from monitor_release.settings import LegacySettings


def get_bearer_token(settings: Settings):
def get_bearer_token(settings: LegacySettings):
headers = {"accept": "application/json", "Content-Type": "application/json"}
payload = json.dumps(
{
Expand All @@ -19,11 +19,10 @@ def get_bearer_token(settings: Settings):
headers=headers,
data=payload,
)
bearer_token = response.json()["jwt"]
return bearer_token
return response.json()["jwt"]


def get_services(settings: Settings, bearer_token):
def get_services(settings: LegacySettings, bearer_token):
services_url = f"{settings.portainer_url}/portainer/api/endpoints/{settings.portainer_endpoint_version}/docker/services"
response = requests.get(
services_url,
Expand All @@ -32,11 +31,10 @@ def get_services(settings: Settings, bearer_token):
"Content-Type": "application/json",
},
)
services = response.json()
return services
return response.json()


def get_tasks(settings: Settings, bearer_token):
def get_tasks(settings: LegacySettings, bearer_token):
tasks_url = f"{settings.portainer_url}/portainer/api/endpoints/{settings.portainer_endpoint_version}/docker/tasks"
response = requests.get(
tasks_url,
Expand All @@ -45,11 +43,10 @@ def get_tasks(settings: Settings, bearer_token):
"Content-Type": "application/json",
},
)
tasks = response.json()
return tasks
return response.json()


def get_containers(settings: Settings, bearer_token):
def get_containers(settings: LegacySettings, bearer_token):
bearer_token = get_bearer_token(settings)

containers_url = f"{settings.portainer_url}/portainer/api/endpoints/{settings.portainer_endpoint_version}/docker/containers/json?all=true"
Expand All @@ -60,11 +57,10 @@ def get_containers(settings: Settings, bearer_token):
"Content-Type": "application/json",
},
)
containers = response.json()
return containers
return response.json()


def check_simcore_running_sidecars(settings: Settings, services):
def check_simcore_running_sidecars(settings: LegacySettings, services):
running_sidecars: list[RunningSidecar] = []
for service in services:
if (
Expand Down Expand Up @@ -106,7 +102,9 @@ def _generate_containers_map(containers):
return container_map


def check_simcore_deployed_services(settings: Settings, services, tasks, containers):
def check_simcore_deployed_services(
settings: LegacySettings, services, tasks, containers
):
container_map = _generate_containers_map(containers)
service_task_map = {}
for service in services:
Expand Down
Loading