mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 06:59:40 -08:00
Merge pull request #1204 from prometheus/port-after-relabel
Add in default port after relabelling.
This commit is contained in:
commit
5b7411e80a
|
@ -446,19 +446,6 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
|
||||||
|
|
||||||
targets := make([]*Target, 0, len(tg.Targets))
|
targets := make([]*Target, 0, len(tg.Targets))
|
||||||
for i, labels := range 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 {
|
for k, v := range cfg.Params {
|
||||||
if len(v) > 0 {
|
if len(v) > 0 {
|
||||||
labels[model.LabelName(model.ParamLabelPrefix+k)] = model.LabelValue(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 {
|
if labels == nil {
|
||||||
continue
|
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 {
|
if err = config.CheckTargetAddress(labels[model.AddressLabel]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ func TestTargetManagerConfigUpdate(t *testing.T) {
|
||||||
TargetGroups: []*config.TargetGroup{{
|
TargetGroups: []*config.TargetGroup{{
|
||||||
Targets: []model.LabelSet{
|
Targets: []model.LabelSet{
|
||||||
{model.AddressLabel: "example.org:80"},
|
{model.AddressLabel: "example.org:80"},
|
||||||
{model.AddressLabel: "example.com:80"},
|
{model.AddressLabel: "example.com"},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
RelabelConfigs: []*config.RelabelConfig{
|
RelabelConfigs: []*config.RelabelConfig{
|
||||||
|
@ -223,6 +223,13 @@ func TestTargetManagerConfigUpdate(t *testing.T) {
|
||||||
Replacement: "$1",
|
Replacement: "$1",
|
||||||
Action: config.RelabelReplace,
|
Action: config.RelabelReplace,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// The port number is added after relabeling, so
|
||||||
|
// this relabel rule should have no effect.
|
||||||
|
SourceLabels: model.LabelNames{model.AddressLabel},
|
||||||
|
Regex: config.MustNewRegexp("example.com:80"),
|
||||||
|
Action: config.RelabelDrop,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testJob2 := &config.ScrapeConfig{
|
testJob2 := &config.ScrapeConfig{
|
||||||
|
|
Loading…
Reference in a new issue