Skip to content

Commit

Permalink
feat(alpha): prepare new version
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxin688 committed Jul 5, 2024
1 parent b17aa5a commit 44251c4
Show file tree
Hide file tree
Showing 33 changed files with 1,064 additions and 1,199 deletions.
1,121 changes: 0 additions & 1,121 deletions backend/alembic/versions/2024_07_04_2338-c09c3268e2b9_init_db.py

This file was deleted.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"bcrypt>=4.0.1",
"passlib>=1.7.4",
"cryptography>=42.0.8",
"celery>=5.4.0",
]
readme = "README.md"
requires-python = ">= 3.11"
Expand Down
28 changes: 28 additions & 0 deletions backend/requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
-e file:.
alembic==1.13.2
# via netsight
amqp==5.2.0
# via kombu
annotated-types==0.6.0
# via pydantic
anyio==4.2.0
Expand All @@ -20,7 +22,11 @@ asyncpg==0.29.0
# via netsight
bcrypt==4.0.1
# via netsight
billiard==4.2.0
# via celery
black==23.12.1
celery==5.4.0
# via netsight
certifi==2023.11.17
# via httpcore
# via httpx
Expand All @@ -31,8 +37,18 @@ cfgv==3.4.0
# via pre-commit
click==8.1.7
# via black
# via celery
# via click-didyoumean
# via click-plugins
# via click-repl
# via typer
# via uvicorn
click-didyoumean==0.3.1
# via celery
click-plugins==1.1.1
# via celery
click-repl==0.3.0
# via celery
coverage==7.4.0
# via pytest-cov
cryptography==42.0.8
Expand Down Expand Up @@ -74,6 +90,8 @@ iniconfig==2.0.0
# via pytest
jinja2==3.1.4
# via fastapi
kombu==5.3.7
# via celery
mako==1.3.0
# via alembic
markdown-it-py==3.0.0
Expand Down Expand Up @@ -112,6 +130,8 @@ platformdirs==4.1.0
pluggy==1.3.0
# via pytest
pre-commit==3.6.0
prompt-toolkit==3.0.47
# via click-repl
pycparser==2.22
# via cffi
pydantic==2.5.3
Expand All @@ -134,6 +154,7 @@ pytest==7.4.4
pytest-asyncio==0.23.3
pytest-cov==4.1.0
python-dateutil==2.8.2
# via celery
# via pandas
python-dotenv==1.0.0
# via pydantic-settings
Expand Down Expand Up @@ -181,6 +202,7 @@ typing-extensions==4.9.0
# via sqlalchemy
# via typer
tzdata==2024.1
# via celery
# via pandas
ujson==5.10.0
# via fastapi
Expand All @@ -191,9 +213,15 @@ uvicorn==0.25.0
# via netsight
uvloop==0.19.0
# via uvicorn
vine==5.1.0
# via amqp
# via celery
# via kombu
virtualenv==20.25.0
# via pre-commit
watchfiles==0.21.0
# via uvicorn
wcwidth==0.2.13
# via prompt-toolkit
websockets==12.0
# via uvicorn
28 changes: 28 additions & 0 deletions backend/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
-e file:.
alembic==1.13.2
# via netsight
amqp==5.2.0
# via kombu
annotated-types==0.6.0
# via pydantic
anyio==4.2.0
Expand All @@ -20,15 +22,29 @@ asyncpg==0.29.0
# via netsight
bcrypt==4.0.1
# via netsight
billiard==4.2.0
# via celery
celery==5.4.0
# via netsight
certifi==2023.11.17
# via httpcore
# via httpx
# via sentry-sdk
cffi==1.16.0
# via cryptography
click==8.1.7
# via celery
# via click-didyoumean
# via click-plugins
# via click-repl
# via typer
# via uvicorn
click-didyoumean==0.3.1
# via celery
click-plugins==1.1.1
# via celery
click-repl==0.3.0
# via celery
cryptography==42.0.8
# via netsight
dnspython==2.5.0
Expand Down Expand Up @@ -60,6 +76,8 @@ idna==3.6
# via httpx
jinja2==3.1.4
# via fastapi
kombu==5.3.7
# via celery
mako==1.3.0
# via alembic
markdown-it-py==3.0.0
Expand All @@ -82,6 +100,8 @@ passlib==1.7.4
# via netsight
phonenumbers==8.13.27
# via netsight
prompt-toolkit==3.0.47
# via click-repl
pycparser==2.22
# via cffi
pydantic==2.5.3
Expand All @@ -99,6 +119,7 @@ pygments==2.18.0
pyjwt==2.8.0
# via netsight
python-dateutil==2.8.2
# via celery
# via pandas
python-dotenv==1.0.0
# via pydantic-settings
Expand Down Expand Up @@ -141,6 +162,7 @@ typing-extensions==4.9.0
# via sqlalchemy
# via typer
tzdata==2024.1
# via celery
# via pandas
ujson==5.10.0
# via fastapi
Expand All @@ -151,7 +173,13 @@ uvicorn==0.25.0
# via netsight
uvloop==0.19.0
# via uvicorn
vine==5.1.0
# via amqp
# via celery
# via kombu
watchfiles==0.21.0
# via uvicorn
wcwidth==0.2.13
# via prompt-toolkit
websockets==12.0
# via uvicorn
43 changes: 43 additions & 0 deletions backend/src/core/celery_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging
from collections.abc import Callable, Coroutine
from logging.config import dictConfig
from typing import Any, TypeVar

from anyio.from_thread import start_blocking_portal
from celery import Celery
from celery.signals import setup_logging

from src.core.config import settings
from src.core.utils.loggers import LOGGING

_R = TypeVar("_R")

celery_app = Celery(
__name__,
backend=settings.CELERY_BACKEND_URL,
broker=settings.CELERY_BROKER_URL,
broker_connection_retry_on_startup=True,
task_acks_late=True,
task_reject_on_worker_lost=True,
worker_prefetch_multiplier=1,
worker_max_tasks_per_child=1,
task_track_started=True,
task_serializer="json",
result_serializer="json",
result_persistence=True,
imports=(),
)


def async_task(func: Callable[..., Coroutine[Any, Any, _R]]) -> _R:
def wrapper(*args: Any) -> _R:
with start_blocking_portal() as portal:
return portal.call(func, *args)

return wrapper # type: ignore # noqa: PGH003


@setup_logging.connect
def _setup_logging(**kwargs: Any) -> None: # noqa: ARG001
dictConfig(LOGGING)
logging.getLogger("child").propagate = False
5 changes: 4 additions & 1 deletion backend/src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ class Settings(BaseSettings):
LIMITED_RATE: tuple[int, int] = Field(default=(20, 10))

WEB_SENTRY_DSN: str | None = Field(default=None)
CELERY_SENTRY_DSN: str | None = Field(default=None)
SENTRY_SAMPLE_RATE: float = Field(default=1.0, gt=0.0, le=1.0)
SENTRY_TRACES_SAMPLE_RATE: float | None = Field(default=None, gt=0.0, le=1.0)

CELERY_SENTRY_DSN: str | None = Field(default=None)
CELERY_BROKER_URL: str | None = Field(default="amqp://demo:demo@localhost:5672")
CELERY_BACKEND_URL: str | None = Field(default="redis://localhost:6379/1")

SQLALCHEMY_DATABASE_URI: str = Field(
default="postgresql+asyncpg://netsight:netsight@localhost:5432/netsight"
) # cover with env with your production database
Expand Down
2 changes: 1 addition & 1 deletion backend/src/features/admin/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Permission(BaseModel):
class PermissionCreate(BaseModel): ...


class PermissionUpdate(QueryParams): ...
class PermissionUpdate(BaseModel): ...


class PermissionQuery(QueryParams): ...
Expand Down
42 changes: 42 additions & 0 deletions backend/src/features/alert/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from enum import StrEnum


class AlertStatusType(StrEnum):
FIRERING = "FIRERING"
RESOLVED = "RESOLVED"


class AlertSeverityType(StrEnum):
P4 = "P4"
P3 = "P3"
P2 = "P2"
P1 = "P1"
P0 = "P0"


class NotificationChannelType(StrEnum):
WEBHOOK = "WEBHOOK"
FEISHU_PRIVATE = "FEISHU_PRIVATE"
FEISHU_GROUP = "FEISHU_GROUP"
DINGTALK_PRIVATE = "DINGTALK_PRIVATE"
DINGTALK_GROUP = "DINGTALK_GROUP"
WECHAT_PRIVATE = "WECHAT_PRIVATE"
WECHAT_GROUP = "WECHAT_GROUP"
SLACK_PRIVATE = "SLACK_PRIVATE"
SLACK_GROUP = "SLACK_GROUP"
EMAIL = "EMAIL"


class NotificationResultType(StrEnum):
SUCCESS = "SUCCESS"
FAIL = "FAIL"
UNKNOWN = "UNKNOWN"


class EventOperationType(StrEnum):
ACKNOWLEDGE = "ACKNOWLEDGE"
UNACKNOWLEDGE = "UNACKNOWLEDGE"
CLOSE = "CLOSE"
COMMENT = "COMMENT"
ASSIGN = "ASSIGN"
INHIBIT = "INHIBIT"
Loading

0 comments on commit 44251c4

Please sign in to comment.