Skip to content

Commit abdd9f9

Browse files
committed
RHINENG-20067: update schema for filters
workload related fields moved from 'system_profile->xxx' to 'system_profile->workloads->xxx' and sap related keys even moved into 'system_profile->workloads->sap->xxx'
1 parent bcac7af commit abdd9f9

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

manager/controllers/utils.go

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ type NestedFilterMap map[string]string
9696

9797
var nestedFilters = NestedFilterMap{
9898
"group_name": "group_name",
99-
"system_profile][sap_system": "system_profile][sap_system",
100-
"system_profile][sap_sids": "system_profile][sap_sids",
101-
"system_profile][ansible": "system_profile][ansible",
102-
"system_profile][ansible][controller_version": "system_profile][ansible][controller_version",
103-
"system_profile][mssql": "system_profile][mssql",
104-
"system_profile][mssql][version": "system_profile][mssql][version",
99+
"system_profile][sap_system": "(ih.system_profile->'workloads'->'sap'->>'sap_system')",
100+
"system_profile][sap_sids": "(ih.system_profile->'workloads'->'sap'->>'sids')",
101+
"system_profile][sap_sids][in]": "(ih.system_profile->'workloads'->'sap'->>'sids')",
102+
"system_profile][ansible": "(ih.system_profile->'workloads'->>'ansible')",
103+
"system_profile][ansible][controller_version": "(ih.system_profile->'workloads'->'ansible'->>'controller_version')",
104+
"system_profile][mssql": "(ih.system_profile->'workloads'->>'mssql')",
105+
"system_profile][mssql][version": "(ih.system_profile->'workloads'->'mssql'->>'version')",
105106
}
106107

107108
func ParseFilters(c *gin.Context, filters Filters, allowedFields database.AttrMap,
@@ -112,8 +113,7 @@ func ParseFilters(c *gin.Context, filters Filters, allowedFields database.AttrMa
112113
subject := name[7 : len(name)-1] // strip key from "filter[...]"
113114
for _, v := range values {
114115
if _, ok := nestedFilters[subject]; ok {
115-
nested := nestedFilters[subject]
116-
filters.Update(InventoryFilter, nested, v)
116+
filters.Update(InventoryFilter, subject, v)
117117
continue
118118
}
119119
if _, ok := allowedFields[subject]; !ok {
@@ -413,10 +413,10 @@ func ApplyInventoryWhere(filters map[string]FilterData, tx *gorm.DB) (*gorm.DB,
413413
return tx, applied
414414
}
415415

416-
// Builds inventory sub query in generic way.
416+
// Builds inventory sub query
417417
// Example:
418-
// buildSystemProfileQuery("mssql->version", "1.0")
419-
// returns "(ih.system_profile -> 'mssql' ->> 'version')::text = 1.0"
418+
// buildSystemProfileQuery("system_profile][mssql][version", "1.0")
419+
// returns "(ih.system_profile->'workloads'->'mssql'->>'version') = 1.0"
420420
func buildInventoryQuery(tx *gorm.DB, key string, values []string) *gorm.DB {
421421
if strings.Contains(key, "group_name") {
422422
groups := []string{}
@@ -444,20 +444,10 @@ func buildInventoryQuery(tx *gorm.DB, key string, values []string) *gorm.DB {
444444
bval, _ := sonic.Marshal(values)
445445
val = string(bval)
446446
default:
447-
cmp = "::text = ?"
447+
cmp = " = ?"
448448
}
449449

450-
sbkeys := strings.Split(key, "][")
451-
subq := fmt.Sprintf("(ih.%s", sbkeys[0])
452-
nSbkeys := len(sbkeys)
453-
if nSbkeys > 2 {
454-
subq = fmt.Sprintf("%s -> '%s'", subq, strings.Join(sbkeys[1:nSbkeys-1], "' -> '"))
455-
}
456-
if nSbkeys > 1 {
457-
subq = fmt.Sprintf("%s ->> '%s')", subq, sbkeys[nSbkeys-1])
458-
}
459-
460-
subq = fmt.Sprintf("%s%s", subq, cmp)
450+
subq := fmt.Sprintf("%s%s", nestedFilters[key], cmp)
461451
if val == "not_nil" {
462452
return tx.Where(subq)
463453
}

tasks/vmaas_sync/metrics_cyndi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
// nolint: lll
3434
type cyndiMetricColumns struct {
3535
AllSystems int64 `query:"count(*)" gorm:"column:all_systems"`
36-
SapSystems int64 `query:"count(*) filter (where system_profile -> 'sap_system' = 'true')" gorm:"column:sap_systems"`
36+
SapSystems int64 `query:"count(*) filter (where system_profile -> 'workloads' -> 'sap' -> 'sap_system' = 'true')" gorm:"column:sap_systems"`
3737
TaggedSystems int64 `query:"count(*) filter (where jsonb_array_length(tags) > 0)" gorm:"column:tagged_systems"`
3838
Updated1D int64 `query:"count(*) filter (where updated > (now() - interval '1 day'))" gorm:"column:updated1d"`
3939
Updated7D int64 `query:"count(*) filter (where updated > (now() - interval '7 day'))" gorm:"column:updated7d"`

0 commit comments

Comments
 (0)