Skip to content

Commit

Permalink
Merge pull request #1588 from DSD-DBS/use-session-id-for-idletime
Browse files Browse the repository at this point in the history
fix: Termination of sessions
  • Loading branch information
MoritzWeber0 authored May 28, 2024
2 parents f730af4 + ff4e2fa commit c8cc4a5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/capellacollab/sessions/idletimeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def terminate_idle_session():
log.error("Could not collect idle sessions from Prometheus")
return
for metric in response.json()["data"]["result"]:
if session_id := metric.get("metric", {}).get("app"):
if session_id := metric.get("metric", {}).get("session_id"):
log.info("Terminating idle session %s", session_id)
with database.SessionLocal() as db:
if session := crud.get_session_by_id(db, session_id):
Expand Down
2 changes: 1 addition & 1 deletion backend/capellacollab/sessions/injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_last_seen(sid: str) -> str:
response.raise_for_status()

for session in response.json()["data"]["result"]:
if sid == session["metric"]["app"]:
if sid == session["metric"]["session_id"]:
return _get_last_seen(float(session["value"][1]))

log.error("No session was found.")
Expand Down
4 changes: 3 additions & 1 deletion backend/tests/sessions/test_session_idletimeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_idle_sessions(monkeypatch):
monkeypatch.setattr(
requests,
"get",
lambda *args, **kwargs: MockResponse({"metric": {"app": session_id}}),
lambda *args, **kwargs: MockResponse(
{"metric": {"session_id": session_id}}
),
)
monkeypatch.setattr(
capellacollab.sessions.operators,
Expand Down

0 comments on commit c8cc4a5

Please sign in to comment.