Skip to content

Commit 0c00b58

Browse files
committed
Update backend group name with a prefix (nginx#2730)
Update backend group name with a prefix Problem: User want to configure split client upstream in a namespace starting with a digit without running into any issues. Solution: Updated backend group name with a prefix "group_". Hence, we update split client variable names, distribution names and upstream names.
1 parent 59000b2 commit 0c00b58

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

internal/mode/static/nginx/config/servers_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ func TestCreateServers(t *testing.T) {
11501150
},
11511151
{
11521152
Path: "/_ngf-internal-rule1-route0",
1153-
ProxyPass: "http://$test__route1_rule1$request_uri",
1153+
ProxyPass: "http://$group_test__route1_rule1$request_uri",
11541154
ProxySetHeaders: httpBaseHeaders,
11551155
Type: http.InternalLocationType,
11561156
Includes: internalIncludes,
@@ -2810,7 +2810,7 @@ func TestCreateProxyPass(t *testing.T) {
28102810
},
28112811
},
28122812
{
2813-
expected: "http://$ns1__bg_rule0$request_uri",
2813+
expected: "http://$group_ns1__bg_rule0$request_uri",
28142814
grp: dataplane.BackendGroup{
28152815
Source: types.NamespacedName{Namespace: "ns1", Name: "bg"},
28162816
Backends: []dataplane.Backend{

internal/mode/static/nginx/config/split_clients_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func TestExecuteSplitClients(t *testing.T) {
5252
bg3,
5353
},
5454
expStrings: []string{
55-
"split_clients $request_id $test__hr_rule0",
56-
"split_clients $request_id $test__hr_rule1",
55+
"split_clients $request_id $group_test__hr_rule0",
56+
"split_clients $request_id $group_test__hr_rule1",
5757
"50.00% test1;",
5858
"50.00% test2;",
5959
"50.00% test3;",
@@ -74,7 +74,7 @@ func TestExecuteSplitClients(t *testing.T) {
7474
},
7575
},
7676
expStrings: []string{
77-
"split_clients $request_id $test__zero_percent_rule0",
77+
"split_clients $request_id $group_test__zero_percent_rule0",
7878
"100.00% non-zero;",
7979
"# 0.00% zero;",
8080
},
@@ -188,7 +188,7 @@ func TestCreateSplitClients(t *testing.T) {
188188
},
189189
expSplitClients: []http.SplitClient{
190190
{
191-
VariableName: "test__hr_one_split_rule0",
191+
VariableName: "group_test__hr_one_split_rule0",
192192
Distributions: []http.SplitClientDistribution{
193193
{
194194
Percent: "50.00",
@@ -201,7 +201,7 @@ func TestCreateSplitClients(t *testing.T) {
201201
},
202202
},
203203
{
204-
VariableName: "test__hr_two_splits_rule0",
204+
VariableName: "group_test__hr_two_splits_rule0",
205205
Distributions: []http.SplitClientDistribution{
206206
{
207207
Percent: "50.00",
@@ -214,7 +214,7 @@ func TestCreateSplitClients(t *testing.T) {
214214
},
215215
},
216216
{
217-
VariableName: "test__hr_two_splits_rule1",
217+
VariableName: "group_test__hr_two_splits_rule1",
218218
Distributions: []http.SplitClientDistribution{
219219
{
220220
Percent: "33.33",
@@ -661,7 +661,7 @@ func TestBackendGroupName(t *testing.T) {
661661
Weight: 1,
662662
},
663663
},
664-
expName: "test__hr_rule0",
664+
expName: "group_test__hr_rule0",
665665
},
666666
{
667667
msg: "multiple invalid backends",
@@ -677,7 +677,7 @@ func TestBackendGroupName(t *testing.T) {
677677
Weight: 1,
678678
},
679679
},
680-
expName: "test__hr_rule0",
680+
expName: "group_test__hr_rule0",
681681
},
682682
}
683683

internal/mode/static/state/dataplane/configuration_test.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -2992,20 +2992,21 @@ func TestBuildUpstreams(t *testing.T) {
29922992
g.Expect(upstreams).To(ConsistOf(expUpstreams))
29932993
}
29942994

2995-
func TestBuildBackendGroups(t *testing.T) {
2996-
t.Parallel()
2997-
createBackendGroup := func(name string, ruleIdx int, backendNames ...string) BackendGroup {
2998-
backends := make([]Backend, len(backendNames))
2999-
for i, name := range backendNames {
3000-
backends[i] = Backend{UpstreamName: name}
3001-
}
2995+
func createBackendGroup(name string, ruleIdx int, backendNames ...string) BackendGroup {
2996+
backends := make([]Backend, len(backendNames))
2997+
for i, name := range backendNames {
2998+
backends[i] = Backend{UpstreamName: name}
2999+
}
30023000

3003-
return BackendGroup{
3004-
Source: types.NamespacedName{Namespace: "test", Name: name},
3005-
RuleIdx: ruleIdx,
3006-
Backends: backends,
3007-
}
3001+
return BackendGroup{
3002+
Source: types.NamespacedName{Namespace: "test", Name: name},
3003+
RuleIdx: ruleIdx,
3004+
Backends: backends,
30083005
}
3006+
}
3007+
3008+
func TestBuildBackendGroups(t *testing.T) {
3009+
t.Parallel()
30093010

30103011
hr1Group0 := createBackendGroup("hr1", 0, "foo", "bar")
30113012

@@ -3061,10 +3062,19 @@ func TestBuildBackendGroups(t *testing.T) {
30613062
g := NewWithT(t)
30623063

30633064
result := buildBackendGroups(servers)
3064-
30653065
g.Expect(result).To(ConsistOf(expGroups))
30663066
}
30673067

3068+
func TestBackendGroupName(t *testing.T) {
3069+
t.Parallel()
3070+
backendGroup := createBackendGroup("route1", 2, "foo", "bar")
3071+
3072+
expectedGroupName := "group_test__route1_rule2"
3073+
3074+
g := NewWithT(t)
3075+
g.Expect(backendGroup.Name()).To(Equal(expectedGroupName))
3076+
}
3077+
30683078
func TestHostnameMoreSpecific(t *testing.T) {
30693079
t.Parallel()
30703080
tests := []struct {

internal/mode/static/state/dataplane/types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,13 @@ type BackendGroup struct {
267267

268268
// Name returns the name of the backend group.
269269
// This name must be unique across all HTTPRoutes and all rules within the same HTTPRoute.
270+
// It is prefixed with `group_` for cases when namespace name starts with a digit. Variable names
271+
// in nginx configuration cannot start with a digit.
270272
// The RuleIdx is used to make the name unique across all rules within the same HTTPRoute.
271273
// The RuleIdx may change for a given rule if an update is made to the HTTPRoute, but it will always match the index
272274
// of the rule in the stored HTTPRoute.
273275
func (bg *BackendGroup) Name() string {
274-
return fmt.Sprintf("%s__%s_rule%d", bg.Source.Namespace, bg.Source.Name, bg.RuleIdx)
276+
return fmt.Sprintf("group_%s__%s_rule%d", bg.Source.Namespace, bg.Source.Name, bg.RuleIdx)
275277
}
276278

277279
// Backend represents a Backend for a routing rule.

site/content/how-to/monitoring/troubleshooting.md

+2
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,15 @@ Verify that the port number (for example, `8080`) matches the port number you ha
294294
### Common errors
295295

296296
{{< bootstrap-table "table table-striped table-bordered" >}}
297+
297298
| Problem Area | Symptom | Troubleshooting Method | Common Cause |
298299
|------------------------------|----------------------------------------|---------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
299300
| Startup | NGINX Gateway Fabric fails to start. | Check logs for _nginx_ and _nginx-gateway_ containers. | Readiness probe failed. |
300301
| Resources not configured | Status missing on resources. | Check referenced resources. | Referenced resources do not belong to NGINX Gateway Fabric. |
301302
| NGINX errors | Reload failures on NGINX | Fix permissions for control plane. | Security context not configured. |
302303
| Usage reporting | Errors logs related to usage reporting | Enable usage reporting. Refer to [Usage Reporting]({{< relref "installation/usage-reporting.md" >}}) | Usage reporting disabled. |
303304
| 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.|
305+
304306
{{< /bootstrap-table >}}
305307

306308
##### NGINX fails to reload

0 commit comments

Comments
 (0)