Skip to content

Commit f0d43ca

Browse files
authored
Merge pull request #213 from StackVista/STAC-23146
[STAC-23146] Expose TCP connections and protocol metrics with OTEL
2 parents c055030 + 8dd3f9b commit f0d43ca

28 files changed

Lines changed: 2970 additions & 710 deletions

checks/net.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type ConnectionsCheck struct {
5959

6060
// Use this as the network relation cache to calculate rate metrics and drop short-lived network relations
6161
cache *NetworkRelationCache
62+
63+
podCorrelation *podCorrelationInfo
6264
}
6365

6466
// Name returns the name of the ConnectionsCheck.
@@ -146,6 +148,21 @@ func (c *ConnectionsCheck) Run(cfg *config.AgentConfig, groupID int32, currentTi
146148
protocolMap[k] = config.PostgresProtocolName
147149
}
148150

151+
log.Debugf("Protocol map: %v", protocolMap)
152+
log.Debugf("collected %d connection data", len(connectionStats))
153+
for key, metrics := range connectionStats {
154+
log.Debugf("connection data for %s", key)
155+
for _, metric := range metrics {
156+
log.Debugf("\t%v", metric)
157+
}
158+
}
159+
// Here we have all we need to export OTEL metrics
160+
// We cannot filter short-lived connections because we need them for the security use case.
161+
if c.podCorrelation != nil {
162+
c.podCorrelation.processConnections(conns.Conns, connectionStats)
163+
// In the future we could return here and disable all the rest of the logic, also the process Check
164+
}
165+
149166
httpObservations := aggregateHTTPTraceObservations(conns.HTTPObservations)
150167

151168
dnsMap := map[string][]dns.Hostname{}
@@ -160,15 +177,6 @@ func (c *ConnectionsCheck) Run(cfg *config.AgentConfig, groupID int32, currentTi
160177
containerToPod = c.podsCache.GetContainerToPodMap(context.TODO())
161178
}
162179

163-
log.Debugf("Protocol map: %v", protocolMap)
164-
log.Debugf("collected %d connection data", len(connectionStats))
165-
for key, metrics := range connectionStats {
166-
log.Debugf("connection data for %s", key)
167-
for _, metric := range metrics {
168-
log.Debugf("\t%v", metric)
169-
}
170-
}
171-
172180
formattedConnections, connsPods := c.formatConnections(cfg, conns.Conns, connectionStats, httpObservations, containerToPod, protocolMap)
173181
c.prevCheckTime = currentTime
174182

checks/net_linux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, _ *model.SystemInfo) er
3333
return fmt.Errorf("failed to create network tracer: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err)
3434
}
3535

36+
if cfg.NetworkTracer.PodCorrelation.Enabled {
37+
cfg.NetworkTracer.PodCorrelation.ObserverLogLevel = cfg.LogLevel
38+
c.podCorrelation, err = newPodCorrelationInfo(&cfg.NetworkTracer.PodCorrelation)
39+
if err != nil {
40+
return err
41+
}
42+
}
43+
3644
c.podsCache = pods.MakeCachedPods(60 * time.Second)
3745
c.localTracer = t
3846

0 commit comments

Comments
 (0)