Skip to content

Commit

Permalink
Combine the two collector func overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Feb 8, 2024
1 parent 3e6c759 commit e1cfc83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
15 changes: 2 additions & 13 deletions collector-framework/pkg/cmd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@ const (
defaultDevInfoInterval int = 60
)

type CollectorArgFunc func() map[string]map[string]any
type CheckVarsFunc func([]string)
type CollectorArgFunc func([]string) map[string]map[string]any

var (
requestedDurationStr string
pollInterval int
devInfoAnnouceInterval int
collectorNames []string
runFunc CollectorArgFunc
checkVars CheckVarsFunc
)

func SetCollecterArgsFunc(f CollectorArgFunc) {
runFunc = f
}

func SetCheckVarsFunc(f CheckVarsFunc) {
checkVars = f
}

// CollectCmd represents the collect command
var CollectCmd = &cobra.Command{
Use: "collect",
Expand All @@ -55,15 +49,10 @@ var CollectCmd = &cobra.Command{
}
utils.IfErrorExitOrPanic(err)

if checkVars != nil {
log.Debug("No checkVars function is defined")
checkVars(collectorNames)
}

collectorArgs := make(map[string]map[string]any)
if runFunc != nil {
log.Debug("No runFunc function is defined")
collectorArgs = runFunc()
collectorArgs = runFunc(collectorNames)
}

collectionRunner.Run(
Expand Down
34 changes: 16 additions & 18 deletions tgm-collector/pkg/cmd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ package cmd

import (
"errors"
"log"
"os"
"os/user"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"

fCmd "github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework/pkg/cmd"
"github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework/pkg/runner"
"github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework/pkg/utils"
Expand All @@ -25,7 +24,6 @@ const (
)

type CollectorArgFunc func() map[string]map[string]any
type CheckVarsFunc func()

var (
logsOutputFile string
Expand All @@ -51,21 +49,8 @@ func init() { //nolint:funlen // Allow this to get a little long
"Directory for storing temp/debug files. Must exist.")
fCmd.CollectCmd.Flags().BoolVar(&keepDebugFiles, "keep", defaultKeepDebugFiles, "Keep debug files")

fCmd.SetCollecterArgsFunc(func() map[string]map[string]any {
collectorArgs := make(map[string]map[string]any)
collectorArgs["PTP"] = map[string]any{
"ptpInterface": ptpInterface,
}
collectorArgs["Logs"] = map[string]any{
"logsOutputFile": logsOutputFile,
"includeLogTimestamps": includeLogTimestamps,
"tempDir": tempDir,
"keepDebugFiles": keepDebugFiles,
}
return collectorArgs
})

fCmd.SetCheckVarsFunc(func(collectorNames []string) {
fCmd.SetCollecterArgsFunc(func(collectorNames []string) map[string]map[string]any {
// Check args
for _, c := range collectorNames {
if (c == collectors.LogsCollectorName || c == runner.All) && logsOutputFile == "" {
utils.IfErrorExitOrPanic(utils.NewMissingInputError(
Expand All @@ -89,5 +74,18 @@ func init() { //nolint:funlen // Allow this to get a little long
if err := os.MkdirAll(tempDir, tempdirPerm); err != nil {
log.Fatal(err)
}

// Populate collector args
collectorArgs := make(map[string]map[string]any)
collectorArgs["PTP"] = map[string]any{
"ptpInterface": ptpInterface,
}
collectorArgs["Logs"] = map[string]any{
"logsOutputFile": logsOutputFile,
"includeLogTimestamps": includeLogTimestamps,
"tempDir": tempDir,
"keepDebugFiles": keepDebugFiles,
}
return collectorArgs
})
}

0 comments on commit e1cfc83

Please sign in to comment.