Skip to content

Commit

Permalink
Merge branch 'main' into fix-metrics
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain authored Oct 31, 2023
2 parents ba0cbbb + 046a593 commit 785808b
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
extended: true

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/retest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
pull-requests: write
actions: write
steps:
- uses: envoyproxy/toolshed/gh-actions/retest@actions-v0.0.25
- uses: envoyproxy/toolshed/gh-actions/retest@actions-v0.1.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ type EnvoyGatewayAdmin struct {
// EnableDumpConfig defines if enable dump config in Envoy Gateway logs.
//
// +optional
EnableDumpConfig bool
EnableDumpConfig bool `json:"enableDumpConfig,omitempty"`
// EnablePprof defines if enable pprof in Envoy Gateway Admin Server.
//
// +optional
EnablePprof bool
EnablePprof bool `json:"enablePprof,omitempty"`
}

// EnvoyGatewayAdminAddress defines the Envoy Gateway Admin Address configuration.
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package v1alpha1

// LoadBalancer defines the load balancer policy to be applied.
// +union
//
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' ? has(self.consistentHash) : !has(self.consistentHash)",message="If LoadBalancer type is consistentHash, consistentHash field needs to be set."
type LoadBalancer struct {
// Type decides the type of Load Balancer policy.
// Valid RateLimitType values are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ spec:
required:
- type
type: object
x-kubernetes-validations:
- message: If LoadBalancer type is consistentHash, consistentHash
field needs to be set.
rule: 'self.type == ''ConsistentHash'' ? has(self.consistentHash)
: !has(self.consistentHash)'
rateLimit:
description: RateLimit allows the user to limit the number of incoming
requests to a predefined value based on attributes within the traffic
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/envoyproxy/ratelimit v1.4.1-0.20230427142404-e2a87f41d3a7
github.com/evanphx/json-patch/v5 v5.7.0
github.com/go-logfmt/logfmt v0.6.0
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/go-logr/zapr v1.2.4
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
Expand Down Expand Up @@ -44,7 +44,7 @@ require (
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/gateway-api v1.0.0-rc2
sigs.k8s.io/yaml v1.3.0
sigs.k8s.io/yaml v1.4.0
)

require (
Expand Down
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KE
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
Expand Down Expand Up @@ -227,6 +228,7 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -780,5 +782,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kF
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
3 changes: 0 additions & 3 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,6 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route
DirectResponse: routeRoute.DirectResponse,
URLRewrite: routeRoute.URLRewrite,
Mirrors: routeRoute.Mirrors,
RateLimit: routeRoute.RateLimit,
CORS: routeRoute.CORS,
JWT: routeRoute.JWT,
Timeout: routeRoute.Timeout,
ExtensionRefs: routeRoute.ExtensionRefs,
}
Expand Down
16 changes: 13 additions & 3 deletions internal/provider/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,19 @@ func testGatewayClassWithParamRef(ctx context.Context, t *testing.T, provider *P
}, defaultWait, defaultTick)

// Ensure the resource map contains the EnvoyProxy.
res, ok := resources.GatewayAPIResources.Load(gc.Name)
assert.Equal(t, ok, true)
assert.Equal(t, res.EnvoyProxy.Spec, ep.Spec)
require.Eventually(t, func() bool {
res, ok := resources.GatewayAPIResources.Load(gc.Name)
if !ok {
return false
}

if res.EnvoyProxy != nil {
assert.Equal(t, res.EnvoyProxy.Spec, ep.Spec)
return true
}

return false
}, defaultWait, defaultTick)
}

func testGatewayScheduledStatus(ctx context.Context, t *testing.T, provider *Provider, resources *message.ProviderResources) {
Expand Down
2 changes: 1 addition & 1 deletion internal/xds/translator/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (t *Translator) buildRateLimitFilter(irListener *ir.HTTPListener) *hcmv3.Ht
// patchRouteWithRateLimit builds rate limit actions and appends to the route.
func patchRouteWithRateLimit(xdsRouteAction *routev3.RouteAction, irRoute *ir.HTTPRoute) error { //nolint:unparam
// Return early if no rate limit config exists.
if irRoute.RateLimit == nil || irRoute.RateLimit.Global == nil {
if irRoute.RateLimit == nil || irRoute.RateLimit.Global == nil || xdsRouteAction == nil {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ _Appears in:_
| Field | Description |
| --- | --- |
| `address` _[EnvoyGatewayAdminAddress](#envoygatewayadminaddress)_ | Address defines the address of Envoy Gateway Admin Server. |
| `EnableDumpConfig` _boolean_ | EnableDumpConfig defines if enable dump config in Envoy Gateway logs. |
| `EnablePprof` _boolean_ | EnablePprof defines if enable pprof in Envoy Gateway Admin Server. |
| `enableDumpConfig` _boolean_ | EnableDumpConfig defines if enable dump config in Envoy Gateway logs. |
| `enablePprof` _boolean_ | EnablePprof defines if enable pprof in Envoy Gateway Admin Server. |


#### EnvoyGatewayAdminAddress
Expand Down
59 changes: 59 additions & 0 deletions test/cel-validation/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,65 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
"spec.targetRef: Invalid value: \"object\": this policy does not yet support the sectionName field",
},
},
{
desc: "consistentHash field not nil when type is consistentHash",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
LoadBalancer: &egv1a1.LoadBalancer{
Type: egv1a1.ConsistentHashLoadBalancerType,
ConsistentHash: &egv1a1.ConsistentHash{
Type: "SourceIP",
},
},
}
},
wantErrors: []string{},
},
{
desc: "consistentHash field nil when type is consistentHash",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
LoadBalancer: &egv1a1.LoadBalancer{
Type: egv1a1.ConsistentHashLoadBalancerType,
},
}
},
wantErrors: []string{
"spec.loadBalancer: Invalid value: \"object\": If LoadBalancer type is consistentHash, consistentHash field needs to be set",
},
},
{
desc: "leastRequest with ConsistentHash nil",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
LoadBalancer: &egv1a1.LoadBalancer{
Type: egv1a1.LeastRequestLoadBalancerType,
},
}
},
wantErrors: []string{},
},
}

for _, tc := range cases {
Expand Down
36 changes: 26 additions & 10 deletions test/cel-validation/envoyproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestEnvoyProxyProvider(t *testing.T) {
wantErrors: []string{"allocateLoadBalancerNodePorts can only be set for LoadBalancer type"},
},
{
desc: "loadBalancerIP-pass-case1",
desc: "ServiceTypeLoadBalancer-with-valid-IP",
mutate: func(envoy *egv1a1.EnvoyProxy) {
envoy.Spec = egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Expand All @@ -139,14 +139,14 @@ func TestEnvoyProxyProvider(t *testing.T) {
wantErrors: []string{},
},
{
desc: "loadBalancerIP-pass-case2",
desc: "ServiceTypeLoadBalancer-with-empty-IP",
mutate: func(envoy *egv1a1.EnvoyProxy) {
envoy.Spec = egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyService: &egv1a1.KubernetesServiceSpec{
Type: ptr.To(egv1a1.ServiceTypeClusterIP),
Type: ptr.To(egv1a1.ServiceTypeLoadBalancer),
},
},
},
Expand All @@ -155,38 +155,54 @@ func TestEnvoyProxyProvider(t *testing.T) {
wantErrors: []string{},
},
{
desc: "loadBalancerIP-fail-case1",
desc: "ServiceTypeLoadBalancer-with-invalid-IP",
mutate: func(envoy *egv1a1.EnvoyProxy) {
envoy.Spec = egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyService: &egv1a1.KubernetesServiceSpec{
Type: ptr.To(egv1a1.ServiceTypeClusterIP),
Type: ptr.To(egv1a1.ServiceTypeLoadBalancer),
LoadBalancerIP: ptr.To("a.b.c.d"),
},
},
},
}
},
wantErrors: []string{"loadBalancerIP can only be set for LoadBalancer type"},
wantErrors: []string{"loadBalancerIP must be a valid IPv4 address"},
},
{
desc: "loadBalancerIP-fail-case2",
desc: "ServiceTypeClusterIP-with-empty-IP",
mutate: func(envoy *egv1a1.EnvoyProxy) {
envoy.Spec = egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyService: &egv1a1.KubernetesServiceSpec{
Type: ptr.To(egv1a1.ServiceTypeLoadBalancer),
LoadBalancerIP: ptr.To("a.b.c.d"),
Type: ptr.To(egv1a1.ServiceTypeClusterIP),
},
},
},
}
},
wantErrors: []string{"loadBalancerIP must be a valid IPv4 address"},
wantErrors: []string{},
},
{
desc: "ServiceTypeClusterIP-with-LoadBalancerIP",
mutate: func(envoy *egv1a1.EnvoyProxy) {
envoy.Spec = egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyService: &egv1a1.KubernetesServiceSpec{
Type: ptr.To(egv1a1.ServiceTypeClusterIP),
LoadBalancerIP: ptr.To("20.205.243.166"), // github ip for test only
},
},
},
}
},
wantErrors: []string{"loadBalancerIP can only be set for LoadBalancer type"},
},
}

Expand Down
17 changes: 17 additions & 0 deletions test/e2e/testdata/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: envoy-gateway-metrics-lb
namespace: envoy-gateway-system
labels:
control-plane: envoy-gateway
spec:
selector:
control-plane: envoy-gateway
app.kubernetes.io/instance: eg
ports:
- name: http-metrics
port: 19001
protocol: TCP
targetPort: 19001
type: LoadBalancer
76 changes: 76 additions & 0 deletions test/e2e/tests/controlplane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

//go:build e2e
// +build e2e

package tests

import (
"context"
"testing"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, ControlPlaneMetricTest)
}

var ControlPlaneMetricTest = suite.ConformanceTest{
ShortName: "ControlPlane",
Description: "Make sure control plane prometheus endpoint is working",
Manifests: []string{"testdata/prometheus.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("Prometheus", func(t *testing.T) {
nn := types.NamespacedName{Name: "envoy-gateway-metrics-lb", Namespace: "envoy-gateway-system"}
if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true,
func(_ context.Context) (done bool, err error) {
svc := corev1.Service{}
if err := suite.Client.Get(context.Background(), nn, &svc); err != nil {
return false, nil
}

host := ""
switch svc.Spec.Type {
case corev1.ServiceTypeLoadBalancer:
for _, ing := range svc.Status.LoadBalancer.Ingress {
if ing.IP != "" {
host = ing.IP
break
}
}
default:
// do nothing
}

if host == "" {
return false, nil
}

return true, nil
}); err != nil {
t.Errorf("failed to get service %s : %v", nn.String(), err)
}

// too much flakes in the test if timeout is 1 minute
// this should not take so long, but we give it a long timeout to be safe, and poll every second
if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, 2*time.Minute, true,
func(_ context.Context) (done bool, err error) {
if err := ScrapeMetrics(t, suite.Client, nn, 19001, "/metrics"); err != nil {
t.Logf("failed to get metric: %v", err)
return false, nil
}
return true, nil
}); err != nil {
t.Errorf("failed to scrape metrics: %v", err)
}
})
},
}
Loading

0 comments on commit 785808b

Please sign in to comment.