Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Harvest should log errors when grafana import fails #2962

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cmd/tools/grafana/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func doImport(_ *cobra.Command, _ []string) {
opts.command = "import"
_, err := conf.LoadHarvestConfig(opts.config)
if err != nil {
return
printErrorAndExit(err)
}

adjustOptions()
Expand All @@ -392,6 +392,11 @@ func doImport(_ *cobra.Command, _ []string) {
importDashboards(opts)
}

func printErrorAndExit(err error) {
fmt.Println(err)
os.Exit(1)
}

func validateImport() {
// default case
if opts.dir == "" && opts.serverfolder.name == "" {
Expand All @@ -418,7 +423,7 @@ func initImportVars() {
switch {
case opts.dir == "grafana/dashboards" && opts.serverfolder.name == "":
m[filepath.Join(opts.dir, "cmode")] = &Folder{name: "Harvest-" + harvestRelease + "-cDOT"}
m[filepath.Join(opts.dir, "cmode", "details")] = &Folder{name: "Harvest-" + harvestRelease + "-cDOT Details"}
m[filepath.Join(opts.dir, "cmode-details")] = &Folder{name: "Harvest-" + harvestRelease + "-cDOT Details"}
m[filepath.Join(opts.dir, "7mode")] = &Folder{name: "Harvest-" + harvestRelease + "-7mode"}
m[filepath.Join(opts.dir, "storagegrid")] = &Folder{name: "Harvest-" + harvestRelease + "-StorageGrid"}
case opts.dir != "" && opts.serverfolder.name != "":
Expand All @@ -431,8 +436,7 @@ func initImportVars() {
if opts.customizeDir == "" {
err := checkAndCreateServerFolder(v)
if err != nil {
fmt.Print(err)
os.Exit(1)
printErrorAndExit(err)
}
}
opts.dirGrafanaFolderMap[k] = v
Expand Down Expand Up @@ -488,8 +492,7 @@ func importFiles(dir string, folder *Folder) {
return
}
if files, err = os.ReadDir(dir); err != nil {
// TODO check for not exist
return
printErrorAndExit(err)
}

for _, file := range files {
Expand Down
2 changes: 1 addition & 1 deletion integration/test/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGrafanaAndPrometheusAreConfigured(t *testing.T) {
cDotFolder = "Harvest-" + version.VERSION + "-cDOT"
sevenModeFolder = "Harvest-" + version.VERSION + "-7mode"
log.Info().Str("cMode", cDotFolder).Str("7mode", sevenModeFolder).Msg("Folder name details")
status, out := new(grafana.Mgr).Import("") // send empty so that it will import all dashboards
status, out := new(grafana.Mgr).Import()
if !status {
t.Errorf("Grafana import operation failed out=%s", out)
}
Expand Down
8 changes: 2 additions & 6 deletions integration/test/grafana/grafana_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Mgr struct {
}

func (g *Mgr) Import(jsonDir string) (bool, string) {
func (g *Mgr) Import() (bool, string) {
var (
importOutput string
status bool
Expand All @@ -31,15 +31,11 @@ func (g *Mgr) Import(jsonDir string) (bool, string) {
if err != nil {
panic(err)
}
directoryOption := ""
if jsonDir != "" {
directoryOption = "--directory"
}
grafanaURL := utils.GetGrafanaURL()
if docker.IsDockerBasedPoller() {
grafanaURL = "grafana:3000"
}
importCmds := []string{"grafana", "import", "--overwrite", "--addr", grafanaURL, directoryOption, jsonDir}
importCmds := []string{"grafana", "import", "--overwrite", "--addr", grafanaURL}
if docker.IsDockerBasedPoller() {
params := []string{"exec", containerIDs[0].ID, "bin/harvest"}
params = append(params, importCmds...)
Expand Down