From 2d1a52e38829518cfb73a9739542ad83a68928b9 Mon Sep 17 00:00:00 2001 From: Arnob kumar saha Date: Tue, 12 Mar 2024 10:57:37 +0600 Subject: [PATCH] Refer to remote dashboard files through `--url` Signed-off-by: Arnob kumar saha --- pkg/cmds/monitor.go | 12 ++++++++++-- pkg/monitor/dashboard/db.go | 14 ++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pkg/cmds/monitor.go b/pkg/cmds/monitor.go index 3d00ecc93..3af75a140 100644 --- a/pkg/cmds/monitor.go +++ b/pkg/cmds/monitor.go @@ -122,7 +122,7 @@ var dashboardLong = templates.LongDesc(` var dashboardExample = templates.Examples(` kubectl dba monitor dashboard [DATABASE] [DATABASE_NAME] -n [NAMESPACE] \ - [DASHBOARD_NAME] --file=[FILE_CONTAINING_DASHBOARD_JSON] \ + [DASHBOARD_NAME] --file=[FILE_CONTAINING_DASHBOARD_JSON] --file=[FILE_CONTAINING_REMOTE_URL] \ <- these are ORed --prom-svc-name=[PROM_SVC_NAME] --prom-svc-namespace=[PROM_SVC_NS] --prom-svc-port=[PROM_SVC_PORT] # Check availability of a postgres grafana dashboard @@ -140,12 +140,18 @@ var dashboardExample = templates.Examples(` * postgres * proxysql * redis + + If --file is given, that is the local file. absolute or relative path both accepted. + If --url is given, that is the remote file. You have to specify the full raw url. + If just the dashboard name is given, then that will be searched in our dashboard repo. To be exact if mongodb-summary-dashboard specified only, The cli will look for the json in + https://raw.githubusercontent.com/appscode/grafana-dashboards/master/mongodb/mongodb-summary-dashboard.json `) func DashboardCMD(f cmdutil.Factory) *cobra.Command { var ( branch string file string + url string ) cmd := &cobra.Command{ Use: "dashboard", @@ -153,7 +159,7 @@ func DashboardCMD(f cmdutil.Factory) *cobra.Command { Long: dashboardLong, Run: func(cmd *cobra.Command, args []string) { - dashboard.Run(f, args, branch, file, prom) + dashboard.Run(f, args, branch, file, url, prom) }, Example: dashboardExample, DisableFlagsInUseLine: true, @@ -161,6 +167,8 @@ func DashboardCMD(f cmdutil.Factory) *cobra.Command { } cmd.Flags().StringVarP(&branch, "branch", "b", "master", "branch name of the github repo") cmd.Flags().StringVarP(&file, "file", "f", "", "absolute or relative path of the file containing dashboard") + cmd.Flags().StringVarP(&url, "url", "u", "", "url of the raw file containing dashboard. "+ + "For example: https://raw.githubusercontent.com/appscode/grafana-dashboards/master/mongodb/mongodb-summary-dashboard.json") return cmd } diff --git a/pkg/monitor/dashboard/db.go b/pkg/monitor/dashboard/db.go index 2d2b4d9b4..5837cc22c 100644 --- a/pkg/monitor/dashboard/db.go +++ b/pkg/monitor/dashboard/db.go @@ -40,7 +40,7 @@ type missingOpts struct { panelTitle []string } -func Run(f cmdutil.Factory, args []string, branch, file string, prom monitor.PromSvc) { +func Run(f cmdutil.Factory, args []string, branch, file, url string, prom monitor.PromSvc) { if len(args) < 2 { log.Fatal("Enter db object's name as an argument") } @@ -61,13 +61,15 @@ func Run(f cmdutil.Factory, args []string, branch, file string, prom monitor.Pro database = monitor.ConvertedResourceToSingular(database) var dashboardData map[string]interface{} if file == "" { - if len(args) < 3 { - log.Fatal("Enter dashboard name as third argument") + if url == "" { // fetch from appscode/grafana-dashboard repo + if len(args) < 3 { + log.Fatal("Enter dashboard name as third argument") + } + dashboard := args[2] + url = getURL(branch, database, dashboard) } - dashboard := args[2] - url := getURL(branch, database, dashboard) dashboardData = getDashboardFromURL(url) - } else { + } else { // the file is local dashboardData = getDashboardFromFile(file) }