Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add feedback anonymity metric to Grafana dashboard #1894

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions backend/capellacollab/feedback/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@

def count_feedback_by_rating(
db: orm.Session,
) -> dict[models.FeedbackRating, int]:
) -> dict[tuple[models.FeedbackRating, bool], int]:
anonymity_case = sa.case(
(models.DatabaseFeedback.user_id.is_(None), True),
else_=False,
)

return {
value[0]: value[1]
(value[0], value[1]): value[2]
for value in db.execute(
sa.select(
models.DatabaseFeedback.rating, sa.func.count()
).group_by(models.DatabaseFeedback.rating)
models.DatabaseFeedback.rating,
anonymity_case.label("anonymous"),
# pylint: disable=not-callable
sa.func.count(),
).group_by(
models.DatabaseFeedback.rating,
anonymity_case,
)
).all()
}

Expand Down
9 changes: 7 additions & 2 deletions backend/capellacollab/feedback/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ def collect(self) -> t.Iterable[prometheus_client.core.Metric]:
metric = prometheus_client.core.GaugeMetricFamily(
"feedback_count",
"Submitted feedback",
labels=["rating"],
labels=["rating", "anonymous"],
)

with database.SessionLocal() as db:
feedback = crud.count_feedback_by_rating(db)

for rating in models.FeedbackRating:
metric.add_metric([str(rating.value)], feedback.get(rating, 0))
metric.add_metric(
[str(rating.value), "true"], feedback.get((rating, True), 0)
)
metric.add_metric(
[str(rating.value), "false"], feedback.get((rating, False), 0)
)

yield metric

Expand Down
4 changes: 2 additions & 2 deletions backend/tests/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ def test_feedback_metric(db: orm.Session):
collector = feedback_metrics.FeedbackCollector()
data = list(collector.collect())

assert len(data[0].samples) == 3
assert len(data[0].samples) == 6

bad_sample = data[0].samples[0]
good_sample = data[0].samples[2]
good_sample = data[0].samples[4]

assert bad_sample.labels["rating"] == "bad"
assert bad_sample.name == "feedback_count"
Expand Down
101 changes: 91 additions & 10 deletions helm/config/grafana/dashboards/feedback.json
zusorio marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@
"id": 13,
"options": {
"legend": {
"calcs": ["lastNotNull"],
"calcs": [
"lastNotNull"
],
"displayMode": "list",
"placement": "bottom",
"showLegend": false
Expand All @@ -168,7 +170,7 @@
"uid": "prometheus_ccm"
},
"editorMode": "code",
"expr": "round(increase(feedback_count[$__range]))",
"expr": "round(sum by (rating) (increase(feedback_count[$__range])))",
"instant": false,
"legendFormat": "{{rating}}",
"range": true,
Expand Down Expand Up @@ -259,13 +261,15 @@
},
"gridPos": {
"h": 6,
"w": 5,
"w": 4,
"x": 0,
"y": 8
},
"id": 8,
"options": {
"displayLabels": ["percent"],
"displayLabels": [
"percent"
],
"legend": {
"displayMode": "list",
"placement": "bottom",
Expand All @@ -274,7 +278,9 @@
},
"pieType": "pie",
"reduceOptions": {
"calcs": ["lastNotNull"],
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
Expand All @@ -290,7 +296,7 @@
"uid": "prometheus_ccm"
},
"editorMode": "code",
"expr": "round(increase(feedback_count[$__range]))",
"expr": "round(sum by (rating) (increase(feedback_count[$__range])))",
"instant": false,
"legendFormat": "{{rating}}",
"range": true,
Expand Down Expand Up @@ -333,8 +339,8 @@
},
"gridPos": {
"h": 6,
"w": 5,
"x": 5,
"w": 3,
"x": 4,
"y": 8
},
"id": 12,
Expand All @@ -343,7 +349,9 @@
"minVizWidth": 75,
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
Expand Down Expand Up @@ -378,6 +386,79 @@
],
"type": "gauge"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus_ccm"
},
"fieldConfig": {
"defaults": {
"color": {
"fixedColor": "blue",
"mode": "fixed"
},
"fieldMinMax": false,
"mappings": [],
"max": 100,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 6,
"w": 3,
"x": 7,
"y": 8
},
"id": 15,
"options": {
"minVizHeight": 75,
"minVizWidth": 75,
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": false,
"sizing": "auto",
"text": {}
},
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus_ccm"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "round((sum(increase(feedback_count{anonymous=\"true\"}[$__range])) / sum(increase(feedback_count[$__range]))) * 100)",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Share of anonymous feedback",
"type": "gauge"
},
{
"datasource": {
"type": "prometheus",
Expand Down Expand Up @@ -490,6 +571,6 @@
"timezone": "",
"title": "Feedback",
"uid": "edzhg6sv97lz4c",
"version": 2,
"version": 3,
"weekStart": ""
}
Loading