Skip to content

feat: expose app insights as Prometheus metrics #10346

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

Merged
merged 20 commits into from
Nov 7, 2023
Merged
Prev Previous commit
Next Next commit
Nasty hack
  • Loading branch information
mtojek committed Nov 7, 2023
commit 5140fbca856bd3a93e57bb63a4e7303d2e46d3b2
16 changes: 13 additions & 3 deletions coderd/prometheusmetrics/insights/metricscollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func TestCollectInsights(t *testing.T) {
AccessMethod: "terminal",
SlugOrPort: "golden-slug",
SessionID: uuid.New(),
SessionStartedAt: time.Now().Add(-5 * time.Minute),
SessionEndedAt: time.Now(),
SessionStartedAt: time.Now().Add(-3 * time.Minute),
SessionEndedAt: time.Now().Add(-time.Minute),
Requests: 1,
},
})
Expand Down Expand Up @@ -148,7 +148,17 @@ func TestCollectInsights(t *testing.T) {
if len(m.Label) > 0 {
key = key + "[" + metricLabelAsString(m) + "]"
}
collected[key] = int(m.Gauge.GetValue())

v := int(m.Gauge.GetValue())
// Unfortunately, this test is time dependent, and due to `s.SessionStartedAt.Truncate`
// performed in `GetTemplateAppInsightsByTemplate`, the session duration can't be
// deterministic.
//
// To ensure consistency with golden files, let's set a constant value, 1sec.
if metric.GetName() == "coderd_insights_applications_usage_seconds" {
v = 1
}
collected[key] = v
}
default:
require.FailNowf(t, "unexpected metric collected", "metric: %s", metric.GetName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coderd_insights_applications_usage_seconds[application_name=SSH,template_name=golden-template]": 60,
"coderd_insights_applications_usage_seconds[application_name=Golden Slug,template_name=golden-template]": 300,
"coderd_insights_applications_usage_seconds[application_name=SSH,template_name=golden-template]": 1,
"coderd_insights_applications_usage_seconds[application_name=Golden Slug,template_name=golden-template]": 1,
"coderd_insights_templates_active_users[template_name=golden-template]": 1
}