Skip to content

Commit d6dae5c

Browse files
authored
Merge pull request #306 from coroot/cap_fqdn_per_container_cardinality
cap unique FQDN labels per container in `container_dns_requests_total`
2 parents 336a3d9 + 33c46ec commit d6dae5c

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

containers/container.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ type Container struct {
130130
activeConnections map[ConnectionKey]*ActiveConnection
131131
connectionsByPidFd map[PidFd]*ActiveConnection
132132

133-
l7Stats L7Stats
134-
dnsStats *L7Metrics
133+
l7Stats L7Stats
134+
dnsStats *L7Metrics
135+
seenFQDNs map[string]struct{}
135136

136137
gpuStats map[string]*GpuUsage
137138

@@ -187,6 +188,7 @@ func NewContainer(id ContainerID, cg *cgroup.Cgroup, md *ContainerMetadata, pid
187188
connectionsByPidFd: map[PidFd]*ActiveConnection{},
188189
l7Stats: L7Stats{},
189190
dnsStats: &L7Metrics{},
191+
seenFQDNs: map[string]struct{}{},
190192

191193
gpuStats: map[string]*GpuUsage{},
192194

@@ -677,6 +679,8 @@ func (c *Container) updateConnectionTrafficStats(ac *ActiveConnection, sent, rec
677679
ac.BytesReceived = received
678680
}
679681

682+
const fqdnOverflowLabel = "~other"
683+
680684
func (c *Container) onDNSRequest(r *l7.RequestData) map[netaddr.IP]*common.Domain {
681685
status := r.Status.DNS()
682686
if status == "" {
@@ -702,7 +706,17 @@ func (c *Container) onDNSRequest(r *l7.RequestData) map[netaddr.IP]*common.Domai
702706
[]string{"request_type", "domain", "status"},
703707
)
704708
}
705-
if m, _ := c.dnsStats.Requests.GetMetricWithLabelValues(t, fqdn, status); m != nil {
709+
metricFQDN := fqdn
710+
if fqdn != "" {
711+
if _, ok := c.seenFQDNs[fqdn]; !ok {
712+
if len(c.seenFQDNs) < *flags.MaxFQDNsPerContainer {
713+
c.seenFQDNs[fqdn] = struct{}{}
714+
} else {
715+
metricFQDN = fqdnOverflowLabel
716+
}
717+
}
718+
}
719+
if m, _ := c.dnsStats.Requests.GetMetricWithLabelValues(t, metricFQDN, status); m != nil {
706720
m.Inc()
707721
}
708722
if r.Duration != 0 {

flags/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
LogPerSecond = kingpin.Flag("log-per-second", "The number of logs per second").Default("10.0").Envar("LOG_PER_SECOND").Float64()
4444
LogBurst = kingpin.Flag("log-burst", "The maximum number of tokens that can be consumed in a single call to allow").Default("100").Envar("LOG_BURST").Int()
4545
LogPatternsPerContainer = kingpin.Flag("log-patterns-per-container", "Max unique log patterns per container per level").Default("256").Envar("LOG_PATTERNS_PER_CONTAINER").Int()
46+
MaxFQDNsPerContainer = kingpin.Flag("max-fqdns-per-container", "Max unique FQDN values per container, extras are bucketed under '~other'").Default("50").Envar("MAX_FQDNS_PER_CONTAINER").Int()
4647

4748
MaxLabelLength = kingpin.Flag("max-label-length", "Maximum length of a metric label value").Default("4096").Envar("MAX_LABEL_LENGTH").Int()
4849

0 commit comments

Comments
 (0)