ocket8888 commented on a change in pull request #3758: Rewrote 
deliveryservice_stats to Go
URL: https://github.com/apache/trafficcontrol/pull/3758#discussion_r328776808
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/api.go
 ##########
 @@ -369,6 +382,78 @@ func (inf *APIInfo) Close() {
        }
 }
 
+// CreateInfluxClient onstructs and returns an InfluxDB HTTP client, if 
enabled and when possible.
+// The error this returns should not be exposed to the user; it's for logging 
purposes only.
+//
+// If Influx connections are not enabled, this will return `nil` - but also no 
error. It is expected
+// that the caller will handle this situation appropriately.
+func (inf *APIInfo) CreateInfluxClient() (c *influx.Client, e error) {
+       if !inf.Config.InfluxEnabled {
+               return
+       }
+
+       var fqdn string
+       var TCPPort uint
+       var HTTPSPort sql.NullInt64 // this is the only one that's optional
+
+       row := inf.Tx.Tx.QueryRow(influxServersQuery)
+       if e = row.Scan(&fqdn, &TCPPort, &HTTPSPort); e != nil {
+               e = fmt.Errorf("Failed to create influx client: %v", e)
+               return
+       }
+
+       useSSL := inf.Config.ConfigInflux != nil && 
*inf.Config.ConfigInflux.Secure
+       host := "http%s://%s"
+       if useSSL {
+               if !HTTPSPort.Valid {
+                       log.Warnf("INFLUXDB Server %s has no secure ports, 
assuming default of 8086!", fqdn)
+                       HTTPSPort = sql.NullInt64{8086, true}
+               }
+               host = fmt.Sprintf(host, "s", fqdn)
+       } else {
+               host = fmt.Sprintf(host, "", fqdn)
+       }
+
+       if useSSL {
 
 Review comment:
   yeah, I just thought it might get ugly. But I guess the proper solution to 
that is to break the logic into smaller `func`s, not checking the same 
condition twice.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to