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

RHINENG-14146 Optimize Get Recommendations Query #282

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Suggested changes for Truncate method usage
  • Loading branch information
saltgen committed Jan 7, 2025
commit bd1791637e86cd0b75e14f8d3a811d4da5e5ca98
7 changes: 3 additions & 4 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ func TestMapQueryParameters(t *testing.T) {
}

now := time.Now().UTC().Truncate(time.Second)
firstOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC).Truncate(time.Second)

startTime := time.Date(2023, 3, 23, 0, 0, 0, 0, time.UTC).Truncate(time.Second)
endTime := time.Date(2023, 3, 24, 0, 0, 0, 0, time.UTC).Truncate(time.Second)
firstOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
startTime := time.Date(2023, 3, 23, 0, 0, 0, 0, time.UTC)
endTime := time.Date(2023, 3, 24, 0, 0, 0, 0, time.UTC)

all_tests := []tests{
{
Expand Down
6 changes: 3 additions & 3 deletions internal/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func MapQueryParameters(c echo.Context) (map[string]interface{}, error) {
var startTimestamp, endTimestamp time.Time
var clusters, projects, workloadNames, workloadTypes, containers []string

now := time.Now().UTC()
now := time.Now().UTC().Truncate(time.Second)
firstOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)

startDateStr := c.QueryParam("start_date")
Expand All @@ -85,7 +85,7 @@ func MapQueryParameters(c echo.Context) (map[string]interface{}, error) {
return queryParams, err
}
}
queryParams["recommendation_sets.monitoring_end_time >= ?"] = startTimestamp.Truncate(time.Second)
queryParams["recommendation_sets.monitoring_end_time >= ?"] = startTimestamp

endDateStr := c.QueryParam("end_date")
if endDateStr == "" {
Expand All @@ -98,7 +98,7 @@ func MapQueryParameters(c echo.Context) (map[string]interface{}, error) {
return queryParams, err
}
}
queryParams["recommendation_sets.monitoring_end_time <= ?"] = endTimestamp.Truncate(time.Second)
queryParams["recommendation_sets.monitoring_end_time <= ?"] = endTimestamp

clusters = c.QueryParams()["cluster"]
if len(clusters) > 0 {
Expand Down
Loading