Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for k8s metadata using src_ip when no containerid found #233

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Comment on lines +100 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Although The k8s information searched may be incorrect when processing data from the loopback device.

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