Skip to content

Commit

Permalink
Refer to remote dashboard files through --url
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha committed Mar 12, 2024
1 parent 3410dd4 commit 2d1a52e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 10 additions & 2 deletions pkg/cmds/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -140,27 +140,35 @@ 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",
Short: i18n.T("Check availability of a grafana dashboard"),
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,
DisableAutoGenTag: true,
}
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
}

Expand Down
14 changes: 8 additions & 6 deletions pkg/monitor/dashboard/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
}

Expand Down

0 comments on commit 2d1a52e

Please sign in to comment.