diff --git a/cmd/scw/testdata/test-all-usage-cockpit-cockpit-get-metrics-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-cockpit-get-metrics-usage.golden new file mode 100644 index 0000000000..99a0d6c45a --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-cockpit-cockpit-get-metrics-usage.golden @@ -0,0 +1,21 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Get the cockpit metrics with the given project ID. + +USAGE: + scw cockpit cockpit get-metrics [arg=value ...] + +ARGS: + [project-id] Project ID to use. If none is passed the default project ID will be used + [start-date] Start date + [end-date] End date + [metric-name] Metric name + +FLAGS: + -h, --help help for get-metrics + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-cockpit-cockpit-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-cockpit-usage.golden index b223370186..b45cf8b88e 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-cockpit-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-cockpit-usage.golden @@ -9,6 +9,7 @@ AVAILABLE COMMANDS: activate Activate a cockpit deactivate Deactivate a cockpit get Get cockpit + get-metrics Get cockpit metrics reset-grafana Reset Grafana WORKFLOW COMMANDS: diff --git a/docs/commands/cockpit.md b/docs/commands/cockpit.md index 125a554067..3d7da2b0fa 100644 --- a/docs/commands/cockpit.md +++ b/docs/commands/cockpit.md @@ -10,6 +10,7 @@ Cockpit API. - [Activate a cockpit](#activate-a-cockpit) - [Deactivate a cockpit](#deactivate-a-cockpit) - [Get cockpit](#get-cockpit) + - [Get cockpit metrics](#get-cockpit-metrics) - [Reset Grafana](#reset-grafana) - [Wait for a cockpit to reach a stable state (installation)](#wait-for-a-cockpit-to-reach-a-stable-state-(installation)) - [Contacts management commands](#contacts-management-commands) @@ -152,6 +153,28 @@ scw cockpit cockpit get [arg=value ...] +### Get cockpit metrics + +Get the cockpit metrics with the given project ID. + +**Usage:** + +``` +scw cockpit cockpit get-metrics [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| project-id | | Project ID to use. If none is passed the default project ID will be used | +| start-date | | Start date | +| end-date | | End date | +| metric-name | | Metric name | + + + ### Reset Grafana Reset the Grafana of your cockpit associated with the given project ID. diff --git a/go.mod b/go.mod index 42aa6d09dd..a09972c6e2 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/moby/buildkit v0.11.5 github.com/opencontainers/go-digest v1.0.0 github.com/pkg/errors v0.9.1 - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.15.0.20230327160534-01e8b89ed721 + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.15.0.20230328152143-e7dd9eaf36ab github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.2 diff --git a/go.sum b/go.sum index fedd7640a5..a7abec3746 100644 --- a/go.sum +++ b/go.sum @@ -275,8 +275,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.15.0.20230327160534-01e8b89ed721 h1:sH3/HWBjaFYFuWnmA2biULFcq6KTc1OP3cdz/OPMhAI= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.15.0.20230327160534-01e8b89ed721/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.15.0.20230328152143-e7dd9eaf36ab h1:VCye3DHBTXfYxCi014GkRliIOvKImUBySvyHwIROCaE= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.15.0.20230328152143-e7dd9eaf36ab/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= diff --git a/internal/namespaces/cockpit/v1beta1/cockpit_cli.go b/internal/namespaces/cockpit/v1beta1/cockpit_cli.go index 396c2fce79..f60012962c 100644 --- a/internal/namespaces/cockpit/v1beta1/cockpit_cli.go +++ b/internal/namespaces/cockpit/v1beta1/cockpit_cli.go @@ -27,6 +27,7 @@ func GetGeneratedCommands() *core.Commands { cockpitContact(), cockpitCockpitActivate(), cockpitCockpitGet(), + cockpitCockpitGetMetrics(), cockpitCockpitDeactivate(), cockpitCockpitResetGrafana(), cockpitTokenCreate(), @@ -144,6 +145,50 @@ func cockpitCockpitGet() *core.Command { } } +func cockpitCockpitGetMetrics() *core.Command { + return &core.Command{ + Short: `Get cockpit metrics`, + Long: `Get the cockpit metrics with the given project ID.`, + Namespace: "cockpit", + Resource: "cockpit", + Verb: "get-metrics", + // Deprecated: false, + ArgsType: reflect.TypeOf(cockpit.GetCockpitMetricsRequest{}), + ArgSpecs: core.ArgSpecs{ + core.ProjectIDArgSpec(), + { + Name: "start-date", + Short: `Start date`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "end-date", + Short: `End date`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "metric-name", + Short: `Metric name`, + Required: false, + Deprecated: false, + Positional: false, + }, + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*cockpit.GetCockpitMetricsRequest) + + client := core.ExtractClient(ctx) + api := cockpit.NewAPI(client) + return api.GetCockpitMetrics(request) + + }, + } +} + func cockpitCockpitDeactivate() *core.Command { return &core.Command{ Short: `Deactivate a cockpit`,