-
Notifications
You must be signed in to change notification settings - Fork 0
chore: fix for external domain resolution (#148) #150
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,26 +218,27 @@ func (d *Domain) String() string { | |
|
|
||
| func NewDomain(fqdn string, ips []netaddr.IP) *Domain { | ||
| d := &Domain{FQDN: fqdn, SpecifyIP: true} | ||
| if len(ips) > 1 { | ||
| containsPrivateIPs := false | ||
| for _, ip := range ips { | ||
| if !IsIpExternal(ip) { | ||
| containsPrivateIPs = true | ||
| break | ||
| } | ||
| } | ||
| if !containsPrivateIPs { | ||
| d.SpecifyIP = false | ||
| } | ||
| } | ||
| return d | ||
| } | ||
|
|
||
| func NewDestinationKey(dst, actualDst netaddr.IPPort, domain *Domain, dstWorkload Workload, actualDestWorkload Workload) DestinationKey { | ||
| if IsIpExternal(actualDst.IP()) && domain != nil && !domain.SpecifyIP { | ||
| return DestinationKey{ | ||
| destination: HostPortWithEmptyIP(domain.FQDN, dst.Port()), | ||
| destination: HostPortWithEmptyIP(domain.FQDN, dst.Port()), | ||
| actualDestination: HostPortFromIPPort(actualDst), | ||
| destinationWorkload: Workload{ | ||
| Kind: "external", | ||
| Name: domain.FQDN, | ||
| Namespace: "external", | ||
| }, | ||
| actualDestinationWorkload: Workload{ | ||
| Kind: "external", | ||
| Name: actualDst.IP().String(), | ||
| Namespace: "external", | ||
| }, | ||
| } | ||
| } else if IsIpExternal(actualDst.IP()) && domain != nil && domain.SpecifyIP { | ||
| klog.Infof("ip %q is external, but domain %q specifies IP, using IP as destination", actualDst.IP(), domain.FQDN) | ||
| } | ||
|
Comment on lines
+240
to
242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if IsIpExternal(actualDst.IP()) && domain != nil && !domain.SpecifyIP {
return DestinationKey{
destination: HostPortWithEmptyIP(domain.FQDN, dst.Port()),
actualDestination: HostPortFromIPPort(actualDst),
destinationWorkload: Workload{
Kind: "external",
Name: domain.FQDN,
Namespace: "external",
},
actualDestinationWorkload: Workload{
Kind: "external",
Name: actualDst.IP().String(),
Namespace: "external",
},
}
}
if IsIpExternal(actualDst.IP()) && domain != nil && domain.SpecifyIP {
klog.Infof("ip %q is external, but domain %q specifies IP, using IP as destination", actualDst.IP(), domain.FQDN)
}
return DestinationKey{
destination: HostPortFromIPPort(dst),
actualDestination: HostPortFromIPPort(actualDst),
destinationWorkload: dstWorkload,
actualDestinationWorkload: actualDestWorkload,
} |
||
| return DestinationKey{ | ||
| destination: HostPortFromIPPort(dst), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ func TestDestinationKey(t *testing.T) { | |
| assert.Equal(t, "1.1.1.1:443 (2.2.2.2:443)", NewDestinationKey(d, ad, nil, Workload{}, Workload{}).String()) | ||
|
|
||
| assert.Equal(t, | ||
| "aa.bb.s3.amazonaws.com:443 ()", | ||
| "aa.bb.s3.amazonaws.com:443 (2.2.2.2:443)", | ||
| NewDestinationKey(d, ad, &Domain{FQDN: "aa.bb.s3.amazonaws.com", SpecifyIP: false}, Workload{}, Workload{}).String(), | ||
| ) | ||
| assert.Equal(t, | ||
|
|
@@ -51,7 +51,7 @@ func TestDomain(t *testing.T) { | |
| assert.Equal(t, "Domain(fqdn,true)", NewDomain("fqdn", []netaddr.IP{ | ||
| netaddr.MustParseIP("1.1.1.1"), | ||
| }).String()) | ||
| assert.Equal(t, "Domain(fqdn,false)", NewDomain("fqdn", []netaddr.IP{ | ||
| assert.Equal(t, "Domain(fqdn,true)", NewDomain("fqdn", []netaddr.IP{ | ||
| netaddr.MustParseIP("1.1.1.1"), | ||
| netaddr.MustParseIP("1.1.1.2"), | ||
| }).String()) | ||
|
Comment on lines
+54
to
57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,7 @@ func (m *L7Metrics) observe(status, method string, duration time.Duration) { | |||||||||
|
|
||||||||||
| type L7Stats map[l7.Protocol]map[common.DestinationKey]*L7Metrics // protocol -> dst:actual_dst -> metrics | ||||||||||
|
|
||||||||||
| func (s L7Stats) get(protocol l7.Protocol, key common.DestinationKey, r *l7.RequestData, srcWorkload common.Workload, dstWorkload common.Workload, actualDstWorkload common.Workload, traceId string) *L7Metrics { | ||||||||||
| func (s L7Stats) get(protocol l7.Protocol, key common.DestinationKey, r *l7.RequestData, srcWorkload common.Workload, traceId string) *L7Metrics { | ||||||||||
| if protocol == l7.ProtocolHTTP2 { | ||||||||||
| protocol = l7.ProtocolHTTP | ||||||||||
| } | ||||||||||
|
|
@@ -53,15 +53,15 @@ func (s L7Stats) get(protocol l7.Protocol, key common.DestinationKey, r *l7.Requ | |||||||||
| protoStats[key] = m | ||||||||||
| constLabels := map[string]string{"destination": key.DestinationLabelValue(), | ||||||||||
| "actual_destination": key.ActualDestinationLabelValue(), | ||||||||||
| "destination_workload_kind": dstWorkload.Kind, | ||||||||||
| "destination_workload_name": dstWorkload.Name, | ||||||||||
| "destination_workload_namespace": dstWorkload.Namespace, | ||||||||||
| "destination_workload_kind": key.GetDestinationWorkload().Kind, | ||||||||||
| "destination_workload_name": key.GetDestinationWorkload().Name, | ||||||||||
| "destination_workload_namespace": key.GetDestinationWorkload().Namespace, | ||||||||||
|
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The destination workload name is being retrieved using
Suggested change
|
||||||||||
| "src_workload_kind": srcWorkload.Kind, | ||||||||||
| "src_workload_name": srcWorkload.Name, | ||||||||||
| "src_workload_namespace": srcWorkload.Namespace, | ||||||||||
| "actual_destination_workload_kind": actualDstWorkload.Kind, | ||||||||||
| "actual_destination_workload_name": actualDstWorkload.Name, | ||||||||||
| "actual_destination_workload_namespace": actualDstWorkload.Namespace, | ||||||||||
| "actual_destination_workload_kind": key.GetActualDestinationWorkload().Kind, | ||||||||||
| "actual_destination_workload_name": key.GetActualDestinationWorkload().Name, | ||||||||||
| "actual_destination_workload_namespace": key.GetActualDestinationWorkload().Namespace, | ||||||||||
|
Comment on lines
+62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual destination workload name is being retrieved using
Suggested change
|
||||||||||
| } | ||||||||||
| if traceId != "" { | ||||||||||
| constLabels["trace_id"] = traceId | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ipsparameter is no longer used within theNewDomainfunction. To improve code clarity and prevent potential misuse, it should be removed from the function signature.