Fix hostport not processed in k8sprocessor #219
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
GetDNATTuple
in the conntracker module returned bothDNAT
andSNAT
connections before. This PR fixes this bug. This bug could bring unexpecteddst_ip
anddst_port
labels when we getSNAT
connections from the methodGetDNATTuple
incorrectly.Motivation and Context
What we expect to see for the metric labels of
hostPort
scenario is:dst_ip
is the pod's IP.dst_port
is the container's port that is exposed to the hostport.dst_service
should behostIP:hostPort
which represents how the pod is called.The scenario of containers using hostPort was not considered before, so when a client calls a pod using HostIP:HostPort, the processed data didn't contain the information of the pod. This PR resolves such a problem by recording the
hostPorts
as a new map and looking up the map for the container's metadata.GetDNATTuple
bugThis is one record shown by executing
conntrack -L
.A
.B
.hostPort
of the PodB
.A
.Since
Send.dst
==Reply.src
andSend.dport
==Reply.sport
, we know there is noDNAT
happened. But becauseSend.src
!=Reply.Dst
,SNAT
happened. This record was returned by the methodGetDNATTuple
before, which resulted in incorrect value indnat_ip
anddnat_port
fields with the following piece of codes.Considering that we replace
dst_ip
anddst_port
withdnat_ip
anddnat_port
in the adapters ofotelexporter
, if the fieldsdnat_ip
anddnat_port
are incorrect, the samedst_ip
anddst_port
will be.Until here it looks like the problem is not serious, because if no
DNAT
happened,dnat_ip
should always equal todst_ip
. There is no effect even if we replacedst_ip
with the samednat_ip
. But when it comes tohostPort
, everything changes.When a pod is called via
hostIP:hostPort
, the originaldst_ip
ishostIP
and the originaldst_port
ishostPort
. In this PR, we replacedst_ip
(hostIP) anddst_port
(hostPort) with its pod's IP and container's port. If they are replaced bydnat_ip
anddnat_port
again, the final result will be not expected.