From 5976d1b002996ea3acdab3be85195cedaa7bb9d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Mon, 22 Apr 2024 09:53:18 +0200 Subject: [PATCH 1/4] implement command and testing --- docs/stackit_argus_scrape-configs.md | 1 + docs/stackit_argus_scrape-configs_create.md | 55 +++ .../cmd/argus/scrape-configs/create/create.go | 166 ++++++++++ .../scrape-configs/create/create_test.go | 312 ++++++++++++++++++ .../argus/scrape-configs/scrape_configs.go | 2 + 5 files changed, 536 insertions(+) create mode 100644 docs/stackit_argus_scrape-configs_create.md create mode 100644 internal/cmd/argus/scrape-configs/create/create.go create mode 100644 internal/cmd/argus/scrape-configs/create/create_test.go diff --git a/docs/stackit_argus_scrape-configs.md b/docs/stackit_argus_scrape-configs.md index 73d9455d8..4072d11e5 100644 --- a/docs/stackit_argus_scrape-configs.md +++ b/docs/stackit_argus_scrape-configs.md @@ -29,5 +29,6 @@ stackit argus scrape-configs [flags] ### SEE ALSO * [stackit argus](./stackit_argus.md) - Provides functionality for Argus +* [stackit argus scrape-configs create](./stackit_argus_scrape-configs_create.md) - Creates a Scrape Config Job for an Argus instance * [stackit argus scrape-configs generate-payload](./stackit_argus_scrape-configs_generate-payload.md) - Generates a payload to create/update Scrape Configurations for an Argus instance diff --git a/docs/stackit_argus_scrape-configs_create.md b/docs/stackit_argus_scrape-configs_create.md new file mode 100644 index 000000000..d88318403 --- /dev/null +++ b/docs/stackit_argus_scrape-configs_create.md @@ -0,0 +1,55 @@ +## stackit argus scrape-configs create + +Creates a Scrape Config Job for an Argus instance + +### Synopsis + +Creates a Scrape Config Job for an Argus instance. +The payload can be provided as a JSON string or a file path prefixed with "@". +If no payload is provided, a default payload will be used. +See https://docs.api.stackit.cloud/documentation/argus/version/v1#tag/scrape-config/operation/v1_projects_instances_scrapeconfigs_create for information regarding the payload structure. + +``` +stackit argus scrape-configs create [flags] +``` + +### Examples + +``` + Create a Scrape Config job using default configuration + $ stackit argus scrape-configs create + + Create a Scrape Config job using an API payload sourced from the file "./payload.json" + $ stackit argus scrape-configs create --payload @./payload.json + + Create a Scrape Config job using an API payload provided as a JSON string + $ stackit argus scrape-configs create --payload "{...}" + + Generate a payload with default values, and adapt it with custom values for the different configuration options + $ stackit argus scrape-configs generate-payload > ./payload.json + + $ stackit argus scrape-configs create --payload @./payload.json +``` + +### Options + +``` + -h, --help Help for "stackit argus scrape-configs create" + --instance-id string Instance ID + --payload string Request payload (JSON). Can be a string or a file path, if prefixed with "@" (example: @./payload.json). If unset, will use a default payload (you can check it by running "stackit argus scrape-configs generate-payload") +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") +``` + +### SEE ALSO + +* [stackit argus scrape-configs](./stackit_argus_scrape-configs.md) - Provides functionality for scrape configs in Argus. + diff --git a/internal/cmd/argus/scrape-configs/create/create.go b/internal/cmd/argus/scrape-configs/create/create.go new file mode 100644 index 000000000..e59fe6c3f --- /dev/null +++ b/internal/cmd/argus/scrape-configs/create/create.go @@ -0,0 +1,166 @@ +package create + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" + argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" + + "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-sdk-go/services/argus" + "github.com/stackitcloud/stackit-sdk-go/services/argus/wait" +) + +const ( + payloadFlag = "payload" + instanceIdFlag = "instance-id" +) + +type inputModel struct { + *globalflags.GlobalFlagModel + InstanceId string + Payload *argus.CreateScrapeConfigPayload +} + +func NewCmd(p *print.Printer) *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Short: "Creates a Scrape Config Job for an Argus instance", + Long: fmt.Sprintf("%s\n%s\n%s\n%s", + "Creates a Scrape Config Job for an Argus instance.", + "The payload can be provided as a JSON string or a file path prefixed with \"@\".", + "If no payload is provided, a default payload will be used.", + "See https://docs.api.stackit.cloud/documentation/argus/version/v1#tag/scrape-config/operation/v1_projects_instances_scrapeconfigs_create for information regarding the payload structure.", + ), + Args: args.NoArgs, + Example: examples.Build( + examples.NewExample( + `Create a Scrape Config job using default configuration`, + "$ stackit argus scrape-configs create"), + examples.NewExample( + `Create a Scrape Config job using an API payload sourced from the file "./payload.json"`, + "$ stackit argus scrape-configs create --payload @./payload.json"), + examples.NewExample( + `Create a Scrape Config job using an API payload provided as a JSON string`, + `$ stackit argus scrape-configs create --payload "{...}"`), + examples.NewExample( + `Generate a payload with default values, and adapt it with custom values for the different configuration options`, + `$ stackit argus scrape-configs generate-payload > ./payload.json`, + ``, + `$ stackit argus scrape-configs create --payload @./payload.json`), + ), + RunE: func(cmd *cobra.Command, args []string) error { + ctx := context.Background() + model, err := parseInput(cmd) + if err != nil { + return err + } + + // Configure API client + apiClient, err := client.ConfigureClient(p) + if err != nil { + return err + } + + instanceLabel, err := argusUtils.GetInstanceName(ctx, apiClient, model.InstanceId, model.ProjectId) + if err != nil { + instanceLabel = model.InstanceId + } + + if !model.AssumeYes { + prompt := fmt.Sprintf("Are you sure you want to create a Scrape Config job on Argus instance %q?", instanceLabel) + err = p.PromptForConfirmation(prompt) + if err != nil { + return err + } + } + + // TODO: confirm if it makes sense to check if JobName already exists + + // Fill in default payload, if needed + if model.Payload == nil { + defaultPayload := argusUtils.DefaultCreateScrapeConfigPayload + if err != nil { + return fmt.Errorf("get default payload: %w", err) + } + model.Payload = &defaultPayload + } + + // Call API + req := buildRequest(ctx, model, apiClient) + _, err = req.Execute() + if err != nil { + return fmt.Errorf("create Scrape Config job: %w", err) + } + + jobName := model.Payload.JobName + + // Wait for async operation, if async mode not enabled + if !model.Async { + s := spinner.New(p) + s.Start("Creating scrape config") + _, err = wait.CreateScrapeConfigWaitHandler(ctx, apiClient, model.InstanceId, *jobName, model.ProjectId).WaitWithContext(ctx) + if err != nil { + return fmt.Errorf("wait for Scrape Config job creation: %w", err) + } + s.Stop() + } + + operationState := "Created" + if model.Async { + operationState = "Triggered creation of" + } + p.Outputf("%s Scrape Configuration for Argus instance %q, with job name %q\n", operationState, instanceLabel, *jobName) + return nil + }, + } + configureFlags(cmd) + return cmd +} + +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Var(flags.ReadFromFileFlag(), payloadFlag, `Request payload (JSON). Can be a string or a file path, if prefixed with "@" (example: @./payload.json). If unset, will use a default payload (you can check it by running "stackit argus scrape-configs generate-payload")`) + cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") + + err := flags.MarkFlagsRequired(cmd, instanceIdFlag) + cobra.CheckErr(err) +} + +func parseInput(cmd *cobra.Command) (*inputModel, error) { + globalFlags := globalflags.Parse(cmd) + if globalFlags.ProjectId == "" { + return nil, &errors.ProjectIdError{} + } + + payloadValue := flags.FlagToStringPointer(cmd, payloadFlag) + var payload *argus.CreateScrapeConfigPayload + if payloadValue != nil { + payload = &argus.CreateScrapeConfigPayload{} + err := json.Unmarshal([]byte(*payloadValue), payload) + if err != nil { + return nil, fmt.Errorf("encode payload: %w", err) + } + } + + return &inputModel{ + GlobalFlagModel: globalFlags, + Payload: payload, + InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag), + }, nil +} + +func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APIClient) argus.ApiCreateScrapeConfigRequest { + req := apiClient.CreateScrapeConfig(ctx, model.InstanceId, model.ProjectId) + + req = req.CreateScrapeConfigPayload(*model.Payload) + return req +} diff --git a/internal/cmd/argus/scrape-configs/create/create_test.go b/internal/cmd/argus/scrape-configs/create/create_test.go new file mode 100644 index 000000000..181862653 --- /dev/null +++ b/internal/cmd/argus/scrape-configs/create/create_test.go @@ -0,0 +1,312 @@ +package create + +import ( + "context" + "testing" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/services/argus" +) + +var projectIdFlag = globalflags.ProjectIdFlag + +type testCtxKey struct{} + +var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") +var testClient = &argus.APIClient{} +var testProjectId = uuid.NewString() +var testInstanceId = uuid.NewString() + +var testPayload = &argus.CreateScrapeConfigPayload{ + BasicAuth: &argus.CreateScrapeConfigPayloadBasicAuth{ + Username: utils.Ptr("username"), + Password: utils.Ptr("password"), + }, + BearerToken: utils.Ptr("bearerToken"), + HonorLabels: utils.Ptr(true), + HonorTimeStamps: utils.Ptr(true), + MetricsPath: utils.Ptr("/metrics"), + JobName: utils.Ptr("default-name"), + MetricsRelabelConfigs: &[]argus.CreateScrapeConfigPayloadMetricsRelabelConfigsInner{ + { + Action: utils.Ptr("replace"), + Modulus: utils.Ptr(1.0), + Regex: utils.Ptr("regex"), + Replacement: utils.Ptr("replacement"), + Separator: utils.Ptr("separator"), + SourceLabels: &[]string{"sourceLabel"}, + TargetLabel: utils.Ptr("targetLabel"), + }, + }, + Params: &map[string]interface{}{ + "key": []interface{}{string("value1"), string("value2")}, + "key2": []interface{}{}, + }, + SampleLimit: utils.Ptr(1.0), + Scheme: utils.Ptr("scheme"), + ScrapeInterval: utils.Ptr("interval"), + ScrapeTimeout: utils.Ptr("timeout"), + StaticConfigs: &[]argus.CreateScrapeConfigPayloadStaticConfigsInner{ + { + Labels: &map[string]interface{}{ + "label": "value", + "label2": "value2", + }, + Targets: &[]string{"target"}, + }, + }, + TlsConfig: &argus.CreateScrapeConfigPayloadHttpSdConfigsInnerOauth2TlsConfig{ + InsecureSkipVerify: utils.Ptr(true), + }, +} + +func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { + flagValues := map[string]string{ + projectIdFlag: testProjectId, + instanceIdFlag: testInstanceId, + payloadFlag: `{ + "jobName": "default-name", + "basicAuth": { + "username": "username", + "password": "password" + }, + "bearerToken": "bearerToken", + "honorLabels": true, + "honorTimeStamps": true, + "metricsPath": "/metrics", + "metricsRelabelConfigs": [ + { + "action": "replace", + "modulus": 1.0, + "regex": "regex", + "replacement": "replacement", + "separator": "separator", + "sourceLabels": ["sourceLabel"], + "targetLabel": "targetLabel" + } + ], + "params": { + "key": ["value1", "value2"], + "key2": [] + }, + "sampleLimit": 1.0, + "scheme": "scheme", + "scrapeInterval": "interval", + "scrapeTimeout": "timeout", + "staticConfigs": [ + { + "labels": { + "label": "value", + "label2": "value2" + }, + "targets": ["target"] + } + ], + "tlsConfig": { + "insecureSkipVerify": true + } + }`, + } + for _, mod := range mods { + mod(flagValues) + } + return flagValues +} + +func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { + model := &inputModel{ + GlobalFlagModel: &globalflags.GlobalFlagModel{ + ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, + }, + InstanceId: testInstanceId, + Payload: testPayload, + } + for _, mod := range mods { + mod(model) + } + return model +} + +func fixtureRequest(mods ...func(request *argus.ApiCreateScrapeConfigRequest)) argus.ApiCreateScrapeConfigRequest { + request := testClient.CreateScrapeConfig(testCtx, testInstanceId, testProjectId) + request = request.CreateScrapeConfigPayload(*testPayload) + for _, mod := range mods { + mod(&request) + } + return request +} + +func TestParseInput(t *testing.T) { + tests := []struct { + description string + flagValues map[string]string + isValid bool + expectedModel *inputModel + }{ + { + description: "base", + flagValues: fixtureFlagValues(), + isValid: true, + expectedModel: fixtureInputModel(), + }, + { + description: "no values", + flagValues: map[string]string{}, + isValid: false, + }, + { + description: "no flag values", + flagValues: map[string]string{}, + isValid: false, + }, + { + description: "project id missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, projectIdFlag) + }), + isValid: false, + }, + { + description: "project id invalid 1", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "" + }), + isValid: false, + }, + { + description: "project id invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "invalid-uuid" + }), + isValid: false, + }, + { + description: "instance id missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, instanceIdFlag) + }), + isValid: false, + }, + { + description: "instance id invalid 1", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "" + }), + isValid: false, + }, + { + description: "instance id invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "invalid-uuid" + }), + isValid: false, + }, + { + description: "default config", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, payloadFlag) + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.Payload = nil + }), + }, + { + description: "invalid json", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[payloadFlag] = "not json" + }), + isValid: false, + expectedModel: fixtureInputModel(), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + cmd := NewCmd(nil) + err := globalflags.Configure(cmd.Flags()) + if err != nil { + t.Fatalf("configure global flags: %v", err) + } + + for flag, value := range tt.flagValues { + err := cmd.Flags().Set(flag, value) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("setting flag --%s=%s: %v", flag, value, err) + } + } + + err = cmd.ValidateRequiredFlags() + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error validating flags: %v", err) + } + + err = cmd.ValidateFlagGroups() + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error validating flags: %v", err) + } + + model, err := parseInput(cmd) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error parsing flags: %v", err) + } + + if !tt.isValid { + t.Fatalf("did not fail on invalid input") + } + diff := cmp.Diff(*model, *tt.expectedModel, + cmpopts.EquateComparable(testCtx), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} + +func TestBuildRequest(t *testing.T) { + tests := []struct { + description string + model *inputModel + expectedRequest argus.ApiCreateScrapeConfigRequest + isValid bool + }{ + { + description: "base", + model: fixtureInputModel(), + expectedRequest: fixtureRequest(), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + request := buildRequest(testCtx, tt.model, testClient) + + diff := cmp.Diff(request, tt.expectedRequest, + cmp.AllowUnexported(tt.expectedRequest), + cmpopts.EquateComparable(testCtx), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} diff --git a/internal/cmd/argus/scrape-configs/scrape_configs.go b/internal/cmd/argus/scrape-configs/scrape_configs.go index 83c4fc634..5e01f8028 100644 --- a/internal/cmd/argus/scrape-configs/scrape_configs.go +++ b/internal/cmd/argus/scrape-configs/scrape_configs.go @@ -1,6 +1,7 @@ package scrapeconfigs import ( + "github.com/stackitcloud/stackit-cli/internal/cmd/argus/scrape-configs/create" generatepayload "github.com/stackitcloud/stackit-cli/internal/cmd/argus/scrape-configs/generate-payload" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -23,4 +24,5 @@ func NewCmd(p *print.Printer) *cobra.Command { func addSubcommands(cmd *cobra.Command, p *print.Printer) { cmd.AddCommand(generatepayload.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) } From 1f23f433904fcc04220f9d5658e658f2d4e6e558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Mon, 22 Apr 2024 09:53:48 +0200 Subject: [PATCH 2/4] remove TODO --- internal/cmd/argus/scrape-configs/create/create.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/cmd/argus/scrape-configs/create/create.go b/internal/cmd/argus/scrape-configs/create/create.go index e59fe6c3f..2568e2a58 100644 --- a/internal/cmd/argus/scrape-configs/create/create.go +++ b/internal/cmd/argus/scrape-configs/create/create.go @@ -84,8 +84,6 @@ func NewCmd(p *print.Printer) *cobra.Command { } } - // TODO: confirm if it makes sense to check if JobName already exists - // Fill in default payload, if needed if model.Payload == nil { defaultPayload := argusUtils.DefaultCreateScrapeConfigPayload From 8e63db396a1228c8cf78012fce3b1749886d1605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Mon, 22 Apr 2024 14:59:27 +0200 Subject: [PATCH 3/4] address PR comments --- docs/stackit_argus_scrape-configs.md | 2 +- docs/stackit_argus_scrape-configs_create.md | 16 ++++++++-------- ...it_argus_scrape-configs_generate-payload.md | 2 +- .../cmd/argus/scrape-configs/create/create.go | 18 +++++++++--------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/stackit_argus_scrape-configs.md b/docs/stackit_argus_scrape-configs.md index 4072d11e5..b1ab5f10a 100644 --- a/docs/stackit_argus_scrape-configs.md +++ b/docs/stackit_argus_scrape-configs.md @@ -29,6 +29,6 @@ stackit argus scrape-configs [flags] ### SEE ALSO * [stackit argus](./stackit_argus.md) - Provides functionality for Argus -* [stackit argus scrape-configs create](./stackit_argus_scrape-configs_create.md) - Creates a Scrape Config Job for an Argus instance +* [stackit argus scrape-configs create](./stackit_argus_scrape-configs_create.md) - Creates a Scrape Config job for an Argus instance * [stackit argus scrape-configs generate-payload](./stackit_argus_scrape-configs_generate-payload.md) - Generates a payload to create/update Scrape Configurations for an Argus instance diff --git a/docs/stackit_argus_scrape-configs_create.md b/docs/stackit_argus_scrape-configs_create.md index d88318403..1f52a31bb 100644 --- a/docs/stackit_argus_scrape-configs_create.md +++ b/docs/stackit_argus_scrape-configs_create.md @@ -1,10 +1,10 @@ ## stackit argus scrape-configs create -Creates a Scrape Config Job for an Argus instance +Creates a Scrape Config job for an Argus instance ### Synopsis -Creates a Scrape Config Job for an Argus instance. +Creates a Scrape Config job for an Argus instance. The payload can be provided as a JSON string or a file path prefixed with "@". If no payload is provided, a default payload will be used. See https://docs.api.stackit.cloud/documentation/argus/version/v1#tag/scrape-config/operation/v1_projects_instances_scrapeconfigs_create for information regarding the payload structure. @@ -16,19 +16,19 @@ stackit argus scrape-configs create [flags] ### Examples ``` - Create a Scrape Config job using default configuration + Create a Scrape Config job on Argus instance "xxx" using default configuration $ stackit argus scrape-configs create - Create a Scrape Config job using an API payload sourced from the file "./payload.json" - $ stackit argus scrape-configs create --payload @./payload.json + Create a Scrape Config job on Argus instance "xxx" using an API payload sourced from the file "./payload.json" + $ stackit argus scrape-configs create --payload @./payload.json --instance-id xxx - Create a Scrape Config job using an API payload provided as a JSON string - $ stackit argus scrape-configs create --payload "{...}" + Create a Scrape Config job on Argus instance "xxx" using an API payload provided as a JSON string + $ stackit argus scrape-configs create --payload "{...}" --instance-id xxx Generate a payload with default values, and adapt it with custom values for the different configuration options $ stackit argus scrape-configs generate-payload > ./payload.json - $ stackit argus scrape-configs create --payload @./payload.json + $ stackit argus scrape-configs create --payload @./payload.json --instance-id xxx ``` ### Options diff --git a/docs/stackit_argus_scrape-configs_generate-payload.md b/docs/stackit_argus_scrape-configs_generate-payload.md index fafe0a559..de814025a 100644 --- a/docs/stackit_argus_scrape-configs_generate-payload.md +++ b/docs/stackit_argus_scrape-configs_generate-payload.md @@ -8,7 +8,7 @@ Generates a JSON payload with values to be used as --payload input for Scrape Co This command can be used to generate a payload to update an existing Scrape Config job or to create a new Scrape Config job. To update an existing Scrape Config job, provide the job name and the instance ID of the Argus instance. To obtain a default payload to create a new Scrape Config job, run the command with no flags. -Note that the default values provided, particularly for the job name, the metrics path and URL of the targets, should be changed to your use case. +Note that some of the default values provided, such as the job name, the metrics path and URL of the targets, should be adapted to your use case. See https://docs.api.stackit.cloud/documentation/argus/version/v1#tag/scrape-config/operation/v1_projects_instances_scrapeconfigs_create for information regarding the payload structure. diff --git a/internal/cmd/argus/scrape-configs/create/create.go b/internal/cmd/argus/scrape-configs/create/create.go index 2568e2a58..9e5e192f7 100644 --- a/internal/cmd/argus/scrape-configs/create/create.go +++ b/internal/cmd/argus/scrape-configs/create/create.go @@ -34,9 +34,9 @@ type inputModel struct { func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", - Short: "Creates a Scrape Config Job for an Argus instance", + Short: "Creates a Scrape Config job for an Argus instance", Long: fmt.Sprintf("%s\n%s\n%s\n%s", - "Creates a Scrape Config Job for an Argus instance.", + "Creates a Scrape Config job for an Argus instance.", "The payload can be provided as a JSON string or a file path prefixed with \"@\".", "If no payload is provided, a default payload will be used.", "See https://docs.api.stackit.cloud/documentation/argus/version/v1#tag/scrape-config/operation/v1_projects_instances_scrapeconfigs_create for information regarding the payload structure.", @@ -44,19 +44,19 @@ func NewCmd(p *print.Printer) *cobra.Command { Args: args.NoArgs, Example: examples.Build( examples.NewExample( - `Create a Scrape Config job using default configuration`, + `Create a Scrape Config job on Argus instance "xxx" using default configuration`, "$ stackit argus scrape-configs create"), examples.NewExample( - `Create a Scrape Config job using an API payload sourced from the file "./payload.json"`, - "$ stackit argus scrape-configs create --payload @./payload.json"), + `Create a Scrape Config job on Argus instance "xxx" using an API payload sourced from the file "./payload.json"`, + "$ stackit argus scrape-configs create --payload @./payload.json --instance-id xxx"), examples.NewExample( - `Create a Scrape Config job using an API payload provided as a JSON string`, - `$ stackit argus scrape-configs create --payload "{...}"`), + `Create a Scrape Config job on Argus instance "xxx" using an API payload provided as a JSON string`, + `$ stackit argus scrape-configs create --payload "{...}" --instance-id xxx`), examples.NewExample( `Generate a payload with default values, and adapt it with custom values for the different configuration options`, `$ stackit argus scrape-configs generate-payload > ./payload.json`, ``, - `$ stackit argus scrape-configs create --payload @./payload.json`), + `$ stackit argus scrape-configs create --payload @./payload.json --instance-id xxx`), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -117,7 +117,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s Scrape Configuration for Argus instance %q, with job name %q\n", operationState, instanceLabel, *jobName) + p.Outputf("%s Scrape Config for Argus instance %q, with job name %q\n", operationState, instanceLabel, *jobName) return nil }, } From ea9d2b7aece5e72023599f2cdee5294283e9c9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Mon, 22 Apr 2024 15:00:06 +0200 Subject: [PATCH 4/4] address PR comments --- internal/cmd/argus/scrape-configs/create/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/argus/scrape-configs/create/create.go b/internal/cmd/argus/scrape-configs/create/create.go index 9e5e192f7..a46b2ac4f 100644 --- a/internal/cmd/argus/scrape-configs/create/create.go +++ b/internal/cmd/argus/scrape-configs/create/create.go @@ -117,7 +117,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s Scrape Config for Argus instance %q, with job name %q\n", operationState, instanceLabel, *jobName) + p.Outputf("%s Scrape Config job with name %q for Argus instance %q\n", operationState, *jobName, instanceLabel) return nil }, }