8000 feat: expose app insights as Prometheus metrics by mtojek · Pull Request #10346 · coder/coder · GitHub
[go: up one dir, main page]

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
Try with 1min truncation
  • Loading branch information
mtojek committed Nov 7, 2023
commit be7b50e8030174a473c78a3a174000d390893d92
5 changes: 3 additions & 2 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2410,11 +2410,12 @@ func (q *FakeQuerier) GetTemplateAppInsightsByTemplate(ctx context.Context, arg
Slug: app.Slug,
}

t := s.SessionStartedAt.Truncate(5 * time.Minute)
t := s.SessionStartedAt.Truncate(time.Minute)
sessionEndedAt := s.SessionEndedAt.Add(-time.Microsecond).Truncate(time.Minute)
if t.Before(arg.StartTime) {
t = arg.StartTime
}
for t.Before(s.SessionEndedAt) && t.Before(arg.EndTime) {
for t.Before(sessionEndedAt) && t.Before(arg.EndTime) {
if _, ok := usageByTemplateAppUser[key]; !ok {
usageByTemplateAppUser[key] = map[time.Time]map[uuid.UUID]int64{}
}
Expand Down
12 changes: 1 addition & 11 deletions coderd/prometheusmetrics/insights/metricscollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,7 @@ func TestCollectInsights(t *testing.T) {
if len(m.Label) > 0 {
key = key + "[" + metricLabelAsString(m) + "]"
}

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
collected[key] = int(m.Gauge.GetValue())
}
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]": 1,
"coderd_insights_applications_usage_seconds[application_name=Golden Slug,template_name=golden-template]": 1,
"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]": 120,
"coderd_insights_templates_active_users[template_name=golden-template]": 1
}
0