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

Use k8s.pod.ip to record resource IP instead of just ip #183

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions processor/k8sprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

const (
sourceFormatJaeger string = "jaeger"
ipLabelName string = "ip"
k8sIPLabelName string = "k8s.pod.ip"
clientIPLabelName string = "ip"
)

type kubernetesprocessor struct {
Expand Down Expand Up @@ -92,15 +93,15 @@ func (kp *kubernetesprocessor) ConsumeTraceData(ctx context.Context, td consumer
// check if the application, a collector/agent or a prior processor has already
// annotated the batch with IP.
if td.Resource != nil {
podIP = td.Resource.Labels[ipLabelName]
podIP = kp.k8sIPFromAttributes(td.Resource.Labels)
}

// Jaeger client libs tag the process with the process/resource IP and
// jaeger to OC translator maps jaeger process to OC node.
// TODO: Should jaeger translator map jaeger process to OC resource instead?
if podIP == "" && td.SourceFormat == sourceFormatJaeger {
if td.Node != nil {
podIP = td.Node.Attributes[ipLabelName]
podIP = kp.k8sIPFromAttributes(td.Node.Attributes)
}
}

Expand All @@ -118,7 +119,7 @@ func (kp *kubernetesprocessor) ConsumeTraceData(ctx context.Context, td consumer
if td.Resource.Labels == nil {
td.Resource.Labels = map[string]string{}
}
td.Resource.Labels[ipLabelName] = podIP
td.Resource.Labels[k8sIPLabelName] = podIP
}

// Don't invoke any k8s client functionality in passthrough mode.
Expand Down Expand Up @@ -154,3 +155,11 @@ func (kp *kubernetesprocessor) getAttributesForPodIP(ip string) map[string]strin
}
return pod.Attributes
}

func (kp *kubernetesprocessor) k8sIPFromAttributes(attrs map[string]string) string {
ip := attrs[k8sIPLabelName]
if ip == "" {
ip = attrs[clientIPLabelName]
}
return ip
}
6 changes: 3 additions & 3 deletions processor/k8sprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestIPDetection(t *testing.T) {

require.Len(t, next.data, 1)
require.NotNil(t, next.data[0].Resource)
assert.Equal(t, next.data[0].Resource.Labels["ip"], "1.1.1.1")
assert.Equal(t, next.data[0].Resource.Labels["k8s.pod.ip"], "1.1.1.1")
}

func TestNoIP(t *testing.T) {
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestJaegerIP(t *testing.T) {
require.NoError(t, err)
require.Len(t, next.data, 2)
assert.NotNil(t, next.data[1].Resource)
assert.Equal(t, next.data[1].Resource.Labels["ip"], "1.1.1.1")
assert.Equal(t, next.data[1].Resource.Labels["k8s.pod.ip"], "1.1.1.1")
}

func TestAddLabels(t *testing.T) {
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestAddLabels(t *testing.T) {
require.Len(t, next.data, i+1)
td := next.data[i]
require.NotNil(t, td.Resource)
assert.Equal(t, td.Resource.Labels["ip"], ip)
assert.Equal(t, td.Resource.Labels["k8s.pod.ip"], ip)
for k, v := range attrs {
vv, ok := td.Resource.Labels[k]
assert.True(t, ok)
Expand Down