ocket8888 commented on code in PR #7291:
URL: https://github.com/apache/trafficcontrol/pull/7291#discussion_r1087207890
##########
traffic_ops/traffic_ops_golang/monitoring/monitoring.go:
##########
@@ -188,7 +188,7 @@ SELECT
status.name as status,
cachegroup.name as cachegroup,
me.tcp_port as port,
- profile.name as profile,
+ (SELECT STRING_AGG(sp.profile_name, '+' ORDER by sp.priority ASC) FROM
server_profile AS sp where sp.server=me.id group by sp.server) as profile,
Review Comment:
This aggregation will break if I have a Profile that contains `+` in its
Name.
Why build up this big simulated Profile-aggregate-pseudo-name thingy instead
of just getting an array of Profile names? Seems like that would be easier to
deal with than joining and splitting on a special string.
##########
traffic_ops/traffic_ops_golang/monitoring/monitoring.go:
##########
@@ -571,3 +542,46 @@ AND c.name = $3
}
return cfg, nil
}
+
+func aggregateMultipleProfileParameters(tx *sql.Tx, profileNames []string)
(map[string]map[string]interface{}, error) {
+ p := make(map[string]map[string]interface{})
+ query := `
+SELECT p.name, pr.name, pr.value
+FROM parameter pr
+JOIN profile p ON p.name = ANY($1)
+JOIN profile_parameter pp ON pp.profile = p.id and pp.parameter = pr.id
+WHERE pr.config_file = $2
+ORDER BY ARRAY_POSITION($1, p.name), pr.name;`
+
+ for _, profile := range profileNames {
+ profileList := strings.Split(profile, "+")
+ rows, err := tx.Query(query, pq.Array(profileList),
CacheMonitorConfigFile)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ var parameter map[string]interface{}
+ for rows.Next() {
+ var pName, prName, value string
+ if err := rows.Scan(&pName, &prName, &value); err !=
nil {
+ return nil, err
+ }
+ if prName == "" {
+ return nil, fmt.Errorf("null name") // TODO
continue and warn?
+ }
+ if parameter == nil {
+ parameter = map[string]interface{}{}
+ }
Review Comment:
Why not just initialize it to an empty map instead of doing this check on
every iteration?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]