Skip to content

Commit b89c314

Browse files
author
Rodrigo Valin
committed
Addressing PR comments.
1 parent 2a0fb41 commit b89c314

File tree

3 files changed

+178
-5
lines changed

3 files changed

+178
-5
lines changed

cmd/readiness/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func main() {
226226

227227
// isInReadyState checks the MongoDB Server state. It returns true if the state
228228
// is PRIMARY or SECONDARY.
229-
// This function will always return true if the agent don't publish this state.
229+
// This function will always return true if the agent doesn't publish this state.
230230
func isInReadyState(health health.Status) bool {
231231
if len(health.Healthiness) == 0 {
232232
return true
@@ -248,6 +248,11 @@ func isInReadyState(health health.Status) bool {
248248
return false
249249
}
250250

251+
// mongoDbServerHasStarted checks if the current plan includes a Move and a Step
252+
// of type "StartFresh" with a Result of "success".
253+
//
254+
// This function will return true if the agent has been able to successfully
255+
// start the MongoDB server.
251256
func mongoDbServerHasStarted(health health.Status) bool {
252257
plan := findCurrentPlan(health.ProcessPlans)
253258
if plan == nil {
@@ -265,18 +270,24 @@ func mongoDbServerHasStarted(health health.Status) bool {
265270
return false
266271
}
267272

273+
// findCurrentPlan returns the current plan as informed by the Agent.
274+
//
275+
// The current plan is the last plan from the `processStatuses` parameter, this
276+
// is, the plan that's currently being processed by the agent.
268277
func findCurrentPlan(processStatuses map[string]health.MmsDirectorStatus) *health.PlanStatus {
269278
var currentPlan *health.PlanStatus
270279
if len(processStatuses) == 0 {
271-
// Seems shouldn't happen but let's check anyway - may be needs to be changed to Info if this happens
280+
// Seems shouldn't happen but let's check anyway - may be needs to be
281+
// changed to Info if this happens.
272282
logger.Warnf("There is no information about Agent process plans")
273283
return nil
274284
}
275285
if len(processStatuses) > 1 {
276286
logger.Errorf("Only one process status is expected but got %d!", len(processStatuses))
277287
return nil
278288
}
279-
// There is always only one process managed by the Agent - so there will be only one loop
289+
// There is only one process managed by the Agent - so will only check one
290+
// iteration.
280291
for k, v := range processStatuses {
281292
if len(v.Plans) == 0 {
282293
logger.Errorf("The process %s doesn't contain any plans!", k)
Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
{ "statuses": { "bar": { "IsInGoalState": true, "LastMongoUpTime": 1568222195, "ExpectedToBeUp": true, "ReplicationStatus": 3 } }, "mmsStatus": { "bar": { "name": "bar", "lastGoalVersionAchieved": 5, "plans": [ { "started": "2019-09-11T14:20:40.631348806Z", "completed": "2019-09-11T14:21:42.034934358Z", "moves": [ { "move": "Download", "moveDoc": "Download mongodb binaries", "steps": [ { "step": "Download", "stepDoc": "Download mongodb binaries (may take a while)", "isWaitStep": false, "started": "2019-09-11T14:20:40.631404367Z", "completed": "2019-09-11T14:20:55.645615846Z", "result": "success" } ] }, { "move": "Start", "moveDoc": "Start the process", "steps": [ { "step": "StartFresh", "stepDoc": "Start a mongo instance (start fresh)", "isWaitStep": false, "started": "2019-09-11T14:20:55.645743003Z", "completed": "2019-09-11T14:20:59.325129842Z", "result": "success" } ] }, { "move": "WaitRsInit", "moveDoc": "Wait for the replica set to be initialized by another member", "steps": [ { "step": "WaitRsInit", "stepDoc": "Wait for the replica set to be initialized by another member", "isWaitStep": true, "started": "2019-09-11T14:20:59.325272608Z", "completed": null, "result": "wait" } ] }, { "move": "WaitFeatureCompatibilityVersionCorrect", "moveDoc": "Wait for featureCompatibilityVersion to be right", "steps": [ { "step": "WaitFeatureCompatibilityVersionCorrect", "stepDoc": "Wait for featureCompatibilityVersion to be right", "isWaitStep": true, "started": null, "completed": null, "result": "" } ] } ] } ], "errorCode": 0, "errorString": "" } } }
1+
{
2+
"mmsStatus": {
3+
"bar": {
4+
"errorString": "",
5+
"errorCode": 0,
6+
"plans": [
7+
{
8+
"moves": [
9+
{
10+
"steps": [
11+
{
12+
"result": "success",
13+
"completed": "2019-09-11T14:20:55.645615846Z",
14+
"started": "2019-09-11T14:20:40.631404367Z",
15+
"isWaitStep": false,
16+
"stepDoc": "Download mongodb binaries (may take a while)",
17+
"step": "Download"
18+
}
19+
],
20+
"moveDoc": "Download mongodb binaries",
21+
"move": "Download"
22+
},
23+
{
24+
"steps": [
25+
{
26+
"result": "success",
27+
"completed": "2019-09-11T14:20:59.325129842Z",
28+
"started": "2019-09-11T14:20:55.645743003Z",
29+
"isWaitStep": false,
30+
"stepDoc": "Start a mongo instance (start fresh)",
31+
"step": "StartFresh"
32+
}
33+
],
34+
"moveDoc": "Start the process",
35+
"move": "Start"
36+
},
37+
{
38+
"steps": [
39+
{
40+
"result": "wait",
41+
"completed": null,
42+
"started": "2019-09-11T14:20:59.325272608Z",
43+
"isWaitStep": true,
44+
"stepDoc": "Wait for the replica set to be initialized by another member",
45+
"step": "WaitRsInit"
46+
}
47+
],
48+
"moveDoc": "Wait for the replica set to be initialized by another member",
49+
"move": "WaitRsInit"
50+
},
51+
{
52+
"steps": [
53+
{
54+
"result": "",
55+
"completed": null,
56+
"started": null,
57+
"isWaitStep": true,
58+
"stepDoc": "Wait for featureCompatibilityVersion to be right",
59+
"step": "WaitFeatureCompatibilityVersionCorrect"
60+
}
61+
],
62+
"moveDoc": "Wait for featureCompatibilityVersion to be right",
63+
"move": "WaitFeatureCompatibilityVersionCorrect"
64+
}
65+
],
66+
"completed": "2019-09-11T14:21:42.034934358Z",
67+
"started": "2019-09-11T14:20:40.631348806Z"
68+
}
69+
],
70+
"lastGoalVersionAchieved": 5,
71+
"name": "bar"
72+
}
73+
},
74+
"statuses": {
75+
"bar": {
76+
"ReplicationStatus": 3,
77+
"ExpectedToBeUp": true,
78+
"LastMongoUpTime": 1568222195,
79+
"IsInGoalState": true
80+
}
81+
}
82+
}
Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
{ "statuses": { "bar": { "IsInGoalState": true, "LastMongoUpTime": 1568222195, "ExpectedToBeUp": true, "ReplicationStatus": null } }, "mmsStatus": { "bar": { "name": "bar", "lastGoalVersionAchieved": 5, "plans": [ { "started": "2019-09-11T14:20:40.631348806Z", "completed": "2019-09-11T14:21:42.034934358Z", "moves": [ { "move": "Download", "moveDoc": "Download mongodb binaries", "steps": [ { "step": "Download", "stepDoc": "Download mongodb binaries (may take a while)", "isWaitStep": false, "started": "2019-09-11T14:20:40.631404367Z", "completed": "2019-09-11T14:20:55.645615846Z", "result": "success" } ] }, { "move": "Start", "moveDoc": "Start the process", "steps": [ { "step": "StartFresh", "stepDoc": "Start a mongo instance (start fresh)", "isWaitStep": false, "started": "2019-09-11T14:20:55.645743003Z", "completed": "2019-09-11T14:20:59.325129842Z", "result": "success" } ] }, { "move": "WaitRsInit", "moveDoc": "Wait for the replica set to be initialized by another member", "steps": [ { "step": "WaitRsInit", "stepDoc": "Wait for the replica set to be initialized by another member", "isWaitStep": true, "started": "2019-09-11T14:20:59.325272608Z", "completed": null, "result": "wait" } ] }, { "move": "WaitFeatureCompatibilityVersionCorrect", "moveDoc": "Wait for featureCompatibilityVersion to be right", "steps": [ { "step": "WaitFeatureCompatibilityVersionCorrect", "stepDoc": "Wait for featureCompatibilityVersion to be right", "isWaitStep": true, "started": null, "completed": null, "result": "" } ] } ] } ], "errorCode": 0, "errorString": "" } } }
1+
{
2+
"mmsStatus": {
3+
"bar": {
4+
"errorString": "",
5+
"errorCode": 0,
6+
"plans": [
7+
{
8+
"moves": [
9+
{
10+
"steps": [
11+
{
12+
"result": "success",
13+
"completed": "2019-09-11T14:20:55.645615846Z",
14+
"started": "2019-09-11T14:20:40.631404367Z",
15+
"isWaitStep": false,
16+
"stepDoc": "Download mongodb binaries (may take a while)",
17+
"step": "Download"
18+
}
19+
],
20+
"moveDoc": "Download mongodb binaries",
21+
"move": "Download"
22+
},
23+
{
24+
"steps": [
25+
{
26+
"result": "success",
27+
"completed": "2019-09-11T14:20:59.325129842Z",
28+
"started": "2019-09-11T14:20:55.645743003Z",
29+
"isWaitStep": false,
30+
"stepDoc": "Start a mongo instance (start fresh)",
31+
"step": "StartFresh"
32+
}
33+
],
34+
"moveDoc": "Start the process",
35+
"move": "Start"
36+
},
37+
{
38+
"steps": [
39+
{
40+
"result": "wait",
41+
"completed": null,
42+
"started": "2019-09-11T14:20:59.325272608Z",
43+
"isWaitStep": true,
44+
"stepDoc": "Wait for the replica set to be initialized by another member",
45+
"step": "WaitRsInit"
46+
}
47+
],
48+
"moveDoc": "Wait for the replica set to be initialized by another member",
49+
"move": "WaitRsInit"
50+
},
51+
{
52+
"steps": [
53+
{
54+
"result": "",
55+
"completed": null,
56+
"started": null,
57+
"isWaitStep": true,
58+
"stepDoc": "Wait for featureCompatibilityVersion to be right",
59+
"step": "WaitFeatureCompatibilityVersionCorrect"
60+
}
61+
],
62+
"moveDoc": "Wait for featureCompatibilityVersion to be right",
63+
"move": "WaitFeatureCompatibilityVersionCorrect"
64+
}
65+
],
66+
"completed": "2019-09-11T14:21:42.034934358Z",
67+
"started": "2019-09-11T14:20:40.631348806Z"
68+
}
69+
],
70+
"lastGoalVersionAchieved": 5,
71+
"name": "bar"
72+
}
73+
},
74+
"statuses": {
75+
"bar": {
76+
"ReplicationStatus": null,
77+
"ExpectedToBeUp": true,
78+
"LastMongoUpTime": 1568222195,
79+
"IsInGoalState": true
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)