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

Make user-friendly status filter multi-search #43

Merged

Conversation

krithika369
Copy link
Collaborator

@krithika369 krithika369 commented Oct 12, 2022

What this PR does / why we need it: This is a follow up from the previous PR #42 which introduced a search filter for the experiments using user-friendly status names. However, in that PR, the API was only designed to take in a single value. This PR makes it possible to search using multiple values of the status, to match any of them. This required the underlying gorm library to be upgraded, as the OR clauses were not gracefully handled in the older version.

Illustration

multiSelectStatus.mov

Search Filter Changes

  • api/experiments.yaml - Accept multiple values for status_friendly, in List Experiments filters
  • management-service/controller/experiment_controller.go - Handle multiple values for status_friendly in List API search filters
  • management-service/services/experiment_service.go - Add filterExperimentStatusFriendly to handle matching the status values.
  • ui/src/experiments/list/search/components/ExperimentStatusFilter.js - Make the status filter multiselect

GORM upgrade

  • Move from:
    • github.com/jinzhu/gorm -> gorm.io/gorm @ latest
    • github.com/jinzhu/gorm/dialects/postgres -> gorm.io/driver/postgres @ latest
  • management-service/database/database.go, management-service/server/server.go, management-service/internal/testutils/database.go - DB init / close related API changes
  • management-service/models/experiment.go, management-service/models/experiment_history.go - Add AfterFind hook as the new ORM version doesn't respect the timezone info in the connection string.
  • Some int / int32 / int64 conversions in OFFSET / LIMIT / COUNT queries to match the new APIs
  • The save function in every service that saves the data to the DB is refactored to use Upsert instead of Create / Update. This is needed because the NewRecord function from Gorm v1 no longer exists. Ref: https://gorm.io/docs/create.html#Upsert-x2F-On-Conflict

@krithika369 krithika369 marked this pull request as draft October 12, 2022 02:37
err = database.Migrate(cfg.DbConfig)
if err != nil {
panic(err)
}
db.LogMode(false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now added to management-service/database/database.go, as a part of the Gorm config, when opening the DB connection. Ref: https://gorm.io/docs/logger.html

@@ -49,12 +49,15 @@ func NewServer(configFiles []string) (*Server, error) {
if err != nil {
panic(err)
}
sqlDB, err := db.DB()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gorm doesn't expose a close method anymore on its DB. We have to grab the underlying SQL db and close it.

OR tstzrange(start_time, end_time, '()') @> tstzrange(?, ?, '[]')
OR tstzrange(?, ?, '[]') @> tstzrange(start_time, end_time, '[)')`,
params.StartTime, params.StartTime, params.EndTime, params.EndTime, params.StartTime, params.EndTime,
svc.query().
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactoring this OR clause to use the APIs rather than raw query string, since the new version of the Gorm API supports it correctly.

@krithika369 krithika369 self-assigned this Oct 12, 2022
@krithika369 krithika369 marked this pull request as ready for review October 12, 2022 03:54
@krithika369 krithika369 requested a review from a team October 12, 2022 03:54
Copy link
Contributor

@deadlycoconuts deadlycoconuts left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀 Thanks a lot for updating all the instances where we're using the gorm library!

}
}
if len(params.StatusFriendly) > 0 {
query = svc.filterExperimentStatusFriendly(query, params.StatusFriendly)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for refactoring this into a separate method!

@krithika369 krithika369 merged commit 87dd5d3 into caraml-dev:main Oct 18, 2022
@krithika369 krithika369 deleted the multisearch_experiment_status branch October 18, 2022 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants