Skip to content

Commit

Permalink
Adding sentry to the code (#87)
Browse files Browse the repository at this point in the history
* Adding poetry to the code

* Client SQL removed

* Few changes to the codebase

* version change

* poetry update

* poetry update

* updates to app.py

* Error change

* minor update

* isort update

* pyproject update

* poetry update

* client sql change

* version change

* remvoving clientsql

* minor change

* minor change?

* cleanup

* minor change

* update to test app

* updated format
  • Loading branch information
ADIMANV authored Sep 27, 2024
1 parent 18e8193 commit 0524981
Show file tree
Hide file tree
Showing 8 changed files with 2,486 additions and 2,241 deletions.
11 changes: 11 additions & 0 deletions database-cleanup/database_cleanup/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@
import uuid

import click
import importlib.metadata
import sentry_sdk
import sqlalchemy as sa
from pvsite_datamodel.sqlmodels import ForecastSQL, ForecastValueSQL
from sqlalchemy.orm import Session, sessionmaker

_log = logging.getLogger(__name__)

version = importlib.metadata.version("database-cleanup")

sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN"), environment=os.getenv("ENVIRONMENT", "local"), traces_sample_rate=1
)

sentry_sdk.set_tag("app_name", "pv-site-production_database_cleanup")
sentry_sdk.set_tag("version", version)


@contextlib.contextmanager
def _profile(msg: str):
Expand Down
1,386 changes: 710 additions & 676 deletions database-cleanup/poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion database-cleanup/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ packages = [{include = "database_cleanup"}]
python = "^3.10"
pvsite-datamodel = "^0.1.32"
click = "^8.1.3"

sentry-sdk = "^2.1.1"
setuptools = "^75.1.0"

[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
Expand Down
6 changes: 2 additions & 4 deletions database-cleanup/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import sqlalchemy as sa
from pvsite_datamodel.sqlmodels import Base, ClientSQL, SiteSQL
from pvsite_datamodel.sqlmodels import Base, SiteSQL
from sqlalchemy.orm import Session
from testcontainers.postgres import PostgresContainer

Expand All @@ -29,11 +29,9 @@ def fill_db(engine):
num_sites = 3
with Session(engine) as session:
for i in range(num_clients):
client = ClientSQL(client_name=f"client-{i}")
session.add(client)
session.commit()
for j in range(num_sites):
session.add(SiteSQL(client_uuid=client.client_uuid, ml_id=j + num_sites * i))
session.add(SiteSQL(ml_id=j + num_sites * i))
session.commit()


Expand Down
8 changes: 2 additions & 6 deletions database-cleanup/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from click.testing import CliRunner
from database_cleanup.app import main
from freezegun import freeze_time
from pvsite_datamodel.sqlmodels import ClientSQL, ForecastSQL, ForecastValueSQL, SiteSQL
from pvsite_datamodel.sqlmodels import ForecastSQL, ForecastValueSQL, SiteSQL
from sqlalchemy.orm import Session


Expand Down Expand Up @@ -54,11 +54,7 @@ def _run_cli(func, args: list[str]):
@pytest.fixture
def site(session):
# Create a new site (this way we know it won't have any forecasts yet).
client = ClientSQL(client_name=str(uuid.uuid4()))
session.add(client)
session.commit()

site = SiteSQL(client_uuid=client.client_uuid, ml_id=hash(uuid.uuid4()) % 2147483647)
site = SiteSQL(ml_id=hash(uuid.uuid4()) % 2147483647)
session.add(site)
session.commit()
return site
Expand Down
11 changes: 11 additions & 0 deletions forecast-inference/forecast_inference/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import datetime as dt
import importlib.metadata
import logging
import os
import pathlib
Expand All @@ -11,6 +12,7 @@
import click
import dotenv
import numpy as np
import sentry_sdk
from psp.models.base import PvSiteModel
from psp.typings import PvId, Timestamp, X
from pvsite_datamodel.connection import DatabaseConnection
Expand All @@ -23,6 +25,15 @@

_log = logging.getLogger(__name__)

version = importlib.metadata.version("forecast_inference")

sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN"), environment=os.getenv("ENVIRONMENT", "local"), traces_sample_rate=1
)

sentry_sdk.set_tag("app_name", "pv-site-production_forecast_inferance")
sentry_sdk.set_tag("version", version)


def _run_model_and_save_for_one_pv(
database_connection: DatabaseConnection,
Expand Down
3,298 changes: 1,745 additions & 1,553 deletions forecast-inference/poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion forecast-inference/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ python-dotenv = "^0.21.1"
sqlalchemy = ">=2.0"
pv-site-prediction = ">=0.1.19"
pvsite-datamodel = "^1.0.28"

sentry-sdk = "^2.1.1"
setuptools = "^75.1.0"

[tool.poetry.group.dev.dependencies]
pytest-cov = "^4.0.0"
Expand All @@ -29,6 +30,7 @@ mypy = "^1.2.0"
freezegun = "^1.2.2"
jupyter = "^1.0.0"
altair = "^4.2.2"
setuptools = "^75.1.0"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 0524981

Please sign in to comment.