Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings about options.cloud #3407

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
}

// Cloud config
cloudConfig, _, err := cloudapi.GetConsolidatedConfig(
cloudConfig, warn, err := cloudapi.GetConsolidatedConfig(
test.derivedConfig.Collectors["cloud"], c.gs.Env, "", arc.Options.Cloud, arc.Options.External)
if err != nil {
return err
Expand All @@ -120,6 +120,11 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
return errors.New("Not logged in, please use `k6 login cloud`.") //nolint:golint,revive,stylecheck
}

// Display config warning if needed
if warn != "" {
modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Warning: "+warn))
}

if cloudConfig.Token.Valid {
tmpCloudConfig["token"] = cloudConfig.Token
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ This will set the default token used when just "k6 run -o cloud" is passed.`,

// We want to use this fully consolidated config for things like
// host addresses, so users can overwrite them with env vars.
consolidatedCurrentConfig, _, err := cloudapi.GetConsolidatedConfig(
consolidatedCurrentConfig, warn, err := cloudapi.GetConsolidatedConfig(
currentJSONConfigRaw, gs.Env, "", nil, nil)
if err != nil {
return err
}

if warn != "" {
gs.Logger.Warn(warn)
}

// But we don't want to save them back to the JSON file, we only
// want to save what already existed there and the login details.
newCloudConf := currentJSONConfig
Expand Down
16 changes: 7 additions & 9 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ export const options = {
// See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/
// to learn about authoring and running k6 test scripts in Grafana k6 Cloud.
//
// ext: {
// loadimpact: {
// // The ID of the project to which the test is assigned in the k6 Cloud UI.
// // By default tests are executed in default project.
// projectID: "",
// // The name of the test in the k6 Cloud UI.
// // Test runs with the same name will be grouped.
// name: "{{ .ScriptName }}"
// }
// cloud: {
// // The ID of the project to which the test is assigned in the k6 Cloud UI.
// // By default tests are executed in default project.
// projectID: "",
// // The name of the test in the k6 Cloud UI.
// // Test runs with the same name will be grouped.
// name: "{{ .ScriptName }}"
// },

// Uncomment this section to enable the use of Browser API in your tests.
Expand Down
18 changes: 8 additions & 10 deletions cmd/tests/cmd_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,19 @@ func TestCloudWithArchive(t *testing.T) {

metadata := struct {
Options struct {
Ext struct {
LoadImpact struct {
Name string `json:"name"`
Note string `json:"note"`
ProjectID int `json:"projectID"`
} `json:"loadimpact"`
} `json:"ext"`
Cloud struct {
Name string `json:"name"`
Note string `json:"note"`
ProjectID int `json:"projectID"`
} `json:"cloud"`
} `json:"options"`
}{}

// then unpacked metadata should not contain any environment variables passed at the moment of archive creation
require.NoError(t, json.Unmarshal(metadataRaw, &metadata))
require.Equal(t, "my load test", metadata.Options.Ext.LoadImpact.Name)
require.Equal(t, "lorem ipsum", metadata.Options.Ext.LoadImpact.Note)
require.Equal(t, 124, metadata.Options.Ext.LoadImpact.ProjectID)
require.Equal(t, "my load test", metadata.Options.Cloud.Name)
require.Equal(t, "lorem ipsum", metadata.Options.Cloud.Note)
require.Equal(t, 124, metadata.Options.Cloud.ProjectID)

// respond with the test run ID
resp.WriteHeader(http.StatusOK)
Expand Down
8 changes: 6 additions & 2 deletions output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func New(params output.Params) (output.Output, error) {

// New creates a new cloud output.
func newOutput(params output.Params) (*Output, error) {
conf, _, err := cloudapi.GetConsolidatedConfig(
conf, warn, err := cloudapi.GetConsolidatedConfig(
params.JSONConfig,
params.Environment,
params.ConfigArgument,
Expand All @@ -88,6 +88,10 @@ func newOutput(params output.Params) (*Output, error) {
return nil, err
}

if warn != "" {
params.Logger.Warn(warn)
}

if err := validateRequiredSystemTags(params.ScriptOptions.SystemTags); err != nil {
return nil, err
}
Expand All @@ -98,7 +102,7 @@ func newOutput(params output.Params) (*Output, error) {
scriptPath := params.ScriptPath.String()
if scriptPath == "" {
// Script from stdin without a name, likely from stdin
return nil, errors.New("script name not set, please specify K6_CLOUD_NAME or options.ext.loadimpact.name")
return nil, errors.New("script name not set, please specify K6_CLOUD_NAME or options.cloud.name")
}

conf.Name = null.StringFrom(filepath.Base(scriptPath))
Expand Down