Skip to content

Commit

Permalink
Dedup using overlaping generations as it provides better consitancey
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Sep 20, 2023
1 parent 9130434 commit 47b5813
Show file tree
Hide file tree
Showing 9 changed files with 1,757 additions and 163 deletions.
30 changes: 30 additions & 0 deletions pkg/cmd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ package cmd
import (
"errors"
"fmt"
"os"
"os/user"
"path/filepath"
"strings"
"time"

Expand All @@ -21,6 +24,9 @@ const (
defaultPollInterval int = 1
defaultDevInfoInterval int = 60
defaultIncludeLogTimestamps bool = false
defaultTempDir string = "."
defaultKeepDebugFiles bool = false
tempdirPerm = 0755
)

var (
Expand All @@ -30,6 +36,8 @@ var (
collectorNames []string
logsOutputFile string
includeLogTimestamps bool
tempDir string
keepDebugFiles bool
)

// collectCmd represents the collect command
Expand All @@ -54,6 +62,22 @@ var collectCmd = &cobra.Command{
}
}

if strings.Contains(tempDir, "~") {
usr, err := user.Current()
if err != nil {
log.Fatal("Failed to result homedir for current user in --tempdir")
}
if tempDir == "~" {
tempDir = usr.HomeDir
} else if strings.HasPrefix(tempDir, "~/") {
tempDir = filepath.Join(usr.HomeDir, tempDir[2:])
}
}

if err := os.MkdirAll(tempDir, tempdirPerm); err != nil {
log.Fatal(err)
}

collectionRunner.Run(
kubeConfig,
outputFile,
Expand All @@ -64,6 +88,8 @@ var collectCmd = &cobra.Command{
useAnalyserJSON,
logsOutputFile,
includeLogTimestamps,
tempDir,
keepDebugFiles,
)
},
}
Expand Down Expand Up @@ -127,4 +153,8 @@ func init() { //nolint:funlen // Allow this to get a little long
"log-timestamps", defaultIncludeLogTimestamps,
"Specifies if collected logs should include timestamps or not. (default is false)",
)

collectCmd.Flags().StringVarP(&tempDir, "tempdir", "t", defaultTempDir,
"Directory for storing temp/debug files. Must exist.")
collectCmd.Flags().BoolVar(&keepDebugFiles, "keep", defaultKeepDebugFiles, "Keep debug files")
}
2 changes: 2 additions & 0 deletions pkg/collectors/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ type CollectionConstructor struct {
PTPInterface string
Msg string
LogsOutputFile string
TempDir string
PollInterval int
DevInfoAnnouceInterval int
IncludeLogTimestamps bool
KeepDebugFiles bool
}

type PollResult struct {
Expand Down
Loading

0 comments on commit 47b5813

Please sign in to comment.