Skip to content

Commit

Permalink
Use k8s.pod.ip to record resource IP instead of just ip (#183)
Browse files Browse the repository at this point in the history
Since the k8s processor prefixes all labels with `k8s.*.`, adding the
same prefix to the IP label. We'll still continue to look for the `ip`
label on resource/node when we can't find the IP by other means but will
only write the IP back to `k8s.pod.ip`.
  • Loading branch information
owais committed Apr 22, 2020
1 parent 0c525ba commit 7370900
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
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

0 comments on commit 7370900

Please sign in to comment.