mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Fix Kubernetes endpoints SD for empty subsets (#3660)
* Fix Kubernetes endpoints SD for empty subsets When an endpoints object has no associated pods (replica scaled to zero for instance), the endpoints SD should return a target group with no targets so that the SD manager propagates this information to the scrape manager. Fixes #3659 * Don't send nil target groups from the Kubernetes SD This is to be consistent with the endpoints SD part.
This commit is contained in:
parent
47538cf6ce
commit
bde64cf5a6
|
@ -185,10 +185,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group {
|
func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group {
|
||||||
if len(eps.Subsets) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
tg := &targetgroup.Group{
|
tg := &targetgroup.Group{
|
||||||
Source: endpointsSource(eps),
|
Source: endpointsSource(eps),
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,3 +339,32 @@ func TestEndpointsDiscoveryUpdate(t *testing.T) {
|
||||||
},
|
},
|
||||||
}.Run(t)
|
}.Run(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEndpointsDiscoveryEmptySubsets(t *testing.T) {
|
||||||
|
n, _, eps, _ := makeTestEndpointsDiscovery()
|
||||||
|
eps.GetStore().Add(makeEndpoints())
|
||||||
|
|
||||||
|
k8sDiscoveryTest{
|
||||||
|
discovery: n,
|
||||||
|
afterStart: func() {
|
||||||
|
go func() {
|
||||||
|
eps.Update(&v1.Endpoints{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "testendpoints",
|
||||||
|
Namespace: "default",
|
||||||
|
},
|
||||||
|
Subsets: []v1.EndpointSubset{},
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
},
|
||||||
|
expectedRes: []*targetgroup.Group{
|
||||||
|
{
|
||||||
|
Labels: model.LabelSet{
|
||||||
|
"__meta_kubernetes_namespace": "default",
|
||||||
|
"__meta_kubernetes_endpoints_name": "testendpoints",
|
||||||
|
},
|
||||||
|
Source: "endpoints/default/testendpoints",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}.Run(t)
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,9 @@ func (n *Node) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
||||||
|
|
||||||
// Send target groups for service updates.
|
// Send target groups for service updates.
|
||||||
send := func(tg *targetgroup.Group) {
|
send := func(tg *targetgroup.Group) {
|
||||||
|
if tg == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
case ch <- []*targetgroup.Group{tg}:
|
case ch <- []*targetgroup.Group{tg}:
|
||||||
|
|
|
@ -68,6 +68,9 @@ func (p *Pod) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
||||||
|
|
||||||
// Send target groups for pod updates.
|
// Send target groups for pod updates.
|
||||||
send := func(tg *targetgroup.Group) {
|
send := func(tg *targetgroup.Group) {
|
||||||
|
if tg == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
level.Debug(p.logger).Log("msg", "pod update", "tg", fmt.Sprintf("%#v", tg))
|
level.Debug(p.logger).Log("msg", "pod update", "tg", fmt.Sprintf("%#v", tg))
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
Loading…
Reference in a new issue