Skip to content

Commit

Permalink
add namespace to server and peer name across namespaces in name resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
esara committed Oct 12, 2024
1 parent 46421d8 commit 56ebd67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
10 changes: 1 addition & 9 deletions pkg/transform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ func (md *metadataDecorator) nodeLoop(in <-chan []request.Span, out chan<- []req
}

func (md *metadataDecorator) do(span *request.Span) {
var podInfo *kube.PodInfo
var ok bool
if podInfo, ok = md.db.OwnerPodInfo(span.Pid.Namespace); ok {
if podInfo, ok := md.db.OwnerPodInfo(span.Pid.Namespace); ok {
md.appendMetadata(span, podInfo)
} else {
// do not leave the service attributes map as nil
Expand All @@ -101,15 +99,9 @@ func (md *metadataDecorator) do(span *request.Span) {
// override the peer and host names from Kubernetes metadata, if found
if hn := md.db.HostNameForIP(span.Host); hn != "" {
span.HostName = hn
if span.OtherNamespace != "" && podInfo != nil && podInfo.Namespace != span.OtherNamespace {
span.HostName = hn + "." + span.OtherNamespace
}
}
if pn := md.db.HostNameForIP(span.Peer); pn != "" {
span.PeerName = pn
if span.OtherNamespace != "" && podInfo != nil && podInfo.Namespace != span.OtherNamespace {
span.PeerName = pn + "." + span.OtherNamespace
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/transform/name_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ func (nr *NameResolver) resolveNames(span *request.Span) {
// in a previous stage (e.g. Kubernetes decorator)
if pn != "" {
span.PeerName = pn
if span.OtherNamespace != "" && span.OtherNamespace != span.ServiceID.Namespace {
span.PeerName = pn + "." + span.OtherNamespace
}
}
if hn != "" {
span.HostName = hn
if span.OtherNamespace != "" && span.OtherNamespace != span.ServiceID.Namespace {
span.HostName = hn + "." + span.OtherNamespace
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/transform/name_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestResolvePodsFromK8s(t *testing.T) {

nr.resolveNames(&clientSpan)

assert.Equal(t, "pod1", clientSpan.PeerName)
assert.Equal(t, "pod1.something", clientSpan.PeerName)
assert.Equal(t, "", clientSpan.ServiceID.Namespace)
assert.Equal(t, "pod2", clientSpan.HostName)
assert.Equal(t, "pod2.something", clientSpan.HostName)
assert.Equal(t, "something", clientSpan.OtherNamespace)

nr.resolveNames(&serverSpan)
Expand Down Expand Up @@ -184,9 +184,9 @@ func TestResolveServiceFromK8s(t *testing.T) {

nr.resolveNames(&clientSpan)

assert.Equal(t, "pod1", clientSpan.PeerName)
assert.Equal(t, "pod1.something", clientSpan.PeerName)
assert.Equal(t, "", clientSpan.ServiceID.Namespace)
assert.Equal(t, "pod2", clientSpan.HostName)
assert.Equal(t, "pod2.something", clientSpan.HostName)
assert.Equal(t, "something", clientSpan.OtherNamespace)

nr.resolveNames(&serverSpan)
Expand Down Expand Up @@ -286,9 +286,9 @@ func TestResolveNodesFromK8s(t *testing.T) {

nr.resolveNames(&clientSpan)

assert.Equal(t, "node1", clientSpan.PeerName)
assert.Equal(t, "node1.something", clientSpan.PeerName)
assert.Equal(t, "", clientSpan.ServiceID.Namespace)
assert.Equal(t, "node2", clientSpan.HostName)
assert.Equal(t, "node2.something", clientSpan.HostName)
assert.Equal(t, "something", clientSpan.OtherNamespace)

nr.resolveNames(&serverSpan)
Expand Down

0 comments on commit 56ebd67

Please sign in to comment.