Skip to content

Commit

Permalink
Merge pull request #120 from MitaliBhalla/OSD-16073
Browse files Browse the repository at this point in the history
OSD-16073 backplane-cli support for monitoring stack for layered…
  • Loading branch information
openshift-merge-robot authored Jun 14, 2023
2 parents d933c9e + 79591c0 commit ac6eef6
Show file tree
Hide file tree
Showing 6 changed files with 724 additions and 15 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ To setup the PS1(prompt) for bash/zsh, please follow [these instructions](https:
| `ocm backplane cloud console` | Launch the current logged in cluster's cloud provider console |
| `ocm backplane cloud credentials [flags]` | Retrieve a set of temporary cloud credentials for the cluster's cloud provider |
| `ocm backplane elevate <reason> -- <command>` | Elevate privileges to backplane-cluster-admin and add a reason to the api request |
| `ocm-backplane monitoring <prometheus/alertmanager/thanos/grafana> [flags]` | Launch the specified monitoring UI (Deprecated following v4.11) |
| `ocm-backplane script describe <script> [flags]` | Describe the given backplane script |
| `ocm-backplane script list [flags]` | List available backplane scripts |
| `ocm-backplane status` | Print essential cluster info |
| `ocm-backplane managedJob create <script> [flags]` | Create a backplane managed job resource |
| `ocm-backplane managedJob get <job_name> [flags]` | Retrieve a backplane managed job resource |
| `ocm-backplane managedJob list [flags]` | Retrieve a list of backplane managed job resources |
| `ocm-backplane managedJob logs <job_name> [flags]` | Retrieve logs of the specified managed job resource |
| `ocm-backplane managedJob delete <job_name> [flags]` | Delete the specified managed job resource |
| `ocm-backplane testJob create <script> [flags]` | Create a backplane test managed job on a non-production cluster for testing. To use with bash libraries, make sure the libraries are in the scripts directory in the format `source /managed-scripts/<path-from-managed-scripts-scripts-dir>` |
| `ocm-backplane testJob get <job_name> [flags]` | Retrieve a backplane test job resource |
| `ocm-backplane testJob list [flags]` | Retrieve a list of backplane test job resources |
| `ocm-backplane testJob logs <job_name> [flags]` | Retrieve logs of the specified test job resource |
| `ocm-backplane upgrade` | Upgrade backplane-cli to the latest version |
| `ocm-backplane version` | Display the installed backplane-cli version |
| `ocm backplane monitoring <prometheus/alertmanager/thanos/grafana> [flags]` | Launch the specified monitoring UI (Deprecated following v4.11 for cluster monitoring stack) |
| `ocm backplane script describe <script> [flags]` | Describe the given backplane script |
| `ocm backplane script list [flags]` | List available backplane scripts |
| `ocm backplane status` | Print essential cluster info |
| `ocm backplane managedJob create <script> [flags]` | Create a backplane managed job resource |
| `ocm backplane managedJob get <job_name> [flags]` | Retrieve a backplane managed job resource |
| `ocm backplane managedJob list [flags]` | Retrieve a list of backplane managed job resources |
| `ocm backplane managedJob logs <job_name> [flags]` | Retrieve logs of the specified managed job resource |
| `ocm backplane managedJob delete <job_name> [flags]` | Delete the specified managed job resource |
| `ocm backplane testJob create <script> [flags]` | Create a backplane test managed job on a non-production cluster for testing. To use with bash libraries, make sure the libraries are in the scripts directory in the format `source /managed-scripts/<path-from-managed-scripts-scripts-dir>` |
| `ocm backplane testJob get <job_name> [flags]` | Retrieve a backplane test job resource |
| `ocm backplane testJob list [flags]` | Retrieve a list of backplane test job resources |
| `ocm backplane testJob logs <job_name> [flags]` | Retrieve logs of the specified test job resource |
| `ocm backplane upgrade` | Upgrade backplane-cli to the latest version |
| `ocm backplane version` | Display the installed backplane-cli version |

## Login

Expand Down Expand Up @@ -184,7 +184,16 @@ Logging into multiple clusters via different terminal instances.
$ export BACKPLANE_DEFAULT_OPEN_BROWSER=true
$ ocm backplane cloud console
`
## Monitoring
Monitoring command can be used to launch the specified monitoring UI.
Run this command from within a cluster :
```
ocm backplane monitoring <prometheus/alertmanager/thanos/grafana> [flags]
```
>Note: Following version 4.11, Prometheus, AlertManager and Grafana monitoring UIs are deprecated for openshift-monitoring stack, please use 'ocm backplane console' and use the observe tab for the same. Other monitoring stacks remain unaffected.
## Backplane Session
Backplane session command will create an isolated environment to interact with a cluster in its own directory.
The default location for this is ~/backplane.
Expand Down
74 changes: 74 additions & 0 deletions cmd/ocm-backplane/monitoring/monitoring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package monitoring

import (
"fmt"
"net/http"
"strings"

"github.com/openshift/backplane-cli/pkg/monitoring"
"github.com/spf13/cobra"
)

var MonitoringCmd = &cobra.Command{
Use: fmt.Sprintf("monitoring <%s>", strings.Join(monitoring.ValidMonitoringNames, "|")),
Short: "Create a local proxy to the monitoring UI",
Long: fmt.Sprintf(`It will proxy to the monitoring UI including %s.`, strings.Join(monitoring.ValidMonitoringNames, ",")),
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
ValidArgs: monitoring.ValidMonitoringNames,
RunE: runMonitoring,
SilenceUsage: true,
}

func init() {
flags := MonitoringCmd.Flags()
flags.BoolVarP(
&monitoring.MonitoringOpts.Browser,
"browser",
"b",
false,
"Open the browser automatically.",
)
flags.StringVarP(
&monitoring.MonitoringOpts.Namespace,
"namespace",
"n",
"openshift-monitoring",
"Specify namespace of monitoring stack.",
)
flags.StringVarP(
&monitoring.MonitoringOpts.Selector,
"selector",
"l",
"",
"Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2).",
)
flags.StringVarP(
&monitoring.MonitoringOpts.Port,
"port",
"p",
"",
"The port the remote application listens on. (Default will be picked by server based on application's conventional port.)",
)
flags.StringVarP(
&monitoring.MonitoringOpts.OriginUrl,
"origin",
"u",
"",
"The original url. Eg, copied from the prometheus url in pagerduty. When specified, it will print the proxied url of the corresponding original url.",
)
flags.StringVar(
&monitoring.MonitoringOpts.ListenAddr,
"listen",
"",
"The local address to listen to. Recommend using 127.0.0.1:xxxx to minimize security risk. The default will pick a random port on 127.0.0.1",
)

}

// runMonitoring create local proxy url to serve monitoring dashboard
func runMonitoring(cmd *cobra.Command, argv []string) error {
monitoringType := argv[0]
monitoring.MonitoringOpts.KeepAlive = true
client := monitoring.NewClient("", http.Client{})
return client.RunMonitoring(monitoringType)
}
2 changes: 2 additions & 0 deletions cmd/ocm-backplane/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/openshift/backplane-cli/cmd/ocm-backplane/login"
"github.com/openshift/backplane-cli/cmd/ocm-backplane/logout"
"github.com/openshift/backplane-cli/cmd/ocm-backplane/managedJob"
"github.com/openshift/backplane-cli/cmd/ocm-backplane/monitoring"
"github.com/openshift/backplane-cli/cmd/ocm-backplane/script"
"github.com/openshift/backplane-cli/cmd/ocm-backplane/session"
"github.com/openshift/backplane-cli/cmd/ocm-backplane/status"
Expand Down Expand Up @@ -103,4 +104,5 @@ func init() {
rootCmd.AddCommand(testJob.NewTestJobCommand())
rootCmd.AddCommand(upgrade.UpgradeCmd)
rootCmd.AddCommand(version.VersionCmd)
rootCmd.AddCommand(monitoring.MonitoringCmd)
}
Loading

0 comments on commit ac6eef6

Please sign in to comment.