-
Notifications
You must be signed in to change notification settings - Fork 0
fix(metrics): correct PromQL for Active Sessions and recording rules … #10
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1769,24 +1769,6 @@ | |||||
| "type": "prometheus", | ||||||
| "uid": "victoriametrics" | ||||||
| }, | ||||||
| "fieldConfig": { | ||||||
| "defaults": { | ||||||
| "color": { | ||||||
| "mode": "thresholds" | ||||||
| }, | ||||||
| "mappings": [], | ||||||
| "thresholds": { | ||||||
| "mode": "absolute", | ||||||
| "steps": [ | ||||||
| { | ||||||
| "color": "green", | ||||||
| "value": null | ||||||
| } | ||||||
| ] | ||||||
| }, | ||||||
| "unit": "short" | ||||||
| } | ||||||
| }, | ||||||
| "fieldConfig": { | ||||||
| "defaults": { | ||||||
| "color": { | ||||||
|
|
@@ -1852,24 +1834,6 @@ | |||||
| "type": "prometheus", | ||||||
| "uid": "victoriametrics" | ||||||
| }, | ||||||
| "fieldConfig": { | ||||||
| "defaults": { | ||||||
| "color": { | ||||||
| "mode": "thresholds" | ||||||
| }, | ||||||
| "mappings": [], | ||||||
| "thresholds": { | ||||||
| "mode": "absolute", | ||||||
| "steps": [ | ||||||
| { | ||||||
| "color": "green", | ||||||
| "value": null | ||||||
| } | ||||||
| ] | ||||||
| }, | ||||||
| "unit": "short" | ||||||
| } | ||||||
| }, | ||||||
| "fieldConfig": { | ||||||
| "defaults": { | ||||||
| "color": { | ||||||
|
|
@@ -2232,7 +2196,7 @@ | |||||
| "pluginVersion": "11.0.0", | ||||||
| "targets": [ | ||||||
| { | ||||||
| "expr": "count(count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[24h]) by (session_hash))", | ||||||
| "expr": "count((sum by (session_hash) (count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[24h]))) > 0)", | ||||||
| "refId": "A" | ||||||
| } | ||||||
| ], | ||||||
|
|
@@ -2420,7 +2384,7 @@ | |||||
| ], | ||||||
| "title": "Funnel: Upload → View → Enrich → Export → Edit → Delete (7d)", | ||||||
| "type": "bargauge" | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| "datasource": { | ||||||
| "type": "prometheus", | ||||||
|
|
@@ -2736,7 +2700,7 @@ | |||||
| "pluginVersion": "11.0.0", | ||||||
| "targets": [ | ||||||
| { | ||||||
| "expr": "count(count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[7d]) by (session_hash))", | ||||||
| "expr": "count((sum by (session_hash) (count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[7d]))) > 0)", | ||||||
|
||||||
| "expr": "count((sum by (session_hash) (count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[7d]))) > 0)", | |
| "expr": "count(sum by (session_hash) (count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[7d])))", |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filtering condition > 0 is redundant in this context. The count() function already excludes time series with no samples. Since sum by (session_hash) (count_over_time(...)) will only produce results for session_hashes that have at least one sample, the > 0 filter doesn't change the result. Consider simplifying to count(sum by (session_hash) (count_over_time(trackly_session_heartbeat{job="trackly_backend"}[30d]))) for clarity and consistency with the recording rules that use sum by (session_hash) (count_over_time(...)) without the > 0 filter.
| "expr": "count((sum by (session_hash) (count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[30d]))) > 0)", | |
| "expr": "count(sum by (session_hash) (count_over_time(trackly_session_heartbeat{job=\"trackly_backend\"}[30d])))", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,19 +14,19 @@ groups: | |
| ) | ||
| - record: sessions_active_1d | ||
| expr: | | ||
| count(count_over_time(trackly_session_heartbeat[1d]) by (session_hash)) | ||
| count((sum by (session_hash) (count_over_time(trackly_session_heartbeat[1d]))) > 0) | ||
|
||
| - record: sessions_active_7d | ||
| expr: | | ||
| count(count_over_time(trackly_session_heartbeat[7d]) by (session_hash)) | ||
| count((sum by (session_hash) (count_over_time(trackly_session_heartbeat[7d]))) > 0) | ||
|
||
| - record: sessions_active_30d | ||
| expr: | | ||
| count(count_over_time(trackly_session_heartbeat[30d]) by (session_hash)) | ||
| count((sum by (session_hash) (count_over_time(trackly_session_heartbeat[30d]))) > 0) | ||
|
||
| - record: sessions_churn_risk | ||
| expr: | | ||
| count( | ||
| count_over_time(trackly_session_heartbeat[30d]) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[30d])) | ||
| unless | ||
| count_over_time(trackly_session_heartbeat[14d]) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[14d])) | ||
| ) | ||
| - record: sessions_churn_rate | ||
| expr: | | ||
|
|
@@ -55,30 +55,30 @@ groups: | |
| - record: retention_d1 | ||
| expr: | | ||
| count( | ||
| count_over_time(trackly_session_heartbeat[1d] offset 1d) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[1d] offset 1d)) | ||
| and | ||
| count_over_time(trackly_session_heartbeat[1d]) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[1d])) | ||
| ) | ||
| / | ||
| count(count_over_time(trackly_session_heartbeat[1d] offset 1d) by (session_hash)) | ||
| count(sum by (session_hash) (count_over_time(trackly_session_heartbeat[1d] offset 1d))) | ||
| - record: retention_d7 | ||
| expr: | | ||
| count( | ||
| count_over_time(trackly_session_heartbeat[7d] offset 7d) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[7d] offset 7d)) | ||
| and | ||
| count_over_time(trackly_session_heartbeat[7d]) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[7d])) | ||
| ) | ||
| / | ||
| count(count_over_time(trackly_session_heartbeat[7d] offset 7d) by (session_hash)) | ||
| count(sum by (session_hash) (count_over_time(trackly_session_heartbeat[7d] offset 7d))) | ||
| - record: retention_d30 | ||
| expr: | | ||
| count( | ||
| count_over_time(trackly_session_heartbeat[30d] offset 30d) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[30d] offset 30d)) | ||
| and | ||
| count_over_time(trackly_session_heartbeat[30d]) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[30d])) | ||
| ) | ||
| / | ||
| count(count_over_time(trackly_session_heartbeat[30d] offset 30d) by (session_hash)) | ||
| count(sum by (session_hash) (count_over_time(trackly_session_heartbeat[30d] offset 30d))) | ||
|
|
||
| # Engagement segments (passive/active/power) derived from engagement_score_7d | ||
| - record: engagement_segment_passive | ||
|
|
@@ -95,7 +95,7 @@ groups: | |
| - record: new_sessions_1d_approx | ||
| expr: | | ||
| count( | ||
| count_over_time(trackly_session_heartbeat[1d]) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[1d])) | ||
| unless | ||
| count_over_time(trackly_session_heartbeat[30d] offset 1d) by (session_hash) | ||
| sum by (session_hash) (count_over_time(trackly_session_heartbeat[30d] offset 1d)) | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filtering condition
> 0is redundant in this context. Thecount()function already excludes time series with no samples. Sincesum by (session_hash) (count_over_time(...))will only produce results for session_hashes that have at least one sample, the> 0filter doesn't change the result. Consider simplifying tocount(sum by (session_hash) (count_over_time(trackly_session_heartbeat{job="trackly_backend"}[24h])))for clarity and consistency with the recording rules that usesum by (session_hash) (count_over_time(...))without the> 0filter.