diff --git a/internal/mode/static/nginx/config/servers_test.go b/internal/mode/static/nginx/config/servers_test.go index f3e523a4c0..112991b521 100644 --- a/internal/mode/static/nginx/config/servers_test.go +++ b/internal/mode/static/nginx/config/servers_test.go @@ -1150,7 +1150,7 @@ func TestCreateServers(t *testing.T) { }, { Path: "/_ngf-internal-rule1-route0", - ProxyPass: "http://$test__route1_rule1$request_uri", + ProxyPass: "http://$group_test__route1_rule1$request_uri", ProxySetHeaders: httpBaseHeaders, Type: http.InternalLocationType, Includes: internalIncludes, @@ -2810,7 +2810,7 @@ func TestCreateProxyPass(t *testing.T) { }, }, { - expected: "http://$ns1__bg_rule0$request_uri", + expected: "http://$group_ns1__bg_rule0$request_uri", grp: dataplane.BackendGroup{ Source: types.NamespacedName{Namespace: "ns1", Name: "bg"}, Backends: []dataplane.Backend{ diff --git a/internal/mode/static/nginx/config/split_clients_test.go b/internal/mode/static/nginx/config/split_clients_test.go index 44eebf359b..4e70c44d1e 100644 --- a/internal/mode/static/nginx/config/split_clients_test.go +++ b/internal/mode/static/nginx/config/split_clients_test.go @@ -52,8 +52,8 @@ func TestExecuteSplitClients(t *testing.T) { bg3, }, expStrings: []string{ - "split_clients $request_id $test__hr_rule0", - "split_clients $request_id $test__hr_rule1", + "split_clients $request_id $group_test__hr_rule0", + "split_clients $request_id $group_test__hr_rule1", "50.00% test1;", "50.00% test2;", "50.00% test3;", @@ -74,7 +74,7 @@ func TestExecuteSplitClients(t *testing.T) { }, }, expStrings: []string{ - "split_clients $request_id $test__zero_percent_rule0", + "split_clients $request_id $group_test__zero_percent_rule0", "100.00% non-zero;", "# 0.00% zero;", }, @@ -188,7 +188,7 @@ func TestCreateSplitClients(t *testing.T) { }, expSplitClients: []http.SplitClient{ { - VariableName: "test__hr_one_split_rule0", + VariableName: "group_test__hr_one_split_rule0", Distributions: []http.SplitClientDistribution{ { Percent: "50.00", @@ -201,7 +201,7 @@ func TestCreateSplitClients(t *testing.T) { }, }, { - VariableName: "test__hr_two_splits_rule0", + VariableName: "group_test__hr_two_splits_rule0", Distributions: []http.SplitClientDistribution{ { Percent: "50.00", @@ -214,7 +214,7 @@ func TestCreateSplitClients(t *testing.T) { }, }, { - VariableName: "test__hr_two_splits_rule1", + VariableName: "group_test__hr_two_splits_rule1", Distributions: []http.SplitClientDistribution{ { Percent: "33.33", @@ -661,7 +661,7 @@ func TestBackendGroupName(t *testing.T) { Weight: 1, }, }, - expName: "test__hr_rule0", + expName: "group_test__hr_rule0", }, { msg: "multiple invalid backends", @@ -677,7 +677,7 @@ func TestBackendGroupName(t *testing.T) { Weight: 1, }, }, - expName: "test__hr_rule0", + expName: "group_test__hr_rule0", }, } diff --git a/internal/mode/static/state/dataplane/configuration_test.go b/internal/mode/static/state/dataplane/configuration_test.go index 4c9e92da38..f3869cbeb2 100644 --- a/internal/mode/static/state/dataplane/configuration_test.go +++ b/internal/mode/static/state/dataplane/configuration_test.go @@ -2992,20 +2992,21 @@ func TestBuildUpstreams(t *testing.T) { g.Expect(upstreams).To(ConsistOf(expUpstreams)) } -func TestBuildBackendGroups(t *testing.T) { - t.Parallel() - createBackendGroup := func(name string, ruleIdx int, backendNames ...string) BackendGroup { - backends := make([]Backend, len(backendNames)) - for i, name := range backendNames { - backends[i] = Backend{UpstreamName: name} - } +func createBackendGroup(name string, ruleIdx int, backendNames ...string) BackendGroup { + backends := make([]Backend, len(backendNames)) + for i, name := range backendNames { + backends[i] = Backend{UpstreamName: name} + } - return BackendGroup{ - Source: types.NamespacedName{Namespace: "test", Name: name}, - RuleIdx: ruleIdx, - Backends: backends, - } + return BackendGroup{ + Source: types.NamespacedName{Namespace: "test", Name: name}, + RuleIdx: ruleIdx, + Backends: backends, } +} + +func TestBuildBackendGroups(t *testing.T) { + t.Parallel() hr1Group0 := createBackendGroup("hr1", 0, "foo", "bar") @@ -3061,10 +3062,19 @@ func TestBuildBackendGroups(t *testing.T) { g := NewWithT(t) result := buildBackendGroups(servers) - g.Expect(result).To(ConsistOf(expGroups)) } +func TestBackendGroupName(t *testing.T) { + t.Parallel() + backendGroup := createBackendGroup("route1", 2, "foo", "bar") + + expectedGroupName := "group_test__route1_rule2" + + g := NewWithT(t) + g.Expect(backendGroup.Name()).To(Equal(expectedGroupName)) +} + func TestHostnameMoreSpecific(t *testing.T) { t.Parallel() tests := []struct { diff --git a/internal/mode/static/state/dataplane/types.go b/internal/mode/static/state/dataplane/types.go index 2b82cde7ae..b096d517ee 100644 --- a/internal/mode/static/state/dataplane/types.go +++ b/internal/mode/static/state/dataplane/types.go @@ -267,11 +267,13 @@ type BackendGroup struct { // Name returns the name of the backend group. // This name must be unique across all HTTPRoutes and all rules within the same HTTPRoute. +// It is prefixed with `group_` for cases when namespace name starts with a digit. Variable names +// in nginx configuration cannot start with a digit. // The RuleIdx is used to make the name unique across all rules within the same HTTPRoute. // The RuleIdx may change for a given rule if an update is made to the HTTPRoute, but it will always match the index // of the rule in the stored HTTPRoute. func (bg *BackendGroup) Name() string { - return fmt.Sprintf("%s__%s_rule%d", bg.Source.Namespace, bg.Source.Name, bg.RuleIdx) + return fmt.Sprintf("group_%s__%s_rule%d", bg.Source.Namespace, bg.Source.Name, bg.RuleIdx) } // Backend represents a Backend for a routing rule. diff --git a/site/content/how-to/monitoring/troubleshooting.md b/site/content/how-to/monitoring/troubleshooting.md index c14d72ea83..7ea6eb0285 100644 --- a/site/content/how-to/monitoring/troubleshooting.md +++ b/site/content/how-to/monitoring/troubleshooting.md @@ -294,6 +294,7 @@ Verify that the port number (for example, `8080`) matches the port number you ha ### Common errors {{< bootstrap-table "table table-striped table-bordered" >}} + | Problem Area | Symptom | Troubleshooting Method | Common Cause | |------------------------------|----------------------------------------|---------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------| | Startup | NGINX Gateway Fabric fails to start. | Check logs for _nginx_ and _nginx-gateway_ containers. | Readiness probe failed. | @@ -301,6 +302,7 @@ Verify that the port number (for example, `8080`) matches the port number you ha | NGINX errors | Reload failures on NGINX | Fix permissions for control plane. | Security context not configured. | | Usage reporting | Errors logs related to usage reporting | Enable usage reporting. Refer to [Usage Reporting]({{< relref "installation/usage-reporting.md" >}}) | Usage reporting disabled. | | Client Settings | Request entity too large error | Adjust client settings. Refer to [Client Settings Policy]({{< relref "../traffic-management/client-settings.md" >}}) | Payload is greater than the [`client_max_body_size`](https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size) value.| + {{< /bootstrap-table >}} ##### NGINX fails to reload