|
|
|
@ -446,19 +446,6 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
|
|
|
|
|
|
|
|
|
|
targets := make([]*Target, 0, len(tg.Targets))
|
|
|
|
|
for i, labels := range tg.Targets {
|
|
|
|
|
addr := string(labels[model.AddressLabel])
|
|
|
|
|
// If no port was provided, infer it based on the used scheme.
|
|
|
|
|
if !strings.Contains(addr, ":") {
|
|
|
|
|
switch cfg.Scheme {
|
|
|
|
|
case "http":
|
|
|
|
|
addr = fmt.Sprintf("%s:80", addr)
|
|
|
|
|
case "https":
|
|
|
|
|
addr = fmt.Sprintf("%s:443", addr)
|
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Errorf("targetsFromGroup: invalid scheme %q", cfg.Scheme))
|
|
|
|
|
}
|
|
|
|
|
labels[model.AddressLabel] = model.LabelValue(addr)
|
|
|
|
|
}
|
|
|
|
|
for k, v := range cfg.Params {
|
|
|
|
|
if len(v) > 0 {
|
|
|
|
|
labels[model.LabelName(model.ParamLabelPrefix+k)] = model.LabelValue(v[0])
|
|
|
|
@ -496,6 +483,19 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
|
|
|
|
|
if labels == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// If no port was provided, infer it based on the used scheme.
|
|
|
|
|
addr := string(labels[model.AddressLabel])
|
|
|
|
|
if !strings.Contains(addr, ":") {
|
|
|
|
|
switch labels[model.SchemeLabel] {
|
|
|
|
|
case "http", "":
|
|
|
|
|
addr = fmt.Sprintf("%s:80", addr)
|
|
|
|
|
case "https":
|
|
|
|
|
addr = fmt.Sprintf("%s:443", addr)
|
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Errorf("targetsFromGroup: invalid scheme %q", cfg.Scheme))
|
|
|
|
|
}
|
|
|
|
|
labels[model.AddressLabel] = model.LabelValue(addr)
|
|
|
|
|
}
|
|
|
|
|
if err = config.CheckTargetAddress(labels[model.AddressLabel]); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|