-
Notifications
You must be signed in to change notification settings - Fork 543
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
feat!: Add dimensions argument to consumer quota override #683
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @stanley98yu
A test would be great. I am not sure what you meant by gsuite as the example inputs only seem to require a project_id.
Sorry about the vague question--I misunderstood how the tests are setup. I've tried adding a new test suite for |
@stanley98yu np, it is linked via the test name |
Hey @bharathkkb I'm having some trouble using the new test framework. How do I run an arbitrary shell command that isn't I tried looking at https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/blueprint-test/pkg/gcloud/gcloud.go to see how the test commands work, but I'm still new to Go. I've pushed my current test setup if you want to take a look. Let me know your thoughts/alternatives |
@stanley98yu I'll ping you |
gcurlCmd := shell.Command{ | ||
Command: "gcurl", | ||
Args: []string{fmt.Sprintf("https://serviceconsumermanagement.googleapis.com/v1beta1/services/%s/projects/%s/consumerQuotaMetrics", computeAPI, projectID)}, | ||
} | ||
op, err := shell.RunCommandAndGetStdOutE(t, gcurlCmd) | ||
if err != nil { | ||
t.Fatal(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets check if gcloud is available. If not, I am leaning towards using https://pkg.go.dev/golang.org/x/oauth2/google#DefaultClient to make the request. We can add a helper to the test framework if there is verbose logic. Based on the API doc, something like below is what I was thinking
httpClient, err := google.DefaultClient(oauth2.NoContext,
"https://www.googleapis.com/auth/cloud-platform")
if err != nil {
t.Fatalf("",err)
}
resp, err := httpClient.Get(runEndPointUrl)
if err != nil {
t.Fatalf("",err)
}
// use utils.ParseJSONResult on resp.Body
@stanley98yu Hoping to pull this into #684 as its a breaking change if you have bandwidth. We can defer the test to a follow up PR if you can validate and add an upgrade guide. |
@bharathkkb Sorry about the delay, but I don't think I can verify WAI just yet. The |
@stanley98yu no worries, we can hold for next release. Thanks for checking! |
I'm able to verify that the feature is WAI but with two notes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Some minor nits related to test below.
The issue before was that setting the dimensions type constraint as object({}) implies it doesn't have any attributes
Baseed on example would map(string)
be a better type?
I ended up not being able to find a gcloud-equivalent command for calling the Service Usage API, so I stuck with using an HTTP client to call the API.
Sounds good, this might also be something we can add to the test framework if you are interested in opening an issue here.
The checks seem to fail for apply-essential-contacts-example
Yeah that seemed like a flake.
|
||
projectID := quotaProjectT.GetStringOutput("project_id") | ||
|
||
apis := gcloud.Run(t, fmt.Sprintf("services list --project %s", projectID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newer versions of the framework has a Runf method which is a bit cleaner
apis := gcloud.Run(t, fmt.Sprintf("services list --project %s", projectID)) | |
apis := gcloud.Runf(t, "services list --project %s", projectID) |
if err != nil { | ||
t.Fatalf("%s", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since we already have assert. https://pkg.go.dev/github.com/stretchr/testify/assert#NoError
if err != nil { | |
t.Fatalf("%s", err) | |
} | |
assert.NoError(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and throughout
} | ||
result = utils.ParseJSONResult(t, string(body)) | ||
assert.Equal("95", result.Get("overrides.0.overrideValue").String(), "has correct consumer quota override value") | ||
assert.True(!result.Get("overrides.0.dimensions").Exists(), "has correct consumer quota override dimensions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed a bit confusing - reworded slightly based on fixture
assert.True(!result.Get("overrides.0.dimensions").Exists(), "has correct consumer quota override dimensions") | |
assert.False(result.Get("overrides.0.dimensions").Exists(), "has empty dimensions") |
if err != nil { | ||
t.Fatalf("%s", err) | ||
} | ||
body, err := io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close body to prevent leaks
body, err := io.ReadAll(resp.Body) | |
defer resp.Body.Close() | |
body, err := io.ReadAll(resp.Body) |
Thanks, @bharathkkb! I've updated with the suggestions. |
hold for next breaking |
@stanley98yu |
Fixes: #665
I was thinking about adding a test, but I don't have gsuite set up. Is there a non-gsuite-enabled test that would be best?