Browse Source

HTTP SD: Simplify logic of disappeared targetgroups (#9026)

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
pull/9032/head
Julien Pivotto 3 years ago committed by GitHub
parent
commit
553dd07777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      discovery/http/http.go
  2. 56
      discovery/http/http_test.go

6
discovery/http/http.go

@ -186,10 +186,8 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
// Generate empty updates for sources that disappeared.
l := len(targetGroups)
if d.tgLastLength > l {
for i := l; i < d.tgLastLength; i++ {
targetGroups = append(targetGroups, &targetgroup.Group{Source: urlSource(d.url, i)})
}
for i := l; i < d.tgLastLength; i++ {
targetGroups = append(targetGroups, &targetgroup.Group{Source: urlSource(d.url, i)})
}
d.tgLastLength = l

56
discovery/http/http_test.go

@ -197,9 +197,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("1"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
},
{
@ -211,9 +211,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("1"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
{
Targets: []model.LabelSet{
@ -223,9 +223,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("2"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 1),
Source: urlSource(ts.URL, 1),
},
},
},
@ -245,9 +245,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("1"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
{
Targets: []model.LabelSet{
@ -257,9 +257,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("2"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 1),
Source: urlSource(ts.URL, 1),
},
},
{
@ -271,14 +271,14 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("1"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
{
Targets: nil,
Labels: nil,
Source: urlSource(ts.URL+"/http_disappeared.json", 1),
Source: urlSource(ts.URL, 1),
},
},
},
@ -299,9 +299,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("1"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
{
Targets: []model.LabelSet{
@ -311,9 +311,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("2"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 1),
Source: urlSource(ts.URL, 1),
},
{
Targets: []model.LabelSet{
@ -323,9 +323,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("3"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 2),
Source: urlSource(ts.URL, 2),
},
},
{
@ -337,19 +337,19 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("1"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
{
Targets: nil,
Labels: nil,
Source: urlSource(ts.URL+"/http_disappeared.json", 1),
Source: urlSource(ts.URL, 1),
},
{
Targets: nil,
Labels: nil,
Source: urlSource(ts.URL+"/http_disappeared.json", 2),
Source: urlSource(ts.URL, 2),
},
},
{
@ -361,9 +361,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("v"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 0),
Source: urlSource(ts.URL, 0),
},
{
Targets: []model.LabelSet{
@ -373,9 +373,9 @@ func TestSourceDisappeared(t *testing.T) {
},
Labels: model.LabelSet{
model.LabelName("k"): model.LabelValue("vv"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL + "/http_disappeared.json"),
model.LabelName("__meta_url"): model.LabelValue(ts.URL),
},
Source: urlSource(ts.URL+"/http_disappeared.json", 1),
Source: urlSource(ts.URL, 1),
},
},
},
@ -384,7 +384,7 @@ func TestSourceDisappeared(t *testing.T) {
cfg := SDConfig{
HTTPClientConfig: config.DefaultHTTPClientConfig,
URL: ts.URL + "/http_disappeared.json",
URL: ts.URL,
RefreshInterval: model.Duration(1 * time.Second),
}
d, err := NewDiscovery(&cfg, log.NewNopLogger())

Loading…
Cancel
Save