Skip to content

Commit 0ecb0d9

Browse files
committed
feat: Harvest 7-mode dashboards should be provisioned
docs: Update Grafana folder names for cDOT and 7-mode
1 parent 3b2042d commit 0ecb0d9

21 files changed

+38
-28
lines changed

cmd/tools/grafana/grafana.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929

3030
const (
3131
clientTimeout = 5
32-
grafanaFolderTitle = "Harvest 2.0"
33-
grafana7modeFolderTitle = "7 mode"
32+
grafanaFolderTitle = "Harvest 2.0 - cDOT"
33+
grafana7modeFolderTitle = "Harvest 2.0 - 7-mode"
3434
grafanaDataSource = "Prometheus"
3535
)
3636

@@ -43,9 +43,10 @@ type options struct {
4343
command string // one of: import, export, clean
4444
addr string // URL of Grafana server (e.g. "http://localhost:3000")
4545
token string // API token issued by Grafana server
46-
dir string // Directory from which to import dashboards (e.g. "opt/harvest/grafana/dashboards")
47-
cmodeFolder Folder
48-
mode7Folder Folder
46+
dir string // Local directory for import/export-ing cDOT dashboards (e.g. "opt/harvest/grafana/dashboards")
47+
dir7mode string // Local directory for import/export-ing 7mode dashboards (e.g. "opt/harvest/grafana/dashboards")
48+
cmodeFolder Folder // Server-side Grafana folder name for cDOT dashboards
49+
mode7Folder Folder // Server-side Grafana folder name for 7-mode dashboards
4950
datasource string
5051
variable bool
5152
client *http.Client
@@ -362,14 +363,12 @@ func exportFiles(folder Folder) error {
362363
}
363364

364365
func importDashboards(opts *options) error {
365-
// Importing C mode dashboards
366-
_ = importFiles(opts.dir, opts.cmodeFolder)
367-
// Importing 7mode dashboards
368-
_ = importFiles(path.Join(opts.dir, strings.ReplaceAll(grafana7modeFolderTitle, " ", "")), opts.mode7Folder)
366+
importFiles(opts.dir, opts.cmodeFolder)
367+
importFiles(opts.dir7mode, opts.mode7Folder)
369368
return nil
370369
}
371370

372-
func importFiles(dir string, folder Folder) error {
371+
func importFiles(dir string, folder Folder) {
373372
var (
374373
request, dashboard map[string]interface{}
375374
files []os.FileInfo
@@ -380,7 +379,7 @@ func importFiles(dir string, folder Folder) error {
380379

381380
if files, err = ioutil.ReadDir(dir); err != nil {
382381
// TODO check for not exist
383-
return err
382+
return
384383
}
385384

386385
for _, file := range files {
@@ -390,7 +389,7 @@ func importFiles(dir string, folder Folder) error {
390389

391390
if data, err = ioutil.ReadFile(path.Join(dir, file.Name())); err != nil {
392391
fmt.Printf("error reading file [%s]\n", file.Name())
393-
return err
392+
return
394393
}
395394

396395
data = bytes.ReplaceAll(data, []byte("${DS_PROMETHEUS}"), []byte(opts.datasource))
@@ -411,7 +410,7 @@ func importFiles(dir string, folder Folder) error {
411410
fmt.Println("-------------------------------")
412411
fmt.Println(string(data))
413412
fmt.Println("-------------------------------")
414-
return err
413+
return
415414
}
416415

417416
// optionally add prefix to all metric names in the queries
@@ -428,18 +427,17 @@ func importFiles(dir string, folder Folder) error {
428427

429428
if err != nil {
430429
fmt.Printf("error importing [%s]\n", file.Name())
431-
return err
430+
return
432431
}
433432

434433
if code != 200 {
435434
fmt.Printf("error - server response (%d - %s) %v\n", code, status, result)
436-
return errors.New(status)
435+
return
437436
}
438-
fmt.Printf("OK - imported [%s]\n", file.Name())
437+
fmt.Printf("OK - imported %s / [%s]\n", folder.folderName, file.Name())
439438
importedFiles++
440439
}
441440
fmt.Printf("Imported %d dashboards from %s \n", importedFiles, dir)
442-
return nil
443441
}
444442

445443
// addGlobalPrefix adds the given prefix to all metric names in the
@@ -853,9 +851,10 @@ func init() {
853851
Cmd.PersistentFlags().StringVar(&opts.config, "config", "./harvest.yml", "harvest config file path")
854852
Cmd.PersistentFlags().StringVarP(&opts.addr, "addr", "a", "http://127.0.0.1:3000", "address of Grafana server (IP, FQDN or hostname)")
855853
Cmd.PersistentFlags().StringVarP(&opts.token, "token", "t", "", "API token issued by Grafana server for authentication")
856-
Cmd.PersistentFlags().StringVarP(&opts.dir, "directory", "d", "grafana/dashboards/", "when importing, directory that contains dashboards.\nWhen exporting, directory to write dashboards to")
857-
Cmd.PersistentFlags().StringVarP(&opts.cmodeFolder.folderName, "folder", "f", grafanaFolderTitle, "Grafana folder name for the C mode dashboards")
858-
Cmd.PersistentFlags().StringVarP(&opts.mode7Folder.folderName, "folder-7mode", "", grafana7modeFolderTitle, "Grafana folder name for the 7mode dashboards")
854+
Cmd.PersistentFlags().StringVarP(&opts.dir, "directory", "d", "grafana/dashboards/cmode", "when importing, directory that contains cDOT dashboards.\nWhen exporting, directory to write dashboards to")
855+
Cmd.PersistentFlags().StringVar(&opts.dir7mode, "seven", "grafana/dashboards/7mode", "when importing, directory that contains 7-mode dashboards.\nWhen exporting, directory to write dashboards to")
856+
Cmd.PersistentFlags().StringVarP(&opts.cmodeFolder.folderName, "folder", "f", grafanaFolderTitle, "Grafana folder name for the cDOT dashboards")
857+
Cmd.PersistentFlags().StringVarP(&opts.mode7Folder.folderName, "folder-7mode", "", grafana7modeFolderTitle, "Grafana folder name for the 7-mode dashboards")
859858
Cmd.PersistentFlags().StringVarP(&opts.prefix, "prefix", "p", "", "Use global metric prefix in queries")
860859
Cmd.PersistentFlags().StringVarP(&opts.datasource, "datasource", "s", grafanaDataSource, "Grafana datasource for the dashboards")
861860
Cmd.PersistentFlags().BoolVarP(&opts.variable, "variable", "v", false, "use datasource as variable, overrides: --datasource")

conf/zapi/7mode/8.6.0/node.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ counters:
1717
- ^vendor-id => vendor
1818
- ^product-version => version
1919

20-
21-
2220
export_options:
2321
require_instance_keys: false
2422
instance_labels:

grafana/dashboards/harvest_dashboard_aggregate.json renamed to grafana/dashboards/cmode/harvest_dashboard_aggregate.json

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

grafana/dashboards/harvest_dashboard_network_detail.json renamed to grafana/dashboards/cmode/harvest_dashboard_network_detail.json

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)