-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to functions and combine files
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
- Loading branch information
1 parent
7835f9d
commit 969d235
Showing
9 changed files
with
190 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-kit/log/level" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var contextCmd = &cobra.Command{ | ||
Use: "context", | ||
Short: "View/Add/Edit context configuration.", | ||
Long: "View/Add/Edit context configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "context called") | ||
}, | ||
} | ||
func NewContextCommand(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "context", | ||
Short: "View/Add/Edit context configuration.", | ||
Long: "View/Add/Edit context configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "context called") | ||
}, | ||
} | ||
|
||
var contextApiCmd = &cobra.Command{ | ||
Use: "api", | ||
Short: "Add/edit API configuration.", | ||
Long: "Add/edit API configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "api called") | ||
}, | ||
} | ||
var contextSwitchCmd = &cobra.Command{ | ||
Use: "switch", | ||
Short: "Switch to another context.", | ||
Long: "View/Add/Edit context configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "switch called") | ||
}, | ||
} | ||
var contextCurrentCmd = &cobra.Command{ | ||
Use: "current", | ||
Short: "View current context configuration.", | ||
Long: "View current context configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "current called") | ||
}, | ||
} | ||
apiCmd := &cobra.Command{ | ||
Use: "api", | ||
Short: "Add/edit API configuration.", | ||
Long: "Add/edit API configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "api called") | ||
}, | ||
} | ||
switchCmd := &cobra.Command{ | ||
Use: "switch", | ||
Short: "Switch to another context.", | ||
Long: "View/Add/Edit context configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "switch called") | ||
}, | ||
} | ||
currentCmd := &cobra.Command{ | ||
Use: "current", | ||
Short: "View current context configuration.", | ||
Long: "View current context configuration.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "current called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(contextCmd) | ||
cmd.AddCommand(apiCmd) | ||
cmd.AddCommand(switchCmd) | ||
cmd.AddCommand(currentCmd) | ||
|
||
contextCmd.AddCommand(contextApiCmd) | ||
contextCmd.AddCommand(contextSwitchCmd) | ||
contextCmd.AddCommand(contextCurrentCmd) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-kit/log/level" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var loginCmd = &cobra.Command{ | ||
Use: "login", | ||
Short: "Login as a tenant. Will also save tenant details locally.", | ||
Long: "Login as a tenant. Will also save tenant details locally.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "login called") | ||
}, | ||
} | ||
func NewLoginCmd(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "login", | ||
Short: "Login as a tenant. Will also save tenant details locally.", | ||
Long: "Login as a tenant. Will also save tenant details locally.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "login called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(loginCmd) | ||
cmd.Flags().String("tenant", "", "The name of the tenant.") | ||
cmd.Flags().String("api", "", "The URL or name of the Observatorium API.") | ||
cmd.Flags().String("ca", "", "Path to the TLS CA against which to verify the Observatorium API. If no server CA is specified, the client will use the system certificates.") | ||
cmd.Flags().String("oidc.issuer-url", "", "The OIDC issuer URL, see https://openid.net/specs/openid-connect-discovery-1_0.html#IssuerDiscovery.") | ||
cmd.Flags().String("oidc.client-secret", "", "The OIDC client secret, see https://tools.ietf.org/html/rfc6749#section-2.3.") | ||
cmd.Flags().String("oidc.client-id", "", "The OIDC client ID, see https://tools.ietf.org/html/rfc6749#section-2.3.") | ||
cmd.Flags().String("oidc.audience", "", "The audience for whom the access token is intended, see https://openid.net/specs/openid-connect-core-1_0.html#IDToken.") | ||
|
||
loginCmd.Flags().String("tenant", "", "The name of the tenant.") | ||
loginCmd.Flags().String("api", "", "The URL or name of the Observatorium API.") | ||
loginCmd.Flags().String("ca", "", "Path to the TLS CA against which to verify the Observatorium API. If no server CA is specified, the client will use the system certificates.") | ||
loginCmd.Flags().String("oidc.issuer-url", "", "The OIDC issuer URL, see https://openid.net/specs/openid-connect-discovery-1_0.html#IssuerDiscovery.") | ||
loginCmd.Flags().String("oidc.client-secret", "", "The OIDC client secret, see https://tools.ietf.org/html/rfc6749#section-2.3.") | ||
loginCmd.Flags().String("oidc.client-id", "", "The OIDC client ID, see https://tools.ietf.org/html/rfc6749#section-2.3.") | ||
loginCmd.Flags().String("oidc.audience", "", "The audience for whom the access token is intended, see https://openid.net/specs/openid-connect-core-1_0.html#IDToken.") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,119 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-kit/log/level" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var metricsCmd = &cobra.Command{ | ||
Use: "metrics", | ||
Short: "Metrics based operations for Observatorium.", | ||
Long: "Metrics based operations for Observatorium.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "metrics called") | ||
}, | ||
func NewMetricsGetCmd(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get", | ||
Short: "Read series, labels & rules (JSON/YAML) of a tenant.", | ||
Long: "Read series, labels & rules (JSON/YAML) of a tenant.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "get called") | ||
}, | ||
} | ||
|
||
seriesCmd := &cobra.Command{ | ||
Use: "series", | ||
Short: "Get series of a tenant.", | ||
Long: "Get series of a tenant..", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "series called") | ||
}, | ||
} | ||
|
||
labelsCmd := &cobra.Command{ | ||
Use: "labels", | ||
Short: "Get labels of a tenant.", | ||
Long: "Get labels of a tenant.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "labels called") | ||
}, | ||
} | ||
|
||
labelValuesCmd := &cobra.Command{ | ||
Use: "labelvalues", | ||
Short: "Get label values of a tenant.", | ||
Long: "Get label values of a tenant.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "label values called") | ||
}, | ||
} | ||
|
||
rulesCmd := &cobra.Command{ | ||
Use: "rules", | ||
Short: "Get rules of a tenant.", | ||
Long: "Get rules of a tenant.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "rules called") | ||
}, | ||
} | ||
|
||
rulesRawCmd := &cobra.Command{ | ||
Use: "rules.raw", | ||
Short: "Get configured rules of a tenant.", | ||
Long: "Get configured rules of a tenant.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "rules.raw called") | ||
}, | ||
} | ||
|
||
cmd.AddCommand(seriesCmd) | ||
cmd.AddCommand(labelsCmd) | ||
cmd.AddCommand(labelValuesCmd) | ||
cmd.AddCommand(rulesCmd) | ||
cmd.AddCommand(rulesRawCmd) | ||
|
||
return cmd | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(metricsCmd) | ||
func NewMetricsSetCmd(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "set", | ||
Short: "Write Prometheus Rules configuration for a tenant.", | ||
Long: "Write Prometheus Rules configuration for a tenant.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "set called") | ||
}, | ||
} | ||
|
||
cmd.Flags().String("rule.file", "", "Path to Rules configuration file, which will be set for a tenant.") | ||
|
||
return cmd | ||
} | ||
|
||
func NewMetricsQueryCmd(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "query", | ||
Short: "Query metrics for a tenant.", | ||
Long: "Query metrics for a tenant. Pass a single valid PromQL query to fetch results for.", | ||
Example: `obsctl query "prometheus_http_request_total"`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "query called") | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func NewMetricsCmd(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "metrics", | ||
Short: "Metrics based operations for Observatorium.", | ||
Long: "Metrics based operations for Observatorium.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
level.Info(logger).Log("msg", "metrics called") | ||
}, | ||
} | ||
|
||
cmd.AddCommand(NewMetricsGetCmd(ctx)) | ||
cmd.AddCommand(NewMetricsSetCmd(ctx)) | ||
cmd.AddCommand(NewMetricsQueryCmd(ctx)) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.