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

feat: support include/exclude for labels filter in config summary #1028

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: consistent behavior in filter clause
adityathebe committed Sep 12, 2024
commit fac83f3d75259a5b4c9ca3e149b63c9467ae63d4
24 changes: 17 additions & 7 deletions query/config.go
Original file line number Diff line number Diff line change
@@ -218,29 +218,39 @@ func (t ConfigSummaryRequest) healthClause() []clause.Expression {
}

func (t *ConfigSummaryRequest) filterClause(q *gorm.DB) *gorm.DB {
var orClause *gorm.DB
var includeClause *gorm.DB
var excludeClause *gorm.DB

for k, v := range t.Filter {
in, notIN, _, _, _ := ParseFilteringQuery(v, true)

if len(notIN) > 0 {
if excludeClause == nil {
excludeClause = q
}

for _, excludeValue := range notIN {
q = q.Where("NOT (config_items.labels @> ?)", types.JSONStringMap{k: excludeValue.(string)})
excludeClause = excludeClause.Where("NOT (config_items.labels @> ?)", types.JSONStringMap{k: excludeValue.(string)})
}
}

if len(in) > 0 {
if orClause == nil {
orClause = q
if includeClause == nil {
includeClause = q
}

for _, includeValue := range in {
orClause = orClause.Or("config_items.labels @> ?", types.JSONStringMap{k: includeValue.(string)})
includeClause = includeClause.Or("config_items.labels @> ?", types.JSONStringMap{k: includeValue.(string)})
}
}
}

if orClause != nil {
q = q.Where(orClause)
if includeClause != nil {
q = q.Where(includeClause)
}

if excludeClause != nil {
q = q.Where(excludeClause)
}

return q
1 change: 1 addition & 0 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
@@ -19,4 +19,5 @@ func TestDuty(t *testing.T) {
var _ = ginkgo.BeforeSuite(func() {
DefaultContext = setup.BeforeSuiteFn()
})

var _ = ginkgo.AfterSuite(setup.AfterSuiteFn)