mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-31 13:47:02 +02:00
fix: now metrics in search will be aggregated across applications (#6915)
This commit is contained in:
parent
9c883ca37d
commit
e0ec5ed4b0
@ -107,8 +107,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
|||||||
'ft.tag_value as tag_value',
|
'ft.tag_value as tag_value',
|
||||||
'ft.tag_type as tag_type',
|
'ft.tag_type as tag_type',
|
||||||
'segments.name as segment_name',
|
'segments.name as segment_name',
|
||||||
'client_metrics_env.yes as yes',
|
|
||||||
'client_metrics_env.no as no',
|
|
||||||
] as (string | Raw<any> | Knex.QueryBuilder)[];
|
] as (string | Raw<any> | Knex.QueryBuilder)[];
|
||||||
|
|
||||||
const lastSeenQuery = 'last_seen_at_metrics.last_seen_at';
|
const lastSeenQuery = 'last_seen_at_metrics.last_seen_at';
|
||||||
@ -212,23 +210,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
|||||||
'=',
|
'=',
|
||||||
'features.name',
|
'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 () {
|
query.leftJoin('last_seen_at_metrics', function () {
|
||||||
@ -264,6 +245,30 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
|||||||
'total_features',
|
'total_features',
|
||||||
this.db.raw('select count(*) as total from final_ranks'),
|
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('*')
|
.select('*')
|
||||||
.from('ranked_features')
|
.from('ranked_features')
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
@ -271,6 +276,17 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
|||||||
'ranked_features.feature_name',
|
'ranked_features.feature_name',
|
||||||
'final_ranks.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')
|
.joinRaw('CROSS JOIN total_features')
|
||||||
.whereBetween('final_rank', [offset + 1, offset + limit]);
|
.whereBetween('final_rank', [offset + 1, offset + limit]);
|
||||||
const rows = await finalQuery;
|
const rows = await finalQuery;
|
||||||
|
@ -939,6 +939,14 @@ test('should return environment usage metrics', async () => {
|
|||||||
yes: 5,
|
yes: 5,
|
||||||
no: 2,
|
no: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
featureName: `my_feature_b`,
|
||||||
|
appName: `web2`,
|
||||||
|
environment: 'development',
|
||||||
|
timestamp: new Date(),
|
||||||
|
yes: 5,
|
||||||
|
no: 2,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
featureName: `my_feature_b`,
|
featureName: `my_feature_b`,
|
||||||
appName: `web`,
|
appName: `web`,
|
||||||
@ -964,8 +972,8 @@ test('should return environment usage metrics', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'development',
|
name: 'development',
|
||||||
yes: 5,
|
yes: 10,
|
||||||
no: 2,
|
no: 4,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'production',
|
name: 'production',
|
||||||
|
Loading…
Reference in New Issue
Block a user