012 remove signoz

This commit is contained in:
Раис Юсупалиев
2026-03-08 22:59:11 +03:00
parent 81e484d7d1
commit f799f2ba03
29 changed files with 118 additions and 1323 deletions
@@ -13,9 +13,3 @@ repository:
adapter:
cdek_client_id: "yaml-id"
cdek_client_secret: "yaml-secret"
observability:
service_name: "from-config-yaml"
alerts:
telegram_enabled: false
@@ -10,13 +10,3 @@ business_logic:
repository:
redis_dsn: "redis://localhost:6379/0"
price_cache_ttl_seconds: 900
adapter:
cdek_base_url: "https://api.cdek.ru/v2"
cdek_client_id: "id"
cdek_client_secret: "secret"
observability:
service_name: "g2s-aggregator"
otlp_endpoint: ""
log_level: "INFO"
@@ -13,9 +13,3 @@ repository:
adapter:
cdek_client_id: "test-id"
cdek_client_secret: "test-secret"
observability:
service_name: "from-config-test-yaml"
alerts:
telegram_enabled: false
-93
View File
@@ -1,93 +0,0 @@
import pytest
from pydantic import ValidationError
from app.config import AlertsConfig, Settings
def _clear_alert_env(monkeypatch: pytest.MonkeyPatch) -> None:
for name in (
"G2S_ALERTS__TELEGRAM_ENABLED",
"G2S_ALERTS__TELEGRAM_BOT_TOKEN",
"G2S_ALERTS__TELEGRAM_CHAT_ID",
):
monkeypatch.delenv(name, raising=False)
def test_alerts_settings_are_loaded_from_yaml(tmp_path, monkeypatch) -> None:
_clear_alert_env(monkeypatch)
config_file = tmp_path / "config.yaml"
config_file.write_text(
"""
alerts:
telegram_enabled: true
telegram_bot_token: "bot-token"
telegram_chat_id: "-100777"
provider_5xx:
error_count: 7
window_minutes: 6
provider_p99_latency:
threshold_ms: 5200
window_minutes: 11
provider_unavailable:
duration_minutes: 8
""".strip(),
encoding="utf-8",
)
monkeypatch.setenv("G2S_CONFIG_FILE", str(config_file))
settings = Settings()
assert settings.alerts.telegram_enabled is True
assert settings.alerts.telegram_bot_token == "bot-token"
assert settings.alerts.telegram_chat_id == "-100777"
assert settings.alerts.provider_5xx.error_count == 7
assert settings.alerts.provider_5xx.window_minutes == 6
assert settings.alerts.provider_p99_latency.threshold_ms == 5200
assert settings.alerts.provider_p99_latency.window_minutes == 11
assert settings.alerts.provider_unavailable.duration_minutes == 8
@pytest.mark.parametrize(
("yaml_body", "error_message"),
[
(
"""
alerts:
telegram_enabled: true
telegram_chat_id: "-100777"
""".strip(),
"alerts.telegram_bot_token is required when alerts.telegram_enabled=true",
),
(
"""
alerts:
telegram_enabled: true
telegram_bot_token: "bot-token"
""".strip(),
"alerts.telegram_chat_id is required when alerts.telegram_enabled=true",
),
],
)
def test_enabled_telegram_requires_credentials(
tmp_path,
monkeypatch,
yaml_body: str,
error_message: str,
) -> None:
_clear_alert_env(monkeypatch)
config_file = tmp_path / "config.yaml"
config_file.write_text(yaml_body, encoding="utf-8")
monkeypatch.setenv("G2S_CONFIG_FILE", str(config_file))
with pytest.raises(ValidationError, match=error_message):
Settings()
def test_alert_condition_defaults_match_required_thresholds() -> None:
alerts = AlertsConfig()
assert alerts.provider_5xx.error_count == 5
assert alerts.provider_5xx.window_minutes == 5
assert alerts.provider_p99_latency.threshold_ms == 5000
assert alerts.provider_p99_latency.window_minutes == 10
assert alerts.provider_unavailable.duration_minutes == 5
+8 -11
View File
@@ -8,8 +8,8 @@ from app.config import Settings, get_settings
PROJECT_ROOT = Path(__file__).resolve().parents[2]
TEST_CONFIG_FILE = PROJECT_ROOT / "config.test.yaml"
MISSING_ALERTS_CONFIG_FILE = (
PROJECT_ROOT / "tests" / "config" / "fixtures" / "config.missing_alerts.yaml"
MISSING_REQUIRED_SECTION_CONFIG_FILE = (
PROJECT_ROOT / "tests" / "config" / "fixtures" / "config.missing_adapter.yaml"
)
DEFAULT_CONFIG_FILE_FIXTURE = (
PROJECT_ROOT / "tests" / "config" / "fixtures" / "config.default.yaml"
@@ -56,24 +56,21 @@ def test_configuration_sections_are_loaded_from_yaml_file(
assert settings.adapter.cdek_retry_backoff_seconds == 0.2
assert settings.adapter.cdek_timeout_seconds == 10.0
assert settings.adapter.cdek_cache_ttl_seconds == 900
assert settings.observability.service_name == "g2s-aggregator-tests"
assert settings.observability.otlp_endpoint == ""
assert settings.observability.log_level == "INFO"
assert settings.alerts.telegram_enabled is False
assert settings.alerts.telegram_bot_token is None
assert settings.alerts.telegram_chat_id is None
def test_get_settings_fails_when_required_yaml_section_is_missing(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_use_runtime_config_files(monkeypatch, test_config_file=MISSING_ALERTS_CONFIG_FILE)
_use_runtime_config_files(
monkeypatch,
test_config_file=MISSING_REQUIRED_SECTION_CONFIG_FILE,
)
with pytest.raises(ValidationError) as error:
get_settings()
locations = {tuple(item["loc"]) for item in error.value.errors()}
assert ("alerts",) in locations
assert ("adapter",) in locations
get_settings.cache_clear()
@@ -101,5 +98,5 @@ def test_get_settings_uses_config_test_yaml_in_pytest_environment(
assert settings.service.provider_timeout_seconds == 17.0
assert settings.controller.api_prefix == "/from-config-test-yaml"
assert settings.observability.service_name == "from-config-test-yaml"
assert settings.adapter.cdek_client_id == "test-id"
get_settings.cache_clear()