Skip to content

Commit

Permalink
Add UserError to ILB DualStack metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
panslava committed Jan 24, 2023
1 parent 8ed99a8 commit 2a5ef12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/l4lb/l4controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/ingress-gce/pkg/forwardingrules"
l4metrics "k8s.io/ingress-gce/pkg/l4lb/metrics"
"k8s.io/ingress-gce/pkg/loadbalancers"
"k8s.io/ingress-gce/pkg/metrics"
negtypes "k8s.io/ingress-gce/pkg/neg/types"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/ingress-gce/pkg/utils/common"
Expand Down Expand Up @@ -233,6 +234,9 @@ func (l4c *L4Controller) processServiceCreateOrUpdate(service *v1.Service) *load
"Error syncing load balancer: %v", syncResult.Error)
if utils.IsUserError(syncResult.Error) {
syncResult.MetricsState.IsUserError = true
if l4c.enableDualStack {
syncResult.DualStackMetricsState.Status = metrics.StatusUserError
}
}
return syncResult
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/l4lb/l4controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"google.golang.org/api/googleapi"
"k8s.io/ingress-gce/pkg/loadbalancers"
"k8s.io/ingress-gce/pkg/metrics"
"k8s.io/ingress-gce/pkg/utils"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
Expand Down Expand Up @@ -112,6 +113,13 @@ func newFakeGCEWithUserInsertError() *gce.Cloud {
return fakeGCE
}

func newFakeGCEWithUserNoIPv6SubnetError() *gce.Cloud {
vals := gce.DefaultTestClusterValues()
fakeGCE := gce.NewFakeGCECloud(vals)
(fakeGCE.Compute().(*cloud.MockGCE)).MockForwardingRules.InsertHook = test.InsertForwardingRuleErrorHook(&googleapi.Error{Code: http.StatusBadRequest, Message: "Subnetwork does not have an internal IPv6 IP space which is required for IPv6 L4 ILB forwarding rules."})
return fakeGCE
}

func addILBService(l4c *L4Controller, svc *api_v1.Service) {
l4c.ctx.KubeClient.CoreV1().Services(svc.Namespace).Create(context2.TODO(), svc, v1.CreateOptions{})
l4c.ctx.ServiceInformer.GetIndexer().Add(svc)
Expand Down Expand Up @@ -768,3 +776,26 @@ func TestCreateDeleteDualStackService(t *testing.T) {
})
}
}

func TestProcessDualStackServiceOnUserError(t *testing.T) {
t.Parallel()
l4c := newServiceController(t, newFakeGCEWithUserNoIPv6SubnetError())
l4c.enableDualStack = true

newSvc := test.NewL4ILBDualStackService(8080, api_v1.ProtocolTCP, []api_v1.IPFamily{api_v1.IPv4Protocol, api_v1.IPv6Protocol}, api_v1.ServiceExternalTrafficPolicyTypeCluster)
addILBService(l4c, newSvc)
addNEG(l4c, newSvc)
syncResult := l4c.processServiceCreateOrUpdate(newSvc)
if syncResult.Error == nil {
t.Fatalf("Failed to generate error when syncing service %s", newSvc.Name)
}
if !syncResult.MetricsState.IsUserError {
t.Errorf("syncResult.MetricsState.IsUserError should be true, got false")
}
if syncResult.MetricsState.InSuccess {
t.Errorf("syncResult.MetricsState.InSuccess should be false, got true")
}
if syncResult.DualStackMetricsState.Status != metrics.StatusUserError {
t.Errorf("syncResult.DualStackMetricsState.Status should be %s, got %s", metrics.StatusUserError, syncResult.DualStackMetricsState.Status)
}
}
1 change: 1 addition & 0 deletions pkg/metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type L4ILBServiceState struct {
type L4ILBDualStackServiceStateStatus string

var StatusSuccess = L4ILBDualStackServiceStateStatus("Success")
var StatusUserError = L4ILBDualStackServiceStateStatus("UserError")
var StatusError = L4ILBDualStackServiceStateStatus("Error")

// L4ILBDualStackServiceState defines ipFamilies, ipFamilyPolicy and status
Expand Down

0 comments on commit 2a5ef12

Please sign in to comment.