Skip to content

Commit

Permalink
fix debug files
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 committed Jun 27, 2024
1 parent 9392737 commit cb153eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 11 additions & 11 deletions pkg/pipeline/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,19 @@ func (c *Controller) uploadDebugFiles() {
}

func (c *Controller) uploadTrackFiles(u uploader.Uploader) {
var dir string
if c.Debug.ToUploadConfig() == nil {
dir = c.Debug.PathPrefix
} else {
dir = c.TmpDir
return
}

files, err := os.ReadDir(dir)
files, err := os.ReadDir(c.TmpDir)
if err != nil {
return
}

for _, f := range files {
if strings.HasSuffix(f.Name(), ".csv") {
local := path.Join(dir, f.Name())
storage := path.Join(c.Debug.PathPrefix, f.Name())
local := path.Join(c.TmpDir, f.Name())
storage := path.Join(c.Debug.PathPrefix, c.Info.EgressId, f.Name())
_, _, err = u.Upload(local, storage, types.OutputTypeBlob, false, "track")
if err != nil {
logger.Errorw("failed to upload debug file", err)
Expand All @@ -121,17 +118,16 @@ func (c *Controller) uploadPProf(u uploader.Uploader) {
}

func (c *Controller) uploadDebugFile(u uploader.Uploader, data []byte, fileExtension string) {
storageDir := path.Join(c.Debug.PathPrefix, c.Info.EgressId)
var dir string
if c.Debug.ToUploadConfig() == nil {
dir = c.Debug.PathPrefix
dir = storageDir
} else {
dir = c.TmpDir
}

filename := fmt.Sprintf("%s%s", c.Info.EgressId, fileExtension)
local := path.Join(dir, filename)
storage := path.Join(c.Debug.PathPrefix, c.Info.EgressId, filename)

f, err := os.Create(local)
if err != nil {
logger.Errorw("failed to create debug file", err)
Expand All @@ -145,7 +141,11 @@ func (c *Controller) uploadDebugFile(u uploader.Uploader, data []byte, fileExten
return
}

_, _, err = u.Upload(local, storage, types.OutputTypeBlob, false, "debug")
if c.Debug.ToUploadConfig() == nil {
return
}

_, _, err = u.Upload(local, path.Join(storageDir, filename), types.OutputTypeBlob, false, "debug")
if err != nil {
logger.Errorw("failed to upload debug file", err)
return
Expand Down
8 changes: 6 additions & 2 deletions pkg/pipeline/source/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package source
import (
"context"
"fmt"
"os"
"path"
"strings"
"sync"
Expand Down Expand Up @@ -489,9 +490,12 @@ func (s *SDKSource) createWriter(
var logFilename string
if s.Debug.EnableProfiling {
if s.Debug.ToUploadConfig() == nil {
logFilename = path.Join(s.Debug.PathPrefix, fmt.Sprintf("%s/%s.csv", s.Info.EgressId, track.ID()))
if err := os.MkdirAll(path.Join(s.Debug.PathPrefix, s.Info.EgressId), 0755); err != nil {
return nil, err
}
logFilename = path.Join(s.Debug.PathPrefix, s.Info.EgressId, fmt.Sprintf("%s.csv", track.ID()))
} else {
logFilename = path.Join(s.TmpDir, fmt.Sprintf("%s/%s.csv", s.Info.EgressId, track.ID()))
logFilename = path.Join(s.TmpDir, fmt.Sprintf("%s.csv", track.ID()))
}
}

Expand Down

0 comments on commit cb153eb

Please sign in to comment.