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

Showing error details for quota exceeded error for gce operations #14879

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8030.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: surface error details for Compute Operation with quota exceeded errors.
```
8 changes: 8 additions & 0 deletions google/services/compute/compute_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ func writeOperationError(w io.StringWriter, opError *compute.OperationErrorError
var link *compute.HelpLink

for _, ed := range opError.ErrorDetails {
if opError.Code == "QUOTA_EXCEEDED" && ed.QuotaInfo != nil {
w.WriteString("\tmetric name = " + ed.QuotaInfo.MetricName + "\n")
w.WriteString("\tlimit name = " + ed.QuotaInfo.LimitName + "\n")
if ed.QuotaInfo.Dimensions != nil {
w.WriteString("\tdimensions = " + fmt.Sprint(ed.QuotaInfo.Dimensions) + "\n")
}
break
}
if lm == nil && ed.LocalizedMessage != nil {
lm = ed.LocalizedMessage
}
Expand Down
62 changes: 62 additions & 0 deletions google/services/compute/compute_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const (
localizedMsgTmpl = "LocalizedMessage%d message"
helpLinkDescriptionTmpl = "Help%dLink%d Description"
helpLinkUrlTmpl = "https://help%d.com/link%d"
quotaExceededMsg = "Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1."
quotaExceededCode = "QUOTA_EXCEEDED"
quotaMetricName = "compute.googleapis.com/disks_total_storage"
quotaLimitName = "DISKS-TOTAL-GB-per-project-region"
)

var locales = []string{"en-US", "es-US", "es-ES", "es-MX", "de-DE"}
Expand Down Expand Up @@ -53,6 +57,27 @@ func buildOperationError(numLocalizedMsg int, numHelpWithLinks []int) compute.Op

}

func buildOperationErrorQuotaExceeded(withDetails bool, withDimensions bool) compute.OperationError {
opError := &compute.OperationErrorErrors{Message: quotaExceededMsg, Code: quotaExceededCode}
opErrorErrors := []*compute.OperationErrorErrors{opError}
if withDetails {
quotaInfo := &compute.QuotaExceededInfo{
MetricName: quotaMetricName,
LimitName: quotaLimitName,
Limit: 1100,
}
if withDimensions {
quotaInfo.Dimensions = map[string]string{"region": "us-central1"}
}
opError.ErrorDetails = append(opError.ErrorDetails,
&compute.OperationErrorErrorsErrorDetails{
QuotaInfo: quotaInfo,
})
}

return compute.OperationError{Errors: opErrorErrors}
}

func omitAlways(numLocalizedMsg int, numHelpWithLinks []int) []string {
var omits []string

Expand Down Expand Up @@ -180,6 +205,43 @@ func TestComputeOperationError_Error(t *testing.T) {
},
expectOmits: append(omitAlways(2, []int{1}), []string{}...),
},
{
name: "QuotaMessageOnly",
input: buildOperationErrorQuotaExceeded(false, false),
expectContains: []string{
"Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1.",
},
expectOmits: append(omitAlways(0, []int{}), []string{
"metric name = compute.googleapis.com/disks_total_storage",
}...),
},
{
name: "QuotaMessageWithDetailsNoDimensions",
input: buildOperationErrorQuotaExceeded(true, false),
expectContains: []string{
"Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1.",
"metric name = compute.googleapis.com/disks_total_storage",
"limit name = DISKS-TOTAL-GB-per-project-region",
},
expectOmits: append(omitAlways(0, []int{}), []string{
"dimensions = map[region:us-central1]",
}...),
},
{
name: "QuotaMessageWithDetailsWithDimensions",
input: buildOperationErrorQuotaExceeded(true, true),
expectContains: []string{
"Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1.",
"metric name = compute.googleapis.com/disks_total_storage",
"limit name = DISKS-TOTAL-GB-per-project-region",
"dimensions = map[region:us-central1]",
},
expectOmits: append(omitAlways(0, []int{}), []string{
"LocalizedMessage1",
"Help1Link1 Description",
"https://help1.com/link1",
}...),
},
}

for _, tc := range testCases {
Expand Down