Skip to content

Commit

Permalink
Fix: Diagnostic did not expose platform information
Browse files Browse the repository at this point in the history
Solution: Expose os-release, Python version and installed Python packages via the example_fastapi diagnostic VM.
  • Loading branch information
hoh committed Oct 3, 2023
1 parent d19a414 commit 14096a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@ jobs:
run: |
black --check ./vm_supervisor
black --check ./runtimes/aleph-debian-11-python/init1.py
black --check ./examples/example_fastapi/
- name: Test with isort
run: |
isort --check-only --profile=black ./vm_supervisor
isort --check-only --profile=black ./runtimes/aleph-debian-11-python/init1.py
isort --check-only --profile=black ./examples/example_fastapi/
- name: Test with MyPy
run: |
mypy --ignore-missing-imports ./vm_supervisor
mypy --ignore-missing-imports ./runtimes/aleph-debian-11-python/init1.py
mypy --ignore-missing-imports ./examples/example_fastapi/
- name: Test with flake8
run: |
flake8 --extend-ignore E501 ./vm_supervisor
flake8 --extend-ignore E501,E402 ./runtimes/aleph-debian-11-python/init1.py
flake8 --extend-ignore E501,E402 ./examples/example_fastapi/
code-quality-shell:
runs-on: ubuntu-22.04
Expand Down
35 changes: 24 additions & 11 deletions examples/example_fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@
import sys
from datetime import datetime
from os import listdir
from pathlib import Path
from typing import Dict

from pydantic import BaseModel

logger = logging.getLogger(__name__)

logger.debug("import aiohttp")
import aiohttp

logger.debug("import aleph_client")
from aleph.sdk.client import AlephClient, AuthenticatedAlephClient
from aleph.sdk.chains.remote import RemoteAccount
from aleph.sdk.client import AlephClient, AuthenticatedAlephClient
from aleph.sdk.types import StorageEnum
from aleph.sdk.vm.app import AlephApp
from aleph.sdk.vm.cache import VmCache

logger.debug("import fastapi")
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse
from pip._internal.operations.freeze import freeze
from pydantic import BaseModel

logger = logging.getLogger(__name__)
logger.debug("imports done")

http_app = FastAPI()
Expand Down Expand Up @@ -60,6 +55,9 @@ async def index():
"/post_a_message",
"/state/increment",
"/wait-for/{delay}",
"/platform/os",
"/platform/python",
"/platform/pip-freeze",
],
"files_in_volumes": {
"/opt/venv": opt_venv,
Expand All @@ -72,7 +70,7 @@ async def check_lifespan():
"""
Check that ASGI lifespan startup signal has been received
"""
return {"Lifetime": startup_lifespan_executed}
return {"Lifespan": startup_lifespan_executed}


@app.get("/environ")
Expand Down Expand Up @@ -252,6 +250,21 @@ def crash():
]


@app.get("/platform/os")
def platform_os():
return PlainTextResponse(content=Path("/etc/os-release").read_text())


@app.get("/platform/python")
def platform_python():
return PlainTextResponse(content=sys.version)


@app.get("/platform/pip-freeze")
def platform_pip_freeze():
return list(freeze())


@app.event(filters=filters)
async def aleph_event(event):
print("aleph_event", event)
Expand Down

0 comments on commit 14096a8

Please sign in to comment.