Skip to content
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

fix: now metrics in search will be aggregated across applications #6915

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

sjaanus
Copy link
Contributor

@sjaanus sjaanus commented Apr 24, 2024

We found a bug indicating that the search was not aggregating metrics properly. The issue was that if there were multiple applications posting metrics, only the metrics from the first one were used.

Fixes implemented in this PR:

Do not join metrics into the main query, as they are not needed for filtering and paging.
Determine 'yes' and 'no' counts outside of the main query, within a CTE.

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 8:17am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Apr 24, 2024 8:17am

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 1 findings(s) 🚩

View detailed results in CodeScene

Comment on lines +279 to +289
.leftJoin('metrics', (qb) => {
qb.on(
'metrics.environment',
'=',
'ranked_features.environment',
).andOn(
'metrics.feature_name',
'=',
'ranked_features.feature_name',
);
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Complex Method
FeatureSearchStore.searchFeatures already has high cyclomatic complexity, and now it increases in Lines of Code from 211 to 227

Suppress

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 1 findings(s) 🚩

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

  • Declining Code Health: 1 findings(s) 🚩

View detailed results in CodeScene

@@ -212,23 +210,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
'=',
'features.name',
);
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now not joining in into main query, because not neede for filtering, paging

.select('*')
.from('ranked_features')
.innerJoin(
'final_ranks',
'ranked_features.feature_name',
'final_ranks.feature_name',
)
.leftJoin('metrics', (qb) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Join it later, just to get the data.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change might have introduced a bug -- when you join here, fields of metrics are also in the final result, duplicating the column names feature_name and environment. When there are no metrics, the fields can be null here (leftJoin, after all), causing problems with the aggregation of the results.

#6988

@sjaanus sjaanus merged commit e0ec5ed into main Apr 24, 2024
12 of 13 checks passed
@sjaanus sjaanus deleted the fix-aggregation branch April 24, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants