Skip to content

Commit 98af3b2

Browse files
committed
added test and a fix
1 parent 4aa836d commit 98af3b2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

services/autoscaling/src/simcore_service_autoscaling/modules/instrumentation/_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def on_shutdown() -> None: ...
3535

3636

3737
def get_instrumentation(app: FastAPI) -> AutoscalingInstrumentation:
38-
if not app.state.instrumentation:
38+
if not hasattr(app.state, "instrumentation"):
3939
raise ConfigurationError(
4040
msg="Instrumentation not setup. Please check the configuration."
4141
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
from fastapi import FastAPI
3+
from pytest_simcore.helpers.typing_env import EnvVarsDict
4+
from simcore_service_autoscaling.core.errors import ConfigurationError
5+
from simcore_service_autoscaling.modules.instrumentation._core import (
6+
get_instrumentation,
7+
has_instrumentation,
8+
)
9+
10+
11+
@pytest.fixture
12+
def disabled_instrumentation(
13+
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
14+
) -> None:
15+
monkeypatch.setenv("AUTOSCALING_PROMETHEUS_INSTRUMENTATION_ENABLED", "false")
16+
17+
18+
async def test_disabled_instrumentation(
19+
disabled_rabbitmq: None,
20+
disabled_ec2: None,
21+
disabled_ssm: None,
22+
disabled_instrumentation: None,
23+
mocked_redis_server: None,
24+
initialized_app: FastAPI,
25+
):
26+
# instrumentation disabled by default
27+
assert not has_instrumentation(initialized_app)
28+
29+
with pytest.raises(ConfigurationError):
30+
get_instrumentation(initialized_app)

0 commit comments

Comments
 (0)