Skip to content

Commit

Permalink
galera-agent: log state data when responding "200 / unhealthy"
Browse files Browse the repository at this point in the history
Previously galera-agent never logged data when a node was unhealthy.
This made interrupt diagnosis of proxy flapping difficult. Now
galera-agent outputs the parameters that determine the node to be
unhealthy.

[#187935541](https://www.pivotaltracker.com/story/show/187935541)

Co-authored-by: Kim Bassett <kbassett@vmware.com>
Co-authored-by: Kyle Ong <kyleo@vmware.com>
  • Loading branch information
kimago and ohkyle committed Jul 16, 2024
1 parent 618232f commit a74baf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,18 @@ func (r router) v1Status() http.Handler {

w.Header().Set("Content-Type", "application/json")

json.NewEncoder(w).Encode(V1StatusResponse{
healthy := s.IsHealthy(r.rootConfig.AvailableWhenReadOnly)
resp := V1StatusResponse{
WsrepLocalState: uint(s.WsrepLocalState),
WsrepLocalStateComment: string(s.WsrepLocalState.Comment()),
WsrepLocalIndex: s.WsrepLocalIndex,
Healthy: s.IsHealthy(r.rootConfig.AvailableWhenReadOnly),
})
Healthy: healthy,
}

if !healthy {
r.logger.Info(fmt.Sprintf("unhealthy state: %#v maintenanceEnabled: %t readOnly: %t", resp, s.MaintenanceEnabled, s.ReadOnly))
}
json.NewEncoder(w).Encode(resp)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ var _ = Describe("Sidecar API", func() {
Expect(state.WsrepLocalStateComment).To(Equal(string(returnedState.WsrepLocalState.Comment())))
Expect(state.Healthy).To(BeTrue())
})

When("it interprets the state as 'unhealthy'", func() {
BeforeEach(func() {
stateSnapshotter.StateReturns(domain.DBState{
WsrepLocalIndex: uint(0),
WsrepLocalState: domain.WsrepLocalState(0),
ReadOnly: false,
MaintenanceEnabled: true, // forces unhealthy state
}, nil)
})

It("logs the unhealthy state", func() {
req := createReq("api/v1/status", "GET")
_, err := http.DefaultClient.Do(req)
Expect(err).ToNot(HaveOccurred())

Expect(len(testLogger.Logs())).To(Equal(1))
logData := testLogger.Logs()[0]
Expect(logData.Message).To(Equal("mysql_cmd.unhealthy state: api.V1StatusResponse{WsrepLocalState:0x0, WsrepLocalStateComment:\"Initialized\", WsrepLocalIndex:0x0, Healthy:false} maintenanceEnabled: true readOnly: false"))
})
})
})

Context("when getting the state fails", func() {
Expand Down

0 comments on commit a74baf5

Please sign in to comment.