-
Notifications
You must be signed in to change notification settings - Fork 24
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
RHINENG-14146 Optimize Get Recommendations Query #282
RHINENG-14146 Optimize Get Recommendations Query #282
Conversation
I'll fix the unittest soon, please feel free to go through the other changes meanwhile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me. 👍 I will continue reviewing latest updated changes specific to date field.
Added just two inline suggestions. Please feel free to skip if it doesn't make sense.
Thanks!
if endDateStr == "" { | ||
endDate = now | ||
endTimestamp = now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endTimestamp = now | |
endTimestamp = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would work in case we don't expect any values for the query param end_date
.
Not sure if I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have the time portion available in the timestamp especially when the query param end_time
value has not been provided
Request to rebase! the IQE tests are running most of the times now! |
d96ab53
to
bd8f4da
Compare
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query
var in GetRecommendationSets
and GetRecommendationSetByID
is exactly same part from a filter Where("recommendation_sets.id = ?", recommendationID)
. This is good candidate to consolidate and take out in another common function.
bd8f4da
to
7e745bc
Compare
/retest |
On IQE I can see its failing because of syntax error, however I dont see this locally? hmm.. is it because locally I am on 1.22 version of Go? need to check,
|
I'll take a look |
@upadhyeammit This should be fixed now, I have also pushed some DRY for GetRecommendationSet db method |
@@ -97,6 +97,8 @@ func MapQueryParameters(c echo.Context) (map[string]interface{}, error) { | |||
log.Error("error parsing end_date:", err) | |||
return queryParams, err | |||
} | |||
// Inclusive user-provided end_date timestamp | |||
endTimestamp = endTimestamp.Add(24 * time.Hour) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@upadhyeammit, what would prefer to have your opinion as well on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me bit of time to understand whats happening here. I can see we are adding 24hours(a day) to user provided date for returning the recommendations upto user provided date. However the condition for filter has <=
; so do we need it?
queryParams["recommendation_sets.monitoring_end_time <= ?"] = endTimestamp
edit:
And if its about, in db we store date plus timestamp and so we need timestamp as well, in that case I think then do we also need -1 day for start date?
Current time 2025-01-13 13:03:28.909723655 +0530 IST m=+0.000029727
User time 2025-01-14
Parsed time 2025-01-14 00:00:00 +0000 UTC
Time after addition 2025-01-15 00:00:00 +0000 UTC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the =
from queryParams["recommendation_sets.monitoring_end_time <= ?"] = endTimestamp
Regarding start_date
I think we should be fine, the 24 Hrs delta is being added only for user provided end_date
internal/model/recommendation_set.go
Outdated
func (r *RecommendationSet) GetRecommendationSets(orgID string, orderQuery string, limit int, offset int, queryParams map[string][]string, user_permissions map[string][]string) ([]RecommendationSet, int, error) { | ||
|
||
var recommendationSets []RecommendationSet | ||
func (r *RecommendationSet) GetRecommendationSet(orgID string, user_permissions map[string][]string, opts ...GetRecommendationOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep separate func for GetRecommendationSet
and GetRecommendationSetByID
, now I see a bigger method doing both.
So it should be,
- Separate
GetRecommendationSet
andGetRecommendationSetByID
- A func for common query
- Another func if there is anything more common, again there is possibility of having few more func instead of just one, considering those have set responsibilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change pushed
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codewise changes look good to me now 👍
@saltgen, could you please check why konflux pipeline is not happy?
/retest |
2 similar comments
/retest |
/retest |
/retest |
1 similar comment
/retest |
Why do we need this change? 💭
The current sql query is expensive considering there is a lot of records to sift through.
Analysis details are present in the JIRA card.
That said, some important details are provided in the Additional section below.
Documentation update? 📝
Security Checklist 🔒
Upon raising this PR please go through RedHatInsights/secure-coding-checklist
💂♂️ Checklist 🎯
Additional 📣
Indexes added
clusters (last_reported_at)
recommendation_sets (workload_id)
workloads (cluster_id)
Other Optimizations
Query Diffs
GetRecommendationSet
Old
New
GetRecommendationSetByID
Old
New