Skip to content

Commit

Permalink
search for k8s metadata using src_ip when no containerid found (#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Daxin Wang <daxinwang@harmonycloud.cn>
  • Loading branch information
dxsup authored Jun 1, 2022
1 parent 8d2fec6 commit 1213fab
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions collector/consumer/processor/k8sprocessor/kubernetes_processor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package k8sprocessor

import (
"strconv"

"github.com/Kindling-project/kindling/collector/component"
"github.com/Kindling-project/kindling/collector/consumer"
"github.com/Kindling-project/kindling/collector/consumer/processor"
Expand All @@ -9,7 +11,6 @@ import (
"github.com/Kindling-project/kindling/collector/model/constlabels"
"github.com/Kindling-project/kindling/collector/model/constnames"
"go.uber.org/zap"
"strconv"
)

const (
Expand Down Expand Up @@ -85,15 +86,36 @@ func (p *K8sMetadataProcessor) processTcpMetric(dataGroup *model.DataGroup) {
func (p *K8sMetadataProcessor) addK8sMetaDataForClientLabel(labelMap *model.AttributeMap) {
// add metadata for src
containerId := labelMap.GetStringValue(constlabels.ContainerId)
labelMap.UpdateAddStringValue(constlabels.SrcContainerId, containerId)
resInfo, ok := p.metadata.GetByContainerId(containerId)
if ok {
addContainerMetaInfoLabelSRC(labelMap, resInfo)
if containerId != "" {
labelMap.UpdateAddStringValue(constlabels.SrcContainerId, containerId)
resInfo, ok := p.metadata.GetByContainerId(containerId)
if ok {
addContainerMetaInfoLabelSRC(labelMap, resInfo)
} else {
labelMap.UpdateAddStringValue(constlabels.SrcNodeIp, p.localNodeIp)
labelMap.UpdateAddStringValue(constlabels.SrcNode, p.localNodeName)
labelMap.UpdateAddStringValue(constlabels.SrcNamespace, constlabels.InternalClusterNamespace)
}
} else {
labelMap.UpdateAddStringValue(constlabels.SrcNodeIp, p.localNodeIp)
labelMap.UpdateAddStringValue(constlabels.SrcNode, p.localNodeName)
labelMap.UpdateAddStringValue(constlabels.SrcNamespace, constlabels.InternalClusterNamespace)
srcIp := labelMap.GetStringValue(constlabels.SrcIp)
if srcIp == loopbackIp {
labelMap.UpdateAddStringValue(constlabels.SrcNodeIp, p.localNodeIp)
labelMap.UpdateAddStringValue(constlabels.SrcNode, p.localNodeName)
}
podInfo, ok := p.metadata.GetPodByIp(srcIp)
if ok {
addPodMetaInfoLabelSRC(labelMap, podInfo)
} else {
if nodeName, ok := p.metadata.GetNodeNameByIp(srcIp); ok {
labelMap.UpdateAddStringValue(constlabels.SrcNodeIp, srcIp)
labelMap.UpdateAddStringValue(constlabels.SrcNode, nodeName)
labelMap.UpdateAddStringValue(constlabels.SrcNamespace, constlabels.InternalClusterNamespace)
} else {
labelMap.UpdateAddStringValue(constlabels.SrcNamespace, constlabels.ExternalClusterNamespace)
}
}
}

// add metadata for dst
dstIp := labelMap.GetStringValue(constlabels.DstIp)
if dstIp == loopbackIp {
Expand Down

0 comments on commit 1213fab

Please sign in to comment.