Skip to content

Commit

Permalink
fix: now metrics in search will be aggregated across applications (#6915
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sjaanus committed Apr 24, 2024
1 parent 9c883ca commit e0ec5ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
54 changes: 35 additions & 19 deletions src/lib/features/feature-search/feature-search-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
'ft.tag_value as tag_value',
'ft.tag_type as tag_type',
'segments.name as segment_name',
'client_metrics_env.yes as yes',
'client_metrics_env.no as no',
] as (string | Raw<any> | Knex.QueryBuilder)[];

const lastSeenQuery = 'last_seen_at_metrics.last_seen_at';
Expand Down Expand Up @@ -212,23 +210,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
'=',
'features.name',
);
})
.leftJoin('client_metrics_env', (qb) => {
qb.on(
'client_metrics_env.environment',
'=',
'environments.name',
)
.andOn(
'client_metrics_env.feature_name',
'=',
'features.name',
)
.andOn(
'client_metrics_env.timestamp',
'>=',
this.db.raw("NOW() - INTERVAL '1 hour'"),
);
});

query.leftJoin('last_seen_at_metrics', function () {
Expand Down Expand Up @@ -264,13 +245,48 @@ class FeatureSearchStore implements IFeatureSearchStore {
'total_features',
this.db.raw('select count(*) as total from final_ranks'),
)
.with('metrics', (queryBuilder) => {
queryBuilder
.sum('yes as yes')
.sum('no as no')
.select([
'client_metrics_env.environment',
'client_metrics_env.feature_name',
])
.from('client_metrics_env')
.innerJoin(
'final_ranks',
'client_metrics_env.feature_name',
'final_ranks.feature_name',
)
.where(
'client_metrics_env.timestamp',
'>=',
this.db.raw("NOW() - INTERVAL '1 hour'"),
)
.groupBy([
'client_metrics_env.feature_name',
'client_metrics_env.environment',
]);
})
.select('*')
.from('ranked_features')
.innerJoin(
'final_ranks',
'ranked_features.feature_name',
'final_ranks.feature_name',
)
.leftJoin('metrics', (qb) => {
qb.on(
'metrics.environment',
'=',
'ranked_features.environment',
).andOn(
'metrics.feature_name',
'=',
'ranked_features.feature_name',
);
})
.joinRaw('CROSS JOIN total_features')
.whereBetween('final_rank', [offset + 1, offset + limit]);
const rows = await finalQuery;
Expand Down
12 changes: 10 additions & 2 deletions src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,14 @@ test('should return environment usage metrics', async () => {
yes: 5,
no: 2,
},
{
featureName: `my_feature_b`,
appName: `web2`,
environment: 'development',
timestamp: new Date(),
yes: 5,
no: 2,
},
{
featureName: `my_feature_b`,
appName: `web`,
Expand All @@ -964,8 +972,8 @@ test('should return environment usage metrics', async () => {
},
{
name: 'development',
yes: 5,
no: 2,
yes: 10,
no: 4,
},
{
name: 'production',
Expand Down

0 comments on commit e0ec5ed

Please sign in to comment.