rob05c commented on a change in pull request #3104: Add monitoring.json
snapshotting
URL: https://github.com/apache/trafficcontrol/pull/3104#discussion_r241074237
##########
File path: traffic_ops/traffic_ops_golang/crconfig/snapshot.go
##########
@@ -68,11 +76,42 @@ where c.name = $1
// CDN doesn't exist
return "", false, nil
}
- return "", false, errors.New("Error querying snapshot: " +
err.Error())
+ return "", false, errors.New("Error querying crconfig snapshot:
" + err.Error())
}
if !snapshot.Valid {
// CDN exists, but snapshot doesn't
return `{}`, true, nil
}
return snapshot.String, true, nil
}
+
+// GetSnapshotMonitoring gets the monitor snapshot for the given CDN.
+// If the CDN does not exist, false is returned.
+// If the CDN exists, but the snapshot does not, the string for an empty JSON
object "{}" is returned.
+// An error is only returned on database error, never if the CDN or snapshot
does not exist.
+// Because all snapshotting is handled by the crconfig endpoints we have to
also do the monitoring one
+// here as well
+func GetSnapshotMonitoring(tx *sql.Tx, cdn string) (string, bool, error) {
+ log.Debugln("calling GetSnapshotMonitoring")
+
+ monitorSnapshot := sql.NullString{}
+ // cdn left join snapshot, so we get a row with null if the CDN exists
but the snapshot doesn't, and no rows if the CDN doesn't exist.
+ q := `
+select s.monitoring as snapshot
Review comment:
Nitpick: Good formatting, but we're trying to move toward capitalizing SQL
keywords as well, prefer:
```
SELECT s.monitoring AS snapshot
FROM cdn AS c ...
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services