More metric URL clean up
@@ -19,7 +19,6 @@ import (
"context"
"fmt"
"math"
- "net/url"
"strconv"
"strings"
"time"
@@ -275,7 +274,7 @@ func (r *ReconcileTrial) Reconcile(request reconcile.Request) (reconcile.Result,
continue
}
- urls, verr := r.findMetricTargets(trial, &m)
+ urls, verr := findMetricTargets(r, &m)
for _, u := range urls {
if value, stddev, retryAfter, err := captureMetric(&m, u, trial); err != nil {
verr = err
@@ -447,7 +446,7 @@ func checkAssignments(trial *redskyv1alpha1.Trial, experiment *redskyv1alpha1.Ex
return nil
}
-func (r *ReconcileTrial) findMetricTargets(trial *redskyv1alpha1.Trial, m *redskyv1alpha1.Metric) ([]string, error) {
+func findMetricTargets(r client.Reader, m *redskyv1alpha1.Metric) ([]string, error) {
// Local metrics don't need to resolve service URLs
if m.Type == redskyv1alpha1.MetricLocal || m.Type == "" {
return []string{""}, nil
@@ -468,9 +467,10 @@ func (r *ReconcileTrial) findMetricTargets(trial *redskyv1alpha1.Trial, m *redsk
// Construct a URL for each service (use IP literals instead of host names to avoid DNS lookups)
var urls []string
for _, s := range list.Items {
+ scheme := "http"
host := s.Spec.ClusterIP
-
port := m.Port.IntValue()
+
if port < 1 {
for _, sp := range s.Spec.Ports {
if m.Port.StrVal == sp.Name || len(s.Spec.Ports) == 1 {
@@ -479,14 +479,11 @@ func (r *ReconcileTrial) findMetricTargets(trial *redskyv1alpha1.Trial, m *redsk
}
}
- // TODO TLS support
- // TODO Port < 1
- // TODO Build this URL properly
- thisIsBad, err := url.Parse(fmt.Sprintf("http://%s:%d%s", host, port, m.Path))
- if err != nil {
- return nil, err
+ if port < 1 {
+ return nil, fmt.Errorf("metric '%s' has unresolvable port: %s", m.Name, m.Port)
}
- urls = append(urls, thisIsBad.String())
+
+ urls = append(urls, fmt.Sprintf("%s://%s:%d%s", scheme, host, port, m.Path))
}
if len(urls) == 0 {
