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

chef-automate gather-logs for faulty nodes #7525

Merged
merged 8 commits into from
Nov 15, 2022
Merged
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
42 changes: 40 additions & 2 deletions components/automate-cli/cmd/chef-automate/gather-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func runGatherLogsCmd(cmd *cobra.Command, args []string) error {
}

if gatherLogsCmdFlags.localFallback {
return runGatherLogsLocalCmd(overridePath, gatherLogsCmdFlags.logLines)
return gatherLogsForBackendNodes(overridePath, gatherLogsCmdFlags.logLines)
}

return gatherLogsFromServer(overridePath, gatherLogsCmdFlags.logLines)
return gatherLogsFromServerForFrontendNodes(overridePath, gatherLogsCmdFlags.logLines)
}

const recoveryMsg = `
Expand Down Expand Up @@ -634,3 +634,41 @@ func tryRevertingAnyNginxConfChanges() {
func init() {
RootCmd.AddCommand(newGatherLogsCmd())
}

//gatherLogsFromServerForFrontendNodes checks for hab svc status and for deployment service error
//Gather the logs for all frontend nodes
func gatherLogsFromServerForFrontendNodes(outfileOverride string, logLines uint64) error {
habSupErrorMsg := `
* * * chef-automate node services are down
* * * No gather-logs collected
`
//check for hab svc status
_, habSupError := exec.Command("hab", "svc", "status").CombinedOutput()

if habSupError != nil {
return status.WithRecovery(habSupError, habSupErrorMsg)
}
_, err := client.Connection(client.DefaultClientTimeout)
//check for deployment service error and if err return local gather-logs
if status.ErrorType(err) == "DeploymentServiceCallError" || status.ErrorType(err) == "DeploymentServiceUnreachableError" {
return runGatherLogsLocalCmd(outfileOverride, logLines)
}

return gatherLogsFromServer(outfileOverride, logLines)
}

//gatherLogsForBackendNodes checks for hab svc status
// Gather the logs for all backend nodes
func gatherLogsForBackendNodes(outfileOverride string, logLines uint64) error {
habSupErrorMsg := `
* * * Backend node services are down
* * * No gather-logs collected
`
//check for hab svc status
_, habSupError := exec.Command("hab", "svc", "status").CombinedOutput()

if habSupError != nil {
return status.WithRecovery(habSupError, habSupErrorMsg)
}
return runGatherLogsLocalCmd(outfileOverride, logLines)
}