mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: insights metrics comparison (#10800)
* fix: insights metrics comparison * links
This commit is contained in:
@ -31,7 +31,6 @@ import (
|
||||
|
||||
func TestCollectInsights(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Skip("https://github.com/coder/coder/issues/10599#issuecomment-1815954166")
|
||||
|
||||
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
|
||||
db, ps := dbtestutil.NewDB(t)
|
||||
@ -164,7 +163,7 @@ func TestCollectInsights(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
return assert.ObjectsAreEqualValues(golden, collected)
|
||||
return insightsMetricsAreEqual(golden, collected)
|
||||
}, testutil.WaitMedium, testutil.IntervalFast, "template insights are inconsistent with golden files, got: %v", collected)
|
||||
}
|
||||
|
||||
@ -219,3 +218,23 @@ func provisionApplyWithAgentAndApp(authToken string) []*proto.Response {
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
// insightsMetricsAreEqual patches collected metrics to be used
|
||||
// in comparison with golden metrics using `assert.ObjectsAreEqualValues`.
|
||||
// Collected metrics must be patched as sometimes they may slip
|
||||
// due to timestamp truncation.
|
||||
// See:
|
||||
// https://github.com/coder/coder/blob/92ef0baff3b632c52c2335aae1d643a3cc49e26a/coderd/database/dbmem/dbmem.go#L2463
|
||||
// https://github.com/coder/coder/blob/9b6433e3a7c788b7e87b7d8f539ea111957a0cf1/coderd/database/queries/insights.sql#L246
|
||||
func insightsMetricsAreEqual(golden, collected map[string]int) bool {
|
||||
greaterOrEqualKeys := []string{
|
||||
"coderd_insights_applications_usage_seconds[application_name=Golden Slug,slug=golden-slug,template_name=golden-template]",
|
||||
"coderd_insights_applications_usage_seconds[application_name=SSH,slug=,template_name=golden-template]",
|
||||
}
|
||||
for _, key := range greaterOrEqualKeys {
|
||||
if v, ok := collected[key]; ok && v > golden[key] {
|
||||
collected[key] = golden[key]
|
||||
}
|
||||
}
|
||||
return assert.ObjectsAreEqualValues(golden, collected)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
"coderd_insights_applications_usage_seconds[application_name=Visual Studio Code,slug=,template_name=golden-template]": 0,
|
||||
"coderd_insights_applications_usage_seconds[application_name=Web Terminal,slug=,template_name=golden-template]": 0,
|
||||
"coderd_insights_applications_usage_seconds[application_name=SSH,slug=,template_name=golden-template]": 60,
|
||||
"coderd_insights_applications_usage_seconds[application_name=Golden Slug,slug=golden-slug,template_name=golden-template]": 180,
|
||||
"coderd_insights_applications_usage_seconds[application_name=Golden Slug,slug=golden-slug,template_name=golden-template]": 120,
|
||||
"coderd_insights_parameters[parameter_name=first_parameter,parameter_type=string,parameter_value=Foobar,template_name=golden-template]": 1,
|
||||
"coderd_insights_parameters[parameter_name=second_parameter,parameter_type=bool,parameter_value=true,template_name=golden-template]": 1,
|
||||
"coderd_insights_parameters[parameter_name=third_parameter,parameter_type=number,parameter_value=789,template_name=golden-template]": 1,
|
||||
|
Reference in New Issue
Block a user