-
Notifications
You must be signed in to change notification settings - Fork 74
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
Keep looking for master process #617
Conversation
✅ Deploy Preview for agent-public-docs canceled.
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #617 +/- ##
==========================================
- Coverage 66.13% 66.02% -0.12%
==========================================
Files 118 118
Lines 13461 13504 +43
==========================================
+ Hits 8903 8916 +13
- Misses 3958 3987 +29
- Partials 600 601 +1 ☔ View full report in Codecov by Sentry. |
src/plugins/registration.go
Outdated
@@ -29,6 +29,7 @@ const ( | |||
dataplaneSoftwareDetailsMaxWaitTime = time.Duration(5 * time.Second) | |||
// Time between attempts to gather DataplaneSoftwareDetails | |||
softwareDetailsOperationInterval = time.Duration(1 * time.Second) | |||
nginxStartMaxWaitTime = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this not essentially turn off backoff altogether, if the MaxElapsedTime
is zero? If that is intentional, then I would maybe adding a comment explaining why it is turned off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the max wait time is set to 0 backoff will continue waiting indefinitely until the master process is found. I'll add in a comment now
src/plugins/registration.go
Outdated
@@ -93,13 +94,16 @@ func (r *OneTimeRegistration) Process(msg *core.Message) { | |||
defer r.dataplaneSoftwareDetailsMutex.Unlock() | |||
r.dataplaneSoftwareDetails[data.GetPluginName()] = data.GetDataplaneSoftwareDetails() | |||
} | |||
case msg.Exact(core.NginxDetailProcUpdate): | |||
r.processes = msg.Data().([]*core.Process) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a type check here, to ensure that the payload of the message is of the correct type (see the previous case
).
If the payload were to contain something other than []*core.Process
, then the code would panic, which is not great. Even though it should never have anything else than a []*core.Process
based on what the code looks like today, you never know how the code base will change in the future. As a rule of thumb, it's always good practice to perform type checking to ensure safe code.
src/plugins/registration.go
Outdated
} | ||
} else { | ||
log.Tracef("NGINX non-master process: %d", proc.Pid) | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return
causes the whole function to exit, meaning that the function will only ever find the master process if it is the first process in r.processes
. I would remove this return
.
// Reading nginx config during registration to populate nginx fields like access/error logs, etc. | ||
_, err := r.binary.ReadConfig(nginxDetails.GetConfPath(), nginxDetails.NginxId, r.env.GetSystemUUID()) | ||
if err != nil { | ||
log.Warnf("Unable to read config for NGINX instance %s, %v", nginxDetails.NginxId, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that this line isn't originally your code, but I'm wondering if we should actually be returning the error here instead of merely logging it 🤔
@oliveromahony, @dhurley, @Dean-Coakley, @aphralG thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the reason we dont return an error here is because we dont want to stop registration just because we cant read the config. If the config is invalid it should not stop the agent from performing other tasks like reporting the status of NGINX is that makes sense.
src/plugins/registration.go
Outdated
context.Background(), backoffSetting, findMaster, | ||
) | ||
if err != nil { | ||
log.Warn(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was previously:
log.Info("No master process found")
But my instinct is that this should be an error log, as I'd think we can't complete registration if we haven't found a master process.
Others could also weigh in on this, as I wouldn't consider myself an expert on registration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I believe previously we would continue with registration even if we didn't find master processes but now that we are waiting until we find one I think it should be an error log message.
log.Errorf("Unable to find NGINX master processes, %v", err)
src/plugins/registration.go
Outdated
Multiplier: backoff.BACKOFF_MULTIPLIER, | ||
} | ||
|
||
findMaster := func() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findMaster := func() error { | |
findNginxMasterProcesses := func() error { |
Proposed changes
Continuously searches for master process
Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)