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

[NPM-3751] retry network ID fetch #33330

Merged
merged 8 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion cmd/system-probe/modules/network_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (nt *networkTracer) Register(httpMux *module.Router) error {
httpMux.HandleFunc("/network_id", utils.WithConcurrencyLimit(utils.DefaultMaxConcurrentRequests, func(w http.ResponseWriter, req *http.Request) {
id, err := nt.tracer.GetNetworkID(req.Context())
if err != nil {
log.Errorf("unable to retrieve network_id: %s", err)
log.Errorf("unable to retrieve network ID: %s", err)
w.WriteHeader(500)
return
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/process/checks/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func (c *ContainerCheck) Run(nextGroupID func() int32, options *RunOptions) (Run
defer c.Unlock()
startTime := time.Now()

if c.networkID == "" {
networkID, err := retryGetNetworkID(c.sysprobeClient)
if err != nil {
log.Warnf("error getting network ID: %s", err)
}
c.networkID = networkID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check that networkID is not empty, if the function retryGetNetworkID is erroring than the value for networkID will be ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up changing the logic around a bit

}

var err error
var containers []*model.Container
var lastRates map[string]*proccontainers.ContainerRateMetrics
Expand Down
8 changes: 8 additions & 0 deletions pkg/process/checks/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ func (c *ConnectionsCheck) ShouldSaveLastRun() bool { return false }
func (c *ConnectionsCheck) Run(nextGroupID func() int32, _ *RunOptions) (RunResult, error) {
start := time.Now()

if c.networkID == "" {
networkID, err := retryGetNetworkID(c.sysprobeClient)
if err != nil {
log.Warnf("error getting network ID: %s", err)
}
c.networkID = networkID
}

conns, err := c.getConnections()
if err != nil {
return nil, err
Expand Down
8 changes: 8 additions & 0 deletions pkg/process/checks/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ func procsToStats(procs map[int32]*procutil.Process) map[int32]*procutil.Stats {

// Run collects process data (regular metadata + stats) and/or realtime process data (stats only)
func (p *ProcessCheck) Run(nextGroupID func() int32, options *RunOptions) (RunResult, error) {
if p.networkID == "" {
networkID, err := retryGetNetworkID(p.sysprobeClient)
if err != nil {
log.Warnf("error getting network ID: %s", err)
}
p.networkID = networkID
}

if options == nil {
return p.run(nextGroupID(), false)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/process/net/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GetNetworkID(client *http.Client) (string, error) {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("network_id request failed: url: %s, status code: %d", req.URL, resp.StatusCode)
return "", fmt.Errorf("network ID request failed: url: %s, status code: %d", req.URL, resp.StatusCode)
}

body, err := sysprobeclient.ReadAllResponseBody(resp)
Expand Down
Loading