Repository: NetApp/harvest
Pull request #2275 (2023-08-10 15:01:20)

test: ensure dashboard time is now-3h


Patch:
diff --git a/cmd/poller/collector/asup.go b/cmd/poller/collector/asup.go
index 42841295..38fd28c9 100644
--- a/cmd/poller/collector/asup.go
+++ b/cmd/poller/collector/asup.go
@@ -15,7 +15,6 @@ import (
 	"github.com/shirou/gopsutil/v3/host"
 	"github.com/shirou/gopsutil/v3/mem"
 	"github.com/shirou/gopsutil/v3/process"
-	"golang.org/x/sys/unix"
 	"os"
 	"os/exec"
 	"path"
@@ -291,7 +290,6 @@ func attachMemory(msg *Payload) {
 	// This is similar to ps -ww -eo user,pid,ppid,stime,nlwp,rss,cmd
 	processes, err := process.Processes()
 	if err != nil {
-		logging.Get().Error().Err(err).Msg("Unable to get processes")
 		return
 	}
 
@@ -301,24 +299,13 @@ func attachMemory(msg *Payload) {
 	for _, p := range processes {
 		name, err := p.Name()
 		if err != nil {
-			if errors.Is(err, unix.EINVAL) || errors.Is(err, unix.ENOENT) {
-				// we do not have permissions. That's OK, skip this one
-			} else {
-				logging.Get().Error().Err(err).Msg("Unable to get name")
-			}
 			continue
 		}
 		pp := Process{
 			Pid: p.Pid,
 		}
 		memInfo, err := p.MemoryInfo()
-		if err != nil {
-			if errors.Is(err, unix.EPERM) {
-				// we do not have permissions. That's OK, skip this one
-			} else {
-				logging.Get().Error().Err(err).Msg("Unable to get memory")
-			}
-		} else {
+		if err == nil {
 			pp.RssBytes = memInfo.RSS
 		}
 
@@ -333,7 +320,7 @@ func attachMemory(msg *Payload) {
 
 		cmdline, err := p.Cmdline()
 		if err != nil {
-			logging.Get().Error().Err(err).Msg("Unable to get cmdline")
+			continue
 		} else {
 			pp.Cmdline = cmdline
 		}
@@ -342,27 +329,19 @@ func attachMemory(msg *Payload) {
 		}
 
 		username, err := p.Username()
-		if err != nil {
-			logging.Get().Error().Err(err).Msg("Unable to get username")
-		} else {
+		if err == nil {
 			pp.User = username
 		}
 		ppid, err := p.Ppid()
-		if err != nil {
-			logging.Get().Error().Err(err).Msg("Unable to get parent pid")
-		} else {
+		if err == nil {
 			pp.Ppid = ppid
 		}
 		ctime, err := p.CreateTime()
-		if err != nil {
-			logging.Get().Error().Err(err).Msg("Unable to get createTime")
-		} else {
+		if err == nil {
 			pp.Ctime = ctime
 		}
 		threads, err := p.NumThreads()
-		if err != nil {
-			logging.Get().Error().Err(err).Msg("Unable to get numThreads")
-		} else {
+		if err == nil {
 			pp.Threads = threads
 		}
 		msg.Platform.Processes = append(msg.Platform.Processes, pp)
diff --git a/grafana/dashboards/cmode/compliance.json b/grafana/dashboards/cmode/compliance.json
index 17d67e63..0801ee38 100644
--- a/grafana/dashboards/cmode/compliance.json
+++ b/grafana/dashboards/cmode/compliance.json
@@ -136,7 +136,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/data_protection_snapshot.json b/grafana/dashboards/cmode/data_protection_snapshot.json
index ef67f825..00719d08 100644
--- a/grafana/dashboards/cmode/data_protection_snapshot.json
+++ b/grafana/dashboards/cmode/data_protection_snapshot.json
@@ -1586,7 +1586,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/disk.json b/grafana/dashboards/cmode/disk.json
index 902ee5e3..e2815844 100644
--- a/grafana/dashboards/cmode/disk.json
+++ b/grafana/dashboards/cmode/disk.json
@@ -2756,7 +2756,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/fsa.json b/grafana/dashboards/cmode/fsa.json
index 937eb7ac..9faa5a3a 100644
--- a/grafana/dashboards/cmode/fsa.json
+++ b/grafana/dashboards/cmode/fsa.json
@@ -1665,7 +1665,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/headroom.json b/grafana/dashboards/cmode/headroom.json
index 78c3aa27..63e192ff 100644
--- a/grafana/dashboards/cmode/headroom.json
+++ b/grafana/dashboards/cmode/headroom.json
@@ -2576,7 +2576,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {},
diff --git a/grafana/dashboards/cmode/health.json b/grafana/dashboards/cmode/health.json
index a671b695..ef693f76 100644
--- a/grafana/dashboards/cmode/health.json
+++ b/grafana/dashboards/cmode/health.json
@@ -3244,7 +3244,7 @@
     ]
   },
   "time": {
-    "from": "now-24h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/lun.json b/grafana/dashboards/cmode/lun.json
index e2068b63..5d08e5a5 100644
--- a/grafana/dashboards/cmode/lun.json
+++ b/grafana/dashboards/cmode/lun.json
@@ -5359,7 +5359,7 @@
     ]
   },
   "time": {
-    "from": "now-1h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/mcc_cluster.json b/grafana/dashboards/cmode/mcc_cluster.json
index 50695039..5e21b379 100644
--- a/grafana/dashboards/cmode/mcc_cluster.json
+++ b/grafana/dashboards/cmode/mcc_cluster.json
@@ -3780,7 +3780,7 @@
     ]
   },
   "time": {
-    "from": "now-30m",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/namespace.json b/grafana/dashboards/cmode/namespace.json
index 62421d5a..46ce473b 100644
--- a/grafana/dashboards/cmode/namespace.json
+++ b/grafana/dashboards/cmode/namespace.json
@@ -1295,7 +1295,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/nfs4storePool.json b/grafana/dashboards/cmode/nfs4storePool.json
index 28050345..97ddcc55 100644
--- a/grafana/dashboards/cmode/nfs4storePool.json
+++ b/grafana/dashboards/cmode/nfs4storePool.json
@@ -2115,7 +2115,7 @@
     ]
   },
   "time": {
-    "from": "now-1h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {},
diff --git a/grafana/dashboards/cmode/nfs_clients.json b/grafana/dashboards/cmode/nfs_clients.json
index a5e46a82..0ac6dc5a 100644
--- a/grafana/dashboards/cmode/nfs_clients.json
+++ b/grafana/dashboards/cmode/nfs_clients.json
@@ -558,7 +558,7 @@
     ]
   },
   "time": {
-    "from": "now-30m",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/node.json b/grafana/dashboards/cmode/node.json
index d00c4fd6..b551b8aa 100644
--- a/grafana/dashboards/cmode/node.json
+++ b/grafana/dashboards/cmode/node.json
@@ -4998,7 +4998,7 @@
     ]
   },
   "time": {
-    "from": "now-24h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/qtree.json b/grafana/dashboards/cmode/qtree.json
index f4e7dbd0..0930a45e 100644
--- a/grafana/dashboards/cmode/qtree.json
+++ b/grafana/dashboards/cmode/qtree.json
@@ -1120,7 +1120,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/quotaReport.json b/grafana/dashboards/cmode/quotaReport.json
index 8236ceb2..75770cb2 100644
--- a/grafana/dashboards/cmode/quotaReport.json
+++ b/grafana/dashboards/cmode/quotaReport.json
@@ -761,7 +761,7 @@
     ]
   },
   "time": {
-    "from": "now-5m",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/s3ObjectStorage.json b/grafana/dashboards/cmode/s3ObjectStorage.json
index e226f629..a36fe1dc 100644
--- a/grafana/dashboards/cmode/s3ObjectStorage.json
+++ b/grafana/dashboards/cmode/s3ObjectStorage.json
@@ -1003,7 +1003,7 @@
     ]
   },
   "time": {
-    "from": "now-5m",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/security.json b/grafana/dashboards/cmode/security.json
index 8240a510..70857e7b 100644
--- a/grafana/dashboards/cmode/security.json
+++ b/grafana/dashboards/cmode/security.json
@@ -4856,7 +4856,7 @@
     ]
   },
   "time": {
-    "from": "now-1m",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/volume.json b/grafana/dashboards/cmode/volume.json
index cf815eb6..cb98c96a 100644
--- a/grafana/dashboards/cmode/volume.json
+++ b/grafana/dashboards/cmode/volume.json
@@ -6965,7 +6965,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/cmode/workload.json b/grafana/dashboards/cmode/workload.json
index 83e2aa60..b10bb54f 100644
--- a/grafana/dashboards/cmode/workload.json
+++ b/grafana/dashboards/cmode/workload.json
@@ -2470,7 +2470,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {
diff --git a/grafana/dashboards/storagegrid/fabricpool.json b/grafana/dashboards/storagegrid/fabricpool.json
index d0a32a4e..f6593b90 100644
--- a/grafana/dashboards/storagegrid/fabricpool.json
+++ b/grafana/dashboards/storagegrid/fabricpool.json
@@ -1941,7 +1941,7 @@
     ]
   },
   "time": {
-    "from": "now-24h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {},
diff --git a/grafana/dashboards/storagegrid/overview.json b/grafana/dashboards/storagegrid/overview.json
index fd84cb4f..c7c849c7 100644
--- a/grafana/dashboards/storagegrid/overview.json
+++ b/grafana/dashboards/storagegrid/overview.json
@@ -2516,7 +2516,7 @@
     ]
   },
   "time": {
-    "from": "now-6h",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {},
diff --git a/grafana/dashboards/storagegrid/tenant.json b/grafana/dashboards/storagegrid/tenant.json
index ca55545b..e9d7a04b 100644
--- a/grafana/dashboards/storagegrid/tenant.json
+++ b/grafana/dashboards/storagegrid/tenant.json
@@ -570,7 +570,7 @@
     ]
   },
   "time": {
-    "from": "now-30m",
+    "from": "now-3h",
     "to": "now"
   },
   "timepicker": {},


Test patch:
diff --git a/cmd/tools/grafana/dashboard_test.go b/cmd/tools/grafana/dashboard_test.go
index 91c30732..db7a5162 100644
--- a/cmd/tools/grafana/dashboard_test.go
+++ b/cmd/tools/grafana/dashboard_test.go
@@ -1212,3 +1212,24 @@ func writeSorted(t *testing.T, path string, sorted []byte) string {
 	create.Close()
 	return dest
 }
+
+func TestDashboardTime(t *testing.T) {
+	visitDashboards(dashboards, func(path string, data []byte) {
+		checkDashboardTime(t, path, data)
+	})
+}
+
+func checkDashboardTime(t *testing.T, path string, data []byte) {
+	dashPath := shortPath(path)
+	from := gjson.GetBytes(data, "time.from")
+	to := gjson.GetBytes(data, "time.to")
+
+	fromWant := "now-3h"
+	toWant := "now"
+	if from.String() != fromWant {
+		t.Errorf("dashboard=%s time.from got=%s want=%s", dashPath, from.String(), fromWant)
+	}
+	if to.String() != toWant {
+		t.Errorf("dashboard=%s time.to got=%s want=%s", dashPath, to.String(), toWant)
+	}
+}