Skip to content

Commit

Permalink
MGMT-14633: WIP include manifest information in the log download
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-maidment committed Dec 5, 2023
1 parent 85498bc commit dd6774a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
37 changes: 37 additions & 0 deletions internal/cluster/cluster.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -40,6 +41,7 @@ import (
"github.com/openshift/assisted-service/pkg/ocm"
"github.com/openshift/assisted-service/pkg/requestid"
"github.com/openshift/assisted-service/pkg/s3wrapper"
operations "github.com/openshift/assisted-service/restapi/operations/manifests"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/thoas/go-funk"
Expand Down Expand Up @@ -1105,7 +1107,42 @@ func (m *Manager) createClusterDataFiles(ctx context.Context, c *common.Cluster,
fileName := fmt.Sprintf("%s/logs/cluster/events.json", c.ID)
_ = m.uploadDataAsFile(ctx, log, events, fileName, objectHandler)
}

includeSystemGenerated := true
listManifests, _ := m.manifestApi.ListClusterManifestsInternal(ctx, operations.V2ListClusterManifestsParams{ClusterID: *c.ID, IncludeSystemGenerated: &includeSystemGenerated})
for _, manifestEntry := range listManifests {
// Download the manifest content
path := filepath.Join(manifestEntry.Folder, manifestEntry.FileName)
objectName := filepath.Join(string(*c.ID), constants.ManifestFolder, path)
exists, _ := objectHandler.DoesObjectExist(ctx, objectName)
if exists {
continue
}
response, numberOfBytes, err := m.objectHandler.Download(ctx, objectName)
if err != nil {
log.WithError(err).Errorf("failed to download file %s from cluster while building log: %s", path, *c.ID)
continue
}
fileContent, err := io.ReadAll(response)
if err != nil {
log.WithError(err).Errorf("failed to read file data %s (%d) from cluster while building log: %s", path, numberOfBytes, *c.ID)
continue
}
// Determine the manifest type, this will determine where the file is uploaded to
isUserManifest, err := m.manifestApi.IsUserManifest(ctx, *c.ID, manifestEntry.Folder, manifestEntry.FileName)
manifestSubdir := "system-generated"
if err != nil {
log.WithError(err).Errorf("Unable to determine if manifest is user generated or not for %s/%s", manifestEntry.Folder, manifestEntry.FileName)
manifestSubdir = "unknown"
}
if isUserManifest {
manifestSubdir = "user-supplied"
}
fileName := fmt.Sprintf("%s/logs/cluster/%s/%s/%s", c.ID, manifestSubdir, manifestEntry.Folder, manifestEntry.FileName)
_ = m.uploadDataAsFile(ctx, log, string(fileContent), fileName, objectHandler)
}
}

func (m *Manager) PrepareHostLogFile(ctx context.Context, c *common.Cluster, host *models.Host, objectHandler s3wrapper.API) (string, error) {
var (
fileName string
Expand Down
10 changes: 8 additions & 2 deletions internal/cluster/cluster_test.go
Expand Up @@ -2783,6 +2783,7 @@ var _ = Describe("Cluster tarred files", func() {
tarFile string
clusterObjectFilename string
eventsFilename string
mockManifestApi *manifestsapi.MockManifestsAPI
)

uploadClusterDataSuccess := func() {
Expand All @@ -2808,7 +2809,8 @@ var _ = Describe("Cluster tarred files", func() {
mockEvents = eventsapi.NewMockHandler(ctrl)
dummy := &leader.DummyElector{}
mockOperators := operators.NewMockAPI(ctrl)
capi = NewManager(cfg, common.GetTestLog(), db, commontesting.GetDummyNotificationStream(ctrl), mockEvents, nil, mockHostAPI, nil, nil, dummy, mockOperators, nil, nil, nil, nil, nil)
mockManifestApi = manifestsapi.NewMockManifestsAPI(ctrl)
capi = NewManager(cfg, common.GetTestLog(), db, commontesting.GetDummyNotificationStream(ctrl), mockEvents, nil, mockHostAPI, nil, nil, dummy, mockOperators, nil, nil, nil, nil, mockManifestApi)
clusterId = strfmt.UUID(uuid.New().String())
cl = common.Cluster{
Cluster: models.Cluster{
Expand All @@ -2824,14 +2826,18 @@ var _ = Describe("Cluster tarred files", func() {
prefix = fmt.Sprintf("%s/logs/", cl.ID)
mockEvents.EXPECT().SendClusterEvent(gomock.Any(), eventstest.NewEventMatcher(
eventstest.WithClusterIdMatcher(clusterId.String()))).AnyTimes()

mockManifestApi.EXPECT().ListClusterManifestsInternal(gomock.Any(), gomock.Any()).Return(models.ListManifests{}, nil)
})

AfterEach(func() {
ctrl.Finish()
common.DeleteTestDB(db, dbName)
})

It("Should add manifests to cluster log file", func() {

})

It("list events failed - but PrepareClusterLogFile should continue to download", func() {
mockS3Client.EXPECT().Upload(ctx, gomock.Any(), clusterObjectFilename).Return(nil).Times(1)
mockEvents.EXPECT().V2GetEvents(gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("dummy")).Times(1)
Expand Down

0 comments on commit dd6774a

Please sign in to comment.