@@ -31,7 +31,6 @@ import (
31
31
32
32
func TestCollectInsights (t * testing.T ) {
33
33
t .Parallel ()
34
- t .Skip ("https://github.com/coder/coder/issues/10599#issuecomment-1815954166" )
35
34
36
35
logger := slogtest .Make (t , & slogtest.Options {IgnoreErrors : true })
37
36
db , ps := dbtestutil .NewDB (t )
@@ -164,7 +163,7 @@ func TestCollectInsights(t *testing.T) {
164
163
}
165
164
}
166
165
167
- return assert . ObjectsAreEqualValues (golden , collected )
166
+ return insightsMetricsAreEqual (golden , collected )
168
167
}, testutil .WaitMedium , testutil .IntervalFast , "template insights are inconsistent with golden files, got: %v" , collected )
169
168
}
170
169
@@ -219,3 +218,23 @@ func provisionApplyWithAgentAndApp(authToken string) []*proto.Response {
219
218
},
220
219
}}
221
220
}
221
+
222
+ // insightsMetricsAreEqual patches collected metrics to be used
223
+ // in comparison with golden metrics using `assert.ObjectsAreEqualValues`.
224
+ // Collected metrics must be patched as sometimes they may slip
225
+ // due to timestamp truncation.
226
+ // See:
227
+ // https://github.com/coder/coder/blob/92ef0baff3b632c52c2335aae1d643a3cc49e26a/coderd/database/dbmem/dbmem.go#L2463
228
+ // https://github.com/coder/coder/blob/9b6433e3a7c788b7e87b7d8f539ea111957a0cf1/coderd/database/queries/insights.sql#L246
229
+ func insightsMetricsAreEqual (golden , collected map [string ]int ) bool {
230
+ greaterOrEqualKeys := []string {
231
+ "coderd_insights_applications_usage_seconds[application_name=Golden Slug,slug=golden-slug,template_name=golden-template]" ,
232
+ "coderd_insights_applications_usage_seconds[application_name=SSH,slug=,template_name=golden-template]" ,
233
+ }
234
+ for _ , key := range greaterOrEqualKeys {
235
+ if v , ok := collected [key ]; ok && v > golden [key ] {
236
+ collected [key ] = golden [key ]
237
+ }
238
+ }
239
+ return assert .ObjectsAreEqualValues (golden , collected )
240
+ }
0 commit comments