mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
HTTP SD: Simplify logic of disappeared targetgroups (#9026)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
ddc476d6f9
commit
553dd07777
|
@ -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
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue