Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Collect bug report for e2e failures
Browse files Browse the repository at this point in the history
Signed-off-by: nshankar13 <[email protected]>
  • Loading branch information
nshankar13 committed Feb 3, 2022
1 parent 3367f49 commit 9458b79
Showing 1 changed file with 12 additions and 102 deletions.
114 changes: 12 additions & 102 deletions tests/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,8 @@ func (td *OsmTestData) Cleanup(ct CleanupType) {
if td.CollectLogs == CollectLogs || td.CollectLogs == ControlPlaneOnly ||
((restartSeen && !td.IgnoreRestarts) || CurrentGinkgoTestDescription().Failed) && td.CollectLogs == CollectLogsIfErrorOnly {
// Grab logs. We will move this to use CLI when able.
if err := td.GrabLogs(); err != nil {

if err := td.GetBugReport(); err != nil {
td.T.Logf("Error getting logs: %v", err)
}
}
Expand Down Expand Up @@ -1389,112 +1390,21 @@ func (td *OsmTestData) GetOsmCtlComponentRestarts() map[string]int {
return restartMap
}

// GrabLogs Collects logs on test folder for td.OsmNamespace
func (td *OsmTestData) GrabLogs() error {
logCollector := "../../scripts/get-osm-namespace-logs.sh"

// Using absolute paths (though inferred from relative) for clarity
absLogCollectorPath, err := filepath.Abs(logCollector)
if err != nil {
return err
}

absTestDirPath, err := filepath.Abs(td.GetTestDirPath())
if err != nil {
return err
}
// GetBugReport runs the "osm support bug-report" command
func (td *OsmTestData) GetBugReport() error {
var args []string
args = append(args, "support",
"bug-report",
"--all",
)

td.T.Logf("Collecting logs, using \"%s %s\"", absLogCollectorPath, absTestDirPath)
// Assumes testing has been launched from repo's root
stdout, stderr, err := td.RunLocal(absLogCollectorPath, absTestDirPath)
if err != nil {
td.T.Logf("error running get-osm-namespace-logs script")
td.T.Logf("stdout:\n%s", stdout)
td.T.Logf("stderr:\n%s", stderr)
}
stdout, stderr, err := td.RunLocal(filepath.FromSlash("../../bin/osm"), args...)

stdout, stderr, err = td.RunLocal("kubectl", "get", "events", "-A")
if err != nil {
td.T.Logf("error running kubectl get events")
td.T.Logf("error running osm support bug-report")
td.T.Logf("stdout:\n%s", stdout)
td.T.Logf("stderr:\n%s", stderr)
} else {
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", absTestDirPath, "events"), stdout.Bytes(), 0600); err != nil {
td.T.Logf("Failed to write file for events: %s", err)
}
}

if td.CollectLogs == ControlPlaneOnly {
return nil
}

if td.InstType == KindCluster {
kindExportPath := td.GetTestFilePath("kindExport")
td.T.Logf("Collecting kind cluster")

stdout, stderr, err := td.RunLocal("kind", "export", "logs", "--name", td.ClusterName, kindExportPath)
if err != nil {
td.T.Logf("error running get-osm-namespace-logs script")
td.T.Logf("stdout:\n%s", stdout)
td.T.Logf("stderr:\n%s", stderr)
}
}

// TODO: Eventually a CLI command should implement collection of configurations necessary for debugging
pods, err := td.Client.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
// Reliable way to select injected pods
LabelSelector: "osm-proxy-uuid",
})

if err != nil {
return err
}

envoyConfDir := td.GetTestFilePath("envoy_configs")
err = os.Mkdir(envoyConfDir, 0750)
if err != nil && !os.IsExist(err) {
td.T.Logf("Error on creating dir for %s: %v", envoyConfDir, err)
return err
}

for _, pod := range pods.Items {
podEnvoyConfigFilepath := strings.Join([]string{envoyConfDir, fmt.Sprintf("%s_%s", pod.Namespace, pod.Name)}, "/")
err := os.Mkdir(podEnvoyConfigFilepath, 0750)
if err != nil && !os.IsExist(err) {
td.T.Logf("Error on creating dir for %s: %v, skipping", podEnvoyConfigFilepath, err)
continue
}

envoyDebugPaths := []string{
"config_dump",
"clusters",
"certs",
"listeners",
"ready",
"stats",
}

for _, dbgEnvoyPath := range envoyDebugPaths {
cmd := "../../bin/osm"
filePath := fmt.Sprintf("%s/%s.txt", podEnvoyConfigFilepath, dbgEnvoyPath)
args := []string{
"proxy",
"get",
dbgEnvoyPath,
pod.Name,
"--namespace",
pod.Namespace,
"-f",
filePath,
}

stdout, stderr, err := td.RunLocal(cmd, args...)
if err != nil {
td.T.Logf("error running cmd: %s args: %v", cmd, args)
td.T.Logf("stdout:\n%s", stdout)
td.T.Logf("stderr:\n%s", stderr)
}
}
return errors.Wrap(err, "failed to run osm support bug-report")
}

return nil
Expand Down

0 comments on commit 9458b79

Please sign in to comment.