mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 05:47:27 -08:00
[bugfix] custom SD: when ip out of order, reflect.deepEqual can not correctly identify whether there is a change (#5856)
* [bugfix] custom SD: when ip out of order, reflect.deepEqual can not correctly identify whether there is a change Signed-off-by: fuling <fuling.lgz@alibaba-inc.com> * [format] makefile:Makefile.common:116: common-style Signed-off-by: fuling <fuling.lgz@alibaba-inc.com> * [bugfix] custom sd: simonpasquier comment,It would be simpler to sort the targets alphabetically and keep reflect.DeepEqual. Signed-off-by: fuling <fuling.lgz@alibaba-inc.com> * [bugfix]custom SD:fix sort Signed-off-by: fuling <fuling.lgz@alibaba-inc.com> * [bugfix] custom SD : adapter.go need an empty line after "sort" Signed-off-by: fuling <fuling.lgz@alibaba-inc.com> * [bugfix]custom SD:test sign-off Signed-off-by: fuling <fuling.lgz@alibaba-inc.com> * [bugfix]custom SD: fix adaper_test.go Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>
This commit is contained in:
parent
f0bb8129c3
commit
d89e783217
|
@ -22,6 +22,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
"github.com/go-kit/kit/log/level"
|
"github.com/go-kit/kit/log/level"
|
||||||
|
@ -76,7 +77,7 @@ func generateTargetGroups(allTargetGroups map[string][]*targetgroup.Group) map[s
|
||||||
newTargets = append(newTargets, string(target))
|
newTargets = append(newTargets, string(target))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort.Strings(newTargets)
|
||||||
for name, value := range group.Labels {
|
for name, value := range group.Labels {
|
||||||
newLabels[string(name)] = string(value)
|
newLabels[string(name)] = string(value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,63 @@ func TestGenerateTargetGroups(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Disordered Ips in Alibaba's application management system",
|
||||||
|
targetGroup: map[string][]*targetgroup.Group{
|
||||||
|
"cart": {
|
||||||
|
{
|
||||||
|
Source: "alibaba",
|
||||||
|
Targets: []model.LabelSet{
|
||||||
|
{
|
||||||
|
model.AddressLabel: "192.168.1.55",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model.AddressLabel: "192.168.1.44",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Labels: model.LabelSet{
|
||||||
|
model.LabelName("__meta_test_label"): model.LabelValue("label_test_1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"buy": {
|
||||||
|
{
|
||||||
|
Source: "alibaba",
|
||||||
|
Targets: []model.LabelSet{
|
||||||
|
{
|
||||||
|
model.AddressLabel: "192.168.1.22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model.AddressLabel: "192.168.1.33",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Labels: model.LabelSet{
|
||||||
|
model.LabelName("__meta_test_label"): model.LabelValue("label_test_1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCustomSD: map[string]*customSD{
|
||||||
|
"buy:alibaba:21c0d97a1e27e6fe": {
|
||||||
|
Targets: []string{
|
||||||
|
"192.168.1.22",
|
||||||
|
"192.168.1.33",
|
||||||
|
},
|
||||||
|
Labels: map[string]string{
|
||||||
|
"__meta_test_label": "label_test_1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"cart:alibaba:1112e97a13b159fa": {
|
||||||
|
Targets: []string{
|
||||||
|
"192.168.1.44",
|
||||||
|
"192.168.1.55",
|
||||||
|
},
|
||||||
|
Labels: map[string]string{
|
||||||
|
"__meta_test_label": "label_test_1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|
Loading…
Reference in a new issue