Skip to content

Commit f015679

Browse files
Added filtering for incorrect slo boosting logs
1 parent 28f5cc8 commit f015679

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

pkg/gce-cloud-provider/compute/gce.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
"net/url"
2323
"os"
24+
"regexp"
2425
"runtime"
2526
"sync"
2627
"time"
@@ -77,6 +78,11 @@ const (
7778
gcpTagsRequestTokenBucketSize = 8
7879
)
7980

81+
var (
82+
ssAlreadyExistsRegex = regexp.MustCompile("The resource [^']+ already exists")
83+
gcpViolationRegex = regexp.MustCompile("violates constraint constraints/gcp.")
84+
)
85+
8086
// ResourceType indicates the type of a compute resource.
8187
type ResourceType string
8288

@@ -441,3 +447,13 @@ func IsGCENotFoundError(err error) bool {
441447
func IsGCEInvalidError(err error) bool {
442448
return IsGCEError(err, "invalid")
443449
}
450+
451+
// IsSnapshotAlreadyExistsError checks if the error is a snapshot already exists error.
452+
func IsSnapshotAlreadyExistsError(err error) bool {
453+
return ssAlreadyExistsRegex.MatchString(err.Error())
454+
}
455+
456+
// IsGCPOrgViolationError checks if the error is a GCP organization policy violation error.
457+
func IsGCPOrgViolationError(err error) bool {
458+
return gcpViolationRegex.MatchString(err.Error())
459+
}

pkg/gce-cloud-provider/compute/gce_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,60 @@ func TestIsGCEError(t *testing.T) {
101101
}
102102
}
103103

104+
func TestErrorIsGCPViolationRegex(t *testing.T) {
105+
testCases := []struct {
106+
name string
107+
inputErr error
108+
expectedResult bool
109+
}{
110+
{
111+
name: "is gcp org violation error",
112+
inputErr: errors.New("Your api request violates constraint constraints/gcp.resourceLocations"),
113+
expectedResult: true,
114+
},
115+
{
116+
name: "is not gcp org violation error",
117+
inputErr: errors.New("Some incorrect error message"),
118+
expectedResult: false,
119+
},
120+
}
121+
122+
for _, tc := range testCases {
123+
t.Logf("Running test: %v", tc.name)
124+
result := IsGCPOrgViolationError(tc.inputErr)
125+
if tc.expectedResult != result {
126+
t.Fatalf("Got '%t', expected '%t'", result, tc.expectedResult)
127+
}
128+
}
129+
}
130+
131+
func TestErrorIsSnapshotExistsError(t *testing.T) {
132+
testCases := []struct {
133+
name string
134+
inputErr error
135+
expectedResult bool
136+
}{
137+
{
138+
name: "is ss error",
139+
inputErr: errors.New("The resource projects/dcme-pre-opt-mdp-rmp-00/global/snapshots/snapshot-3c208602-d815-40ae-a61e-3259e3bd29ca already exists, alreadyExists"),
140+
expectedResult: true,
141+
},
142+
{
143+
name: "is not ss already exists error",
144+
inputErr: errors.New("Some incorrect error message"),
145+
expectedResult: false,
146+
},
147+
}
148+
149+
for _, tc := range testCases {
150+
t.Logf("Running test: %v", tc.name)
151+
result := IsSnapshotAlreadyExistsError(tc.inputErr)
152+
if tc.expectedResult != result {
153+
t.Fatalf("Got '%t', expected '%t'", result, tc.expectedResult)
154+
}
155+
}
156+
}
157+
104158
func TestGetComputeVersion(t *testing.T) {
105159
testCases := []struct {
106160
name string

pkg/gce-pd-csi-driver/controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,16 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
16681668
if gce.IsGCEError(err, "notFound") {
16691669
return nil, status.Errorf(codes.NotFound, "Could not find volume with ID %v: %v", volKey.String(), err.Error())
16701670
}
1671+
1672+
// Identified as incorrect error handling
1673+
if gce.IsSnapshotAlreadyExistsError(err) {
1674+
return nil, status.Errorf(codes.AlreadyExists, "Snapshot already exists: %v", err.Error())
1675+
}
1676+
1677+
// Identified as incorrect error handling
1678+
if gce.IsGCPOrgViolationError(err) {
1679+
return nil, status.Errorf(codes.FailedPrecondition, "Violates GCP org policy: %v", err.Error())
1680+
}
16711681
return nil, common.LoggedError("Failed to create snapshot: ", err)
16721682
}
16731683
}

0 commit comments

Comments
 (0)