Skip to content

Commit 993d71d

Browse files
Merge pull request openshift#8787 from r4f4/analyze-gather-fails
OCPBUGS-34953: fix bogus analyze message when gather fails
2 parents a651e1a + e1fab6a commit 993d71d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pkg/gather/service/analyze.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"archive/tar"
55
"compress/gzip"
66
"encoding/json"
7+
"errors"
8+
"fmt"
79
"io"
810
"os"
911
"regexp"
1012
"strings"
1113

12-
"github.com/pkg/errors"
1314
"github.com/sirupsen/logrus"
1415
)
1516

@@ -27,7 +28,7 @@ func AnalyzeGatherBundle(bundlePath string) error {
2728
// open the bundle file for reading
2829
bundleFile, err := os.Open(bundlePath)
2930
if err != nil {
30-
return errors.Wrap(err, "could not open the gather bundle")
31+
return fmt.Errorf("could not open the gather bundle: %w", err)
3132
}
3233
defer bundleFile.Close()
3334
return analyzeGatherBundle(bundleFile)
@@ -37,20 +38,21 @@ func analyzeGatherBundle(bundleFile io.Reader) error {
3738
// decompress the bundle
3839
uncompressedStream, err := gzip.NewReader(bundleFile)
3940
if err != nil {
40-
return errors.Wrap(err, "could not decompress the gather bundle")
41+
return fmt.Errorf("could not decompress the gather bundle: %w", err)
4142
}
4243
defer uncompressedStream.Close()
4344

4445
// read through the tar for relevant files
4546
tarReader := tar.NewReader(uncompressedStream)
4647
serviceAnalyses := make(map[string]analysis)
48+
servicesFound := make([]string, 0)
4749
for {
4850
header, err := tarReader.Next()
4951
if err == io.EOF {
5052
break
5153
}
5254
if err != nil {
53-
return errors.Wrap(err, "encountered an error reading from the gather bundle")
55+
return fmt.Errorf("encountered an error reading from the gather bundle: %w", err)
5456
}
5557
if header.Typeflag != tar.TypeReg {
5658
continue
@@ -61,6 +63,7 @@ func analyzeGatherBundle(bundleFile io.Reader) error {
6163
continue
6264
}
6365
serviceName := serviceEntriesFileSubmatch[1]
66+
servicesFound = append(servicesFound, serviceName)
6467

6568
serviceAnalysis, err := analyzeService(tarReader)
6669
if err != nil {
@@ -71,6 +74,11 @@ func analyzeGatherBundle(bundleFile io.Reader) error {
7174
serviceAnalyses[serviceName] = serviceAnalysis
7275
}
7376

77+
if len(servicesFound) == 0 {
78+
logrus.Error("Invalid log bundle or the bootstrap machine could not be reached and bootstrap logs were not collected")
79+
return nil
80+
}
81+
7482
analysisChecks := []struct {
7583
name string
7684
check func(analysis) bool
@@ -138,7 +146,7 @@ func analyzeService(r io.Reader) (analysis, error) {
138146
decoder := json.NewDecoder(r)
139147
t, err := decoder.Token()
140148
if err != nil {
141-
return a, errors.Wrap(err, "service entries file does not begin with a token")
149+
return a, fmt.Errorf("service entries file does not begin with a token: %w", err)
142150
}
143151
delim, isDelim := t.(json.Delim)
144152
if !isDelim {
@@ -151,7 +159,7 @@ func analyzeService(r io.Reader) (analysis, error) {
151159
for decoder.More() {
152160
entry := &Entry{}
153161
if err := decoder.Decode(entry); err != nil {
154-
return a, errors.Wrap(err, "could not decode an entry in the service entries file")
162+
return a, fmt.Errorf("could not decode an entry in the service entries file: %w", err)
155163
}
156164

157165
// record a new start of the service

pkg/gather/service/analyze_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestAnalyzeGatherBundle(t *testing.T) {
5454
{
5555
name: "no files",
5656
expectedOutput: []logrus.Entry{
57-
{Level: logrus.ErrorLevel, Message: "The bootstrap machine did not execute the release-image.service systemd unit"},
57+
{Level: logrus.ErrorLevel, Message: "Invalid log bundle or the bootstrap machine could not be reached and bootstrap logs were not collected"},
5858
},
5959
},
6060
{

0 commit comments

Comments
 (0)