Skip to content

Commit

Permalink
Merge pull request #2199 from DSD-DBS/more-xpra-metrics
Browse files Browse the repository at this point in the history
feat: Add new dashboard to see metrics for a specific session
  • Loading branch information
MoritzWeber0 authored Feb 13, 2025
2 parents 9bc9e64 + 0ecd47c commit 49e597a
Show file tree
Hide file tree
Showing 8 changed files with 1,529 additions and 53 deletions.
2 changes: 1 addition & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ app:
source $(VENV)/Scripts/activate;
fi
export OAUTHLIB_INSECURE_TRANSPORT=1;
uvicorn --host $(HOST) --reload --reload-dir $$(pwd) --reload-include "*.py" --reload-include "*.yaml" --reload-include "*.yml" capellacollab.__main__:app
uvicorn --host $(HOST) --reload --reload-dir $$(pwd) --reload-include "*.py" --reload-include "*.yaml" --reload-include "*.yml" --reload-include "*.jinja" capellacollab.__main__:app

coverage:
pytest \
Expand Down
2 changes: 1 addition & 1 deletion backend/capellacollab/core/email/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def send_email(
msg["From"] = config.smtp.sender
msg["To"] = recipient
msg["Subject"] = email.subject
msg.attach(text.MIMEText(email.message, "plain"))
msg.attach(text.MIMEText(email.message, "html"))

logger.info(
"Sending email to '%s' with subject '%s'",
Expand Down
63 changes: 63 additions & 0 deletions backend/capellacollab/feedback/email.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!--
~ SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
~ SPDX-License-Identifier: Apache-2.0
-->

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue',
sans-serif;
}
p {
margin: 10px 0;
}
</style>
</head>

<body>
<div>
<p><strong>Rating:</strong> {{ feedback.rating.value|capitalize }}</p>
<p><strong>Text:</strong> {{ feedback.feedback_text or 'No feedback text provided' }}</p>
<p><strong>User:</strong> {% if user %}{{ user.name }}{% if user.email %} ({{ user.email }}){% endif %}{% else
%}Anonymous{% endif %}</p>
<p><strong>User Agent:</strong> {{ user_agent or 'Unknown' }}</p>

{% if user %}
<p><strong>Beta Tester:</strong> {{ user.beta_tester }}</p>
{% endif %}

{% if feedback.trigger %}
<p><strong>Trigger:</strong> {{ feedback.trigger }}</p>
{% endif %}
</div>

{% if feedback.sessions %}
<div>
<p><strong>Sessions:</strong></p>
{% for session in feedback.sessions %}
<pre>{{ session.model_dump_json(indent=2) }}</pre>
{% set grafana_url
= ccm_url ~ '/grafana/d/individual-session/individual-session?orgId=1&var-session_id=' ~ session.id %}
<p>Get more insights in our Grafana dashboard: <a href="{{ grafana_url }}">{{ grafana_url }}</a></p>
{% endfor %}
</div>
{% endif %}

<div>
<hr>
<p>You received this email because you're registered as feedback recipient in the
Capella Collaboration Manager (<a href="{{ ccm_url }}">{{ ccm_url }}</a>).</p>
<p>If you want to unsubscribe, contact your System Administrator.</p>
<p><em>Please note that only the user is validated. All other fields are provided via the API and should not be
trusted.</em></p>
</div>
</body>

</html>
61 changes: 16 additions & 45 deletions backend/capellacollab/feedback/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# SPDX-License-Identifier: Apache-2.0

import logging
import pathlib

import jinja2
from sqlalchemy import orm

from capellacollab.configuration import core as config_core
Expand Down Expand Up @@ -52,57 +54,26 @@ def format_email(
user: users_models.User | None,
user_agent: str | None,
) -> email_models.EMailContent:
rating = feedback.rating.value
user_msg = user.name if user else "Anonymous"
if user and user.email:
user_msg += f" ({user.email})"

message_list = [
f"Rating: {rating.capitalize()}",
f"Text: {feedback.feedback_text or 'No feedback text provided'}",
f"User: {user_msg}",
f"User Agent: {user_agent or 'Unknown'}",
]
if user:
message_list.append(
f"Beta Tester: {user.beta_tester}",
)

if feedback.trigger:
message_list.append(f"Trigger: {feedback.trigger}")

if feedback.sessions:
message_list.append("Sessions:")
message_list += [
session.model_dump_json(indent=2) for session in feedback.sessions
]

message_list.append("---")
message_list.append(
f"You received this email because you're registered as feedback recipient in the "
f"Capella Collaboration Manager ({config.general.scheme}://{config.general.host}:{config.general.port})."
)
message_list.append(
"If you want to unsubscribe, contact your System Administrator."
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(pathlib.Path(__file__).parent),
autoescape=True,
)
message_list.append(
"Please note that only the user is validated. All other fields are provided via the API and should not be trusted."
template = env.get_template("email.jinja")
ccm_url = f"{config.general.scheme}://{config.general.host}:{config.general.port}"

html_content = template.render(
feedback=feedback, user=user, user_agent=user_agent, ccm_url=ccm_url
)
message = "\n".join(message_list)

if len(feedback.sessions) > 0:
if feedback.sessions:
sessions = ", ".join(
[format_session(session) for session in feedback.sessions]
)
return email_models.EMailContent(
subject=f"New Feedback with rating {rating} for sessions: {sessions}",
message=message,
format_session(session) for session in feedback.sessions
)
subject = f"New Feedback with rating {feedback.rating.value} for sessions: {sessions}"
else:
return email_models.EMailContent(
subject=f"New General Feedback with rating {rating}",
message=message,
)
subject = f"New General Feedback with rating {feedback.rating.value}"

return email_models.EMailContent(subject=subject, message=html_content)


def send_feedback_email(
Expand Down
2 changes: 2 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies = [
"cryptography",
"croniter",
"pyinstrument",
"Jinja2",
]

[project.urls]
Expand Down Expand Up @@ -125,6 +126,7 @@ module = [
"websocket.*",
"testcontainers.*",
"valkey.*",
"jinja2.*"
]
ignore_missing_imports = true

Expand Down
Loading

0 comments on commit 49e597a

Please sign in to comment.