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

Metric optimizations #140

Merged
merged 3 commits into from
Nov 14, 2024
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
15 changes: 15 additions & 0 deletions common/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (f connectionFilter) WhitelistPrefix(p netaddr.IPPrefix) {
}

func (f connectionFilter) ShouldBeSkipped(dst, actualDst netaddr.IP) bool {
if dst.IsLinkLocalUnicast() {
return true
}
if IsIpPrivate(dst) || dst.IsLoopback() {
return false
}
Expand Down Expand Up @@ -206,3 +209,15 @@ func NewDestinationKey(dst, actualDst netaddr.IPPort, fqdn string) DestinationKe
actualDestination: HostPortFromIPPort(actualDst),
}
}

var ec2NodeRegex = regexp.MustCompile(`ip-\d+-\d+-\d+-\d+\.ec2`)
var externalDomainWithSuffix = regexp.MustCompile(`(.+\.(com|net|org|io))\..+`)

func NormalizeFQDN(fqdn string, requestType string) string {
if requestType == "TypePTR" {
return "IP.in-addr.arpa"
}
fqdn = ec2NodeRegex.ReplaceAllLiteralString(fqdn, "IP.ec2")
fqdn = externalDomainWithSuffix.ReplaceAllString(fqdn, "$1.search_path_suffix")
return fqdn
}
15 changes: 15 additions & 0 deletions common/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ func TestDestinationKey(t *testing.T) {
NewDestinationKey(d, ad, "bucket.s3.amazonaws.com.default.svc.cluster.local").String(),
)
}

func TestNormalizeFQDN(t *testing.T) {
assert.Equal(t, "IP.in-addr.arpa", NormalizeFQDN("4.3.2.1.in-addr.arpa", "TypePTR"))
assert.Equal(t, "coroot.com", NormalizeFQDN("coroot.com", "TypeA"))
assert.Equal(t, "IP.ec2.internal", NormalizeFQDN("ip-172-1-2-3.ec2.internal", "TypeA"))

assert.Equal(t, "example.com", NormalizeFQDN("example.com", "TypeA"))
assert.Equal(t, "example.com.search_path_suffix", NormalizeFQDN("example.com.cluster.local", "TypeA"))
assert.Equal(t, "example.com.search_path_suffix", NormalizeFQDN("example.com.svc.cluster.local", "TypeA"))
assert.Equal(t, "example.com.search_path_suffix", NormalizeFQDN("example.com.svc.default.cluster.local", "TypeA"))

assert.Equal(t, "example.net.search_path_suffix", NormalizeFQDN("example.net.svc.default.cluster.local", "TypeA"))
assert.Equal(t, "example.org.search_path_suffix", NormalizeFQDN("example.org.svc.default.cluster.local", "TypeA"))
assert.Equal(t, "example.io.search_path_suffix", NormalizeFQDN("example.io.svc.default.cluster.local", "TypeA"))
}
9 changes: 9 additions & 0 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,15 @@ func (c *Container) onDNSRequest(r *l7.RequestData) map[netaddr.IP]string {
if t == "" {
return nil
}
fqdn = common.NormalizeFQDN(fqdn, t)

// To reduce the number of metrics, we ignore AAAA requests with empty results,
// as they are typically performed simultaneously with A requests and do not add
// any additional latency to the application.
if t == "TypeAAAA" && r.Status == 0 && len(ips) == 0 {
return nil
}

if c.dnsStats.Requests == nil {
dnsReq := L7Requests[l7.ProtocolDNS]
c.dnsStats.Requests = prometheus.NewCounterVec(
Expand Down
14 changes: 13 additions & 1 deletion ebpftracer/l7/l7.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,19 @@ func (s Status) String() string {
}

func (s Status) Http() string {
return strconv.Itoa(int(s))
switch {
case s >= 100 && s < 200:
return "1xx"
case s >= 200 && s < 300:
return "2xx"
case s >= 300 && s < 400:
return "3xx"
case s >= 400 && s < 500:
return "4xx"
case s >= 500 && s < 600:
return "5xx"
}
return "unknown"
}

func (s Status) DNS() string {
Expand Down