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

[usm] reliability, preparation for pool of objects, Protocol.ReleaseStats() #32170

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cmd/system-probe/modules/network_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (nt *networkTracer) Register(httpMux *module.Router) error {
}

utils.WriteAsJSON(w, httpdebugging.HTTP(cs.HTTP, cs.DNS))
nt.tracer.ReleaseUSMStats()
})

httpMux.HandleFunc("/debug/kafka_monitoring", func(w http.ResponseWriter, req *http.Request) {
Expand Down
1 change: 1 addition & 0 deletions pkg/network/nettop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
for _, c := range cs.Conns {
fmt.Println(network.ConnectionSummary(&c, cs.DNS))
}
t.ReleaseUSMStats()
}

stopChan := make(chan struct{})
Expand Down
5 changes: 5 additions & 0 deletions pkg/network/protocols/http/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func (p *protocol) GetStats() *protocols.ProtocolStats {
}
}

// ReleaseStats releases stats objects.
func (p *protocol) ReleaseStats() {
p.statkeeper.ReleaseStats()
}

// IsBuildModeSupported returns always true, as http module is supported by all modes.
func (*protocol) IsBuildModeSupported(buildmode.Type) bool {
return true
Expand Down
14 changes: 11 additions & 3 deletions pkg/network/protocols/http/statkeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type StatKeeper struct {
mux sync.Mutex
stats map[Key]*RequestStats
prevStats map[Key]*RequestStats
incomplete IncompleteBuffer
maxEntries int
quantizer *URLQuantizer
Expand Down Expand Up @@ -87,7 +88,7 @@ func (h *StatKeeper) GetAndResetAllStats() (stats map[Key]*RequestStats) {
}

// Rotate stats
stats = h.stats
h.prevStats = h.stats
h.stats = make(map[Key]*RequestStats)

// Rotate ConnectionAggregator
Expand All @@ -100,8 +101,8 @@ func (h *StatKeeper) GetAndResetAllStats() (stats map[Key]*RequestStats) {
h.connectionAggregator = utils.NewConnectionAggregator()
}()

h.clearEphemeralPorts(previousAggregationState, stats)
return stats
h.clearEphemeralPorts(previousAggregationState, h.prevStats)
return h.prevStats
}

// Close closes the stat keeper.
Expand Down Expand Up @@ -217,3 +218,10 @@ func (h *StatKeeper) clearEphemeralPorts(aggregator *utils.ConnectionAggregator,
stats[key] = aggregation
}
}

// ReleaseStats release reported stats.
func (h *StatKeeper) ReleaseStats() {
h.mux.Lock()
defer h.mux.Unlock()
h.prevStats = nil
}
4 changes: 3 additions & 1 deletion pkg/network/protocols/http/statkeeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func TestProcessHTTPTransactions(t *testing.T) {
cfg.MaxHTTPStatsBuffered = 1000
tel := NewTelemetry("http")
sk := NewStatkeeper(cfg, tel, NewIncompleteBuffer(cfg, tel))

t.Cleanup(func() {
sk.ReleaseStats()
})
srcString := "1.1.1.1"
dstString := "2.2.2.2"
sourceIP := util.AddressFromString(srcString)
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/protocols/http2/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ func (p *Protocol) GetStats() *protocols.ProtocolStats {
}
}

// ReleaseStats releases stats objects.
func (p *Protocol) ReleaseStats() {
}

// IsBuildModeSupported returns always true, as http2 module is supported by all modes.
func (*Protocol) IsBuildModeSupported(buildmode.Type) bool {
return true
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/protocols/kafka/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ func (p *protocol) GetStats() *protocols.ProtocolStats {
}
}

// ReleaseStats releases stats objects.
func (p *protocol) ReleaseStats() {
}

// IsBuildModeSupported returns always true, as kafka module is supported by all modes.
func (*protocol) IsBuildModeSupported(buildmode.Type) bool {
return true
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/protocols/postgres/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ func (p *protocol) GetStats() *protocols.ProtocolStats {
}
}

// ReleaseStats releases stats objects.
func (p *protocol) ReleaseStats() {
}

// IsBuildModeSupported returns always true, as postgres module is supported by all modes.
func (*protocol) IsBuildModeSupported(buildmode.Type) bool {
return true
Expand Down
3 changes: 3 additions & 0 deletions pkg/network/protocols/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type Protocol interface {
// implementation.
GetStats() *ProtocolStats

// ReleaseStats releases stats related objects.
ReleaseStats()

// IsBuildModeSupported return true is the given build mode is supported by this protocol.
IsBuildModeSupported(buildmode.Type) bool
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/protocols/redis/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (p *protocol) GetStats() *protocols.ProtocolStats {
}
}

// ReleaseStats releases stats objects.
func (p *protocol) ReleaseStats() {
}

// IsBuildModeSupported returns always true, as Redis module is supported by all modes.
func (*protocol) IsBuildModeSupported(buildmode.Type) bool {
return true
Expand Down
5 changes: 5 additions & 0 deletions pkg/network/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ func (t *Tracer) GetActiveConnections(clientID string) (*network.Connections, er
return conns, nil
}

// ReleaseUSMStats releases usm stats objects.
func (t *Tracer) ReleaseUSMStats() {
t.usmMonitor.ReleaseStats()
}

// RegisterClient registers a clientID with the tracer
func (t *Tracer) RegisterClient(clientID string) error {
t.state.RegisterClient(clientID)
Expand Down
3 changes: 3 additions & 0 deletions pkg/network/tracer/tracer_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (t *Tracer) GetActiveConnections(_ string) (*network.Connections, error) {
return nil, ebpf.ErrNotImplemented
}

// ReleaseUSMStats is not implemented on this OS for Tracer
func (t *Tracer) ReleaseUSMStats() {}

// GetNetworkID is not implemented on this OS for Tracer
func (t *Tracer) GetNetworkID(_ context.Context) (string, error) {
return "", ebpf.ErrNotImplemented
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/tracer/tracer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ func (t *Tracer) GetActiveConnections(clientID string) (*network.Connections, er
return conns, nil
}

// ReleaseUSMStats is not implemented on this OS for Tracer.
func (t *Tracer) ReleaseUSMStats() {
}

// RegisterClient registers the client
func (t *Tracer) RegisterClient(clientID string) error {
t.state.RegisterClient(clientID)
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/usm/ebpf_gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ func (p *goTLSProgram) GetStats() *protocols.ProtocolStats {
return nil
}

// ReleaseStats is a no-op.
func (p *goTLSProgram) ReleaseStats() {
}

// Stop terminates goTLS main goroutine.
func (p *goTLSProgram) Stop(*manager.Manager) {
close(p.done)
Expand Down
6 changes: 6 additions & 0 deletions pkg/network/usm/ebpf_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ func (e *ebpfProgram) getProtocolStats() map[protocols.ProtocolType]interface{}
return ret
}

func (e *ebpfProgram) releaseStats() {
for _, protocol := range e.enabledProtocols {
protocol.Instance.ReleaseStats()
}
}

// executePerProtocol runs the given callback (`cb`) for every protocol in the given list (`protocolList`).
// If the callback failed, then we call the error callback (`errorCb`). Eventually returning a list of protocols which
// successfully executed the callback.
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/usm/ebpf_ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ func (o *sslProgram) GetStats() *protocols.ProtocolStats {
return nil
}

// ReleaseStats is a no-op.
func (o *sslProgram) ReleaseStats() {
}

const (
// Defined in https://man7.org/linux/man-pages/man5/proc.5.html.
taskCommLen = 16
Expand Down
5 changes: 5 additions & 0 deletions pkg/network/usm/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func (m *Monitor) GetProtocolStats() map[protocols.ProtocolType]interface{} {
return m.ebpfProgram.getProtocolStats()
}

// ReleaseStats release stats related objects.
func (m *Monitor) ReleaseStats() {
m.ebpfProgram.releaseStats()
}

// Stop HTTP monitoring
func (m *Monitor) Stop() {
if m == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/network/usm/monitor_testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (p *protocolMock) Stop(mgr *manager.Manager) {

func (p *protocolMock) DumpMaps(io.Writer, string, *ebpf.Map) {}
func (p *protocolMock) GetStats() *protocols.ProtocolStats { return nil }
func (p *protocolMock) ReleaseStats() {}

// IsBuildModeSupported returns always true, as the mock is supported by all modes.
func (*protocolMock) IsBuildModeSupported(buildmode.Type) bool { return true }
Expand Down
1 change: 1 addition & 0 deletions pkg/network/usm/tests/tracer_classification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func waitForConnectionsWithProtocol(t *testing.T, tr *tracer.Tracer, targetAddr,
if failed {
t.Log(conns)
}
tr.ReleaseUSMStats()
return !failed
}, 5*time.Second, 100*time.Millisecond, "could not find incoming or outgoing connections")
if failed {
Expand Down
Loading