Browse Source

[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>
pull/5937/head
李国忠 5 years ago committed by Simon Pasquier
parent
commit
d89e783217
  1. 3
      documentation/examples/custom-sd/adapter/adapter.go
  2. 57
      documentation/examples/custom-sd/adapter/adapter_test.go

3
documentation/examples/custom-sd/adapter/adapter.go

@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"reflect"
"sort"
"github.com/go-kit/kit/log"
"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))
}
}
sort.Strings(newTargets)
for name, value := range group.Labels {
newLabels[string(name)] = string(value)
}

57
documentation/examples/custom-sd/adapter/adapter_test.go

@ -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 {

Loading…
Cancel
Save