mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-10 15:14:09 +00:00
lib/promscrape/discovery/kubernetes: do not drop pod meta-labels even if the corresponding node objects are missing
This reflects the logic used in Prometheus. See https://github.com/prometheus/prometheus/pull/10080
This commit is contained in:
parent
155cd5d6e1
commit
aa82987d70
3 changed files with 13 additions and 41 deletions
|
@ -132,11 +132,7 @@ func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []map[string]string {
|
||||||
m := map[string]string{
|
m := map[string]string{
|
||||||
"__address__": addr,
|
"__address__": addr,
|
||||||
}
|
}
|
||||||
if !p.appendCommonLabels(m, gw) {
|
p.appendCommonLabels(m, gw)
|
||||||
// The corresponding node is filtered out with label or field selectors.
|
|
||||||
// Do not generate endpoint labels in this case.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
p.appendContainerLabels(m, c, &cp)
|
p.appendContainerLabels(m, c, &cp)
|
||||||
if svc != nil {
|
if svc != nil {
|
||||||
svc.appendCommonLabels(m)
|
svc.appendCommonLabels(m)
|
||||||
|
@ -158,10 +154,8 @@ func appendEndpointLabelsForAddresses(ms []map[string]string, gw *groupWatcher,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m := getEndpointLabelsForAddressAndPort(gw, podPortsSeen, eps, ea, epp, p, svc, ready)
|
m := getEndpointLabelsForAddressAndPort(gw, podPortsSeen, eps, ea, epp, p, svc, ready)
|
||||||
if m != nil {
|
|
||||||
ms = append(ms, m)
|
ms = append(ms, m)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ms
|
return ms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,11 +170,7 @@ func getEndpointLabelsForAddressAndPort(gw *groupWatcher, podPortsSeen map[*Pod]
|
||||||
if ea.TargetRef.Kind != "Pod" || p == nil {
|
if ea.TargetRef.Kind != "Pod" || p == nil {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
if !p.appendCommonLabels(m, gw) {
|
p.appendCommonLabels(m, gw)
|
||||||
// The corresponding node is filtered out with label or field selectors.
|
|
||||||
// Do not generate endpoint labels in this case.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// always add pod targetRef, even if epp port doesn't match container port
|
// always add pod targetRef, even if epp port doesn't match container port
|
||||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2134
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2134
|
||||||
if _, ok := podPortsSeen[p]; !ok {
|
if _, ok := podPortsSeen[p]; !ok {
|
||||||
|
|
|
@ -52,10 +52,8 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []map[string]string
|
||||||
for _, epp := range eps.Ports {
|
for _, epp := range eps.Ports {
|
||||||
for _, addr := range ess.Addresses {
|
for _, addr := range ess.Addresses {
|
||||||
m := getEndpointSliceLabelsForAddressAndPort(gw, podPortsSeen, addr, eps, ess, epp, p, svc)
|
m := getEndpointSliceLabelsForAddressAndPort(gw, podPortsSeen, addr, eps, ess, epp, p, svc)
|
||||||
if m != nil {
|
|
||||||
ms = append(ms, m)
|
ms = append(ms, m)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,11 +77,7 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []map[string]string
|
||||||
m := map[string]string{
|
m := map[string]string{
|
||||||
"__address__": addr,
|
"__address__": addr,
|
||||||
}
|
}
|
||||||
if !p.appendCommonLabels(m, gw) {
|
p.appendCommonLabels(m, gw)
|
||||||
// The corresponding node is filtered out with label or field selectors.
|
|
||||||
// Do not generate endpointslice labels in this case.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
p.appendContainerLabels(m, c, &cp)
|
p.appendContainerLabels(m, c, &cp)
|
||||||
if svc != nil {
|
if svc != nil {
|
||||||
svc.appendCommonLabels(m)
|
svc.appendCommonLabels(m)
|
||||||
|
@ -116,11 +110,7 @@ func getEndpointSliceLabelsForAddressAndPort(gw *groupWatcher, podPortsSeen map[
|
||||||
if _, ok := podPortsSeen[p]; !ok {
|
if _, ok := podPortsSeen[p]; !ok {
|
||||||
podPortsSeen[p] = []int{}
|
podPortsSeen[p] = []int{}
|
||||||
}
|
}
|
||||||
if !p.appendCommonLabels(m, gw) {
|
p.appendCommonLabels(m, gw)
|
||||||
// The corresponding node is filtered out with label or field selectors.
|
|
||||||
// Do not generate endpointslice labels in this case.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for _, c := range p.Spec.Containers {
|
for _, c := range p.Spec.Containers {
|
||||||
for _, cp := range c.Ports {
|
for _, cp := range c.Ports {
|
||||||
if cp.ContainerPort == epp.Port {
|
if cp.ContainerPort == epp.Port {
|
||||||
|
|
|
@ -129,11 +129,7 @@ func appendPodLabelsInternal(ms []map[string]string, gw *groupWatcher, p *Pod, c
|
||||||
"__address__": addr,
|
"__address__": addr,
|
||||||
"__meta_kubernetes_pod_container_init": isInit,
|
"__meta_kubernetes_pod_container_init": isInit,
|
||||||
}
|
}
|
||||||
if !p.appendCommonLabels(m, gw) {
|
p.appendCommonLabels(m, gw)
|
||||||
// The corresponding node is filtered out with label or field selectors.
|
|
||||||
// Do not generate pod labels in this case.
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
p.appendContainerLabels(m, c, cp)
|
p.appendContainerLabels(m, c, cp)
|
||||||
return append(ms, m)
|
return append(ms, m)
|
||||||
}
|
}
|
||||||
|
@ -147,18 +143,15 @@ func (p *Pod) appendContainerLabels(m map[string]string, c Container, cp *Contai
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pod) appendCommonLabels(m map[string]string, gw *groupWatcher) bool {
|
func (p *Pod) appendCommonLabels(m map[string]string, gw *groupWatcher) {
|
||||||
if gw.attachNodeMetadata {
|
if gw.attachNodeMetadata {
|
||||||
o := gw.getObjectByRoleLocked("node", p.Metadata.Namespace, p.Spec.NodeName)
|
|
||||||
if o == nil {
|
|
||||||
// The node associated with the pod is filtered out with label or field selectors,
|
|
||||||
// so do not generate labels for the pod.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
n := o.(*Node)
|
|
||||||
m["__meta_kubernetes_node_name"] = p.Spec.NodeName
|
m["__meta_kubernetes_node_name"] = p.Spec.NodeName
|
||||||
|
o := gw.getObjectByRoleLocked("node", p.Metadata.Namespace, p.Spec.NodeName)
|
||||||
|
if o != nil {
|
||||||
|
n := o.(*Node)
|
||||||
n.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_node", m)
|
n.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_node", m)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
m["__meta_kubernetes_pod_name"] = p.Metadata.Name
|
m["__meta_kubernetes_pod_name"] = p.Metadata.Name
|
||||||
m["__meta_kubernetes_pod_ip"] = p.Status.PodIP
|
m["__meta_kubernetes_pod_ip"] = p.Status.PodIP
|
||||||
m["__meta_kubernetes_pod_ready"] = getPodReadyStatus(p.Status.Conditions)
|
m["__meta_kubernetes_pod_ready"] = getPodReadyStatus(p.Status.Conditions)
|
||||||
|
@ -176,7 +169,6 @@ func (p *Pod) appendCommonLabels(m map[string]string, gw *groupWatcher) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_pod", m)
|
p.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_pod", m)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPodController(ors []OwnerReference) *OwnerReference {
|
func getPodController(ors []OwnerReference) *OwnerReference {
|
||||||
|
|
Loading…
Reference in a new issue