add prometheus instrumentation (but dont' expose yet)
also fixes prod running
This commit is contained in:
parent
6c49265e8a
commit
9e092edfe6
1 changed files with 6 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ from typing import Any, AsyncIterator, Dict, List, Optional, Protocol, Tuple, ca
|
|||
|
||||
import json_logging
|
||||
import uvicorn
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request, status
|
||||
from fastapi.security import (
|
||||
HTTPAuthorizationCredentials,
|
||||
|
|
@ -34,7 +35,7 @@ async def matrix_main(matrix_client: MatrixClient) -> None:
|
|||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
|
||||
instrumentator.expose(app)
|
||||
config_fname = os.environ.get("BOT_CONFIG_FILE", "config.yaml")
|
||||
bot_settings = load_config(config_fname)
|
||||
c = MatrixClient(settings=bot_settings.matrix, join_rooms=bot_settings.get_rooms())
|
||||
|
|
@ -46,6 +47,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
instrumentator = Instrumentator().instrument(app)
|
||||
bearer_security = HTTPBearer(auto_error=False)
|
||||
basic_security = HTTPBasic(auto_error=False)
|
||||
|
||||
|
|
@ -173,9 +175,9 @@ def start_dev() -> None:
|
|||
uvicorn.run("ops_bot.main:app", port=1111, host="127.0.0.1", reload=True)
|
||||
|
||||
|
||||
def start() -> None:
|
||||
uvicorn.run("ops_bot.main:app", port=1111, host="0.0.0.0") # nosec B104
|
||||
def main() -> None:
|
||||
uvicorn.run(app, port=1111, host="0.0.0.0") # nosec B104
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start()
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue