Skip to content

Commit 0cb75c8

Browse files
mergify[bot]michel-latermanclaudeycombinator
authored
fix: correct typos in default rate limit YAML keys (#6835) (#6847)
* fix: correct typos in default rate limit YAML keys The embedded default YAML files used `pgp_retieval_limit` (missing 'r') instead of `pgp_retrieval_limit`, causing the values to never deserialize into the Go struct. PGP retrieval limits silently fell back to hardcoded defaults for all agent-count tiers. Also fixes `policy_interval` -> `policy_limit` in lte10000_limits.yml and renames `lte2500_limite.yml` -> `lte2500_limits.yml`. Adds a regression test that verifies all embedded YAML files populate every limit field, catching future key/struct-tag mismatches. * test: use reflection to validate YAML keys match struct tags Replace manually enumerated field assertions with a reflection-based approach that reads raw YAML keys and verifies each has a matching `config` struct tag on serverLimitDefaults. This catches typos automatically without needing to update the test when fields are added. * Cleanup test code * Update internal/pkg/config/env_defaults_test.go --------- (cherry picked from commit 47b6210) Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
1 parent 63edaed commit 0cb75c8

8 files changed

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: bug-fix
2+
summary: Fix typos in default rate limit YAML keys that prevented PGP retrieval and policy limits from loading
3+
component: fleet-server

‎internal/pkg/config/defaults/lte10000_limits.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ server_limits:
1010
action_limit:
1111
interval: 1ms
1212
burst: 10
13-
policy_interval:
13+
policy_limit:
1414
interval: 5ms
1515
burst: 1
1616
checkin_limit:
@@ -49,7 +49,7 @@ server_limits:
4949
interval: 100ms
5050
burst: 40
5151
max: 80
52-
pgp_retieval_limit:
52+
pgp_retrieval_limit:
5353
interval: 1ms
5454
burst: 2000
5555
max: 4000

‎internal/pkg/config/defaults/lte20000_limits.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ server_limits:
4949
interval: 100ms
5050
burst: 40
5151
max: 80
52-
pgp_retieval_limit:
52+
pgp_retrieval_limit:
5353
interval: 0.5ms
5454
burst: 4000
5555
max: 8000

internal/pkg/config/defaults/lte2500_limite.yml renamed to internal/pkg/config/defaults/lte2500_limits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ server_limits:
4949
interval: 100ms
5050
burst: 10
5151
max: 20
52-
pgp_retieval_limit:
52+
pgp_retrieval_limit:
5353
interval: 5ms
5454
burst: 500
5555
max: 1000

‎internal/pkg/config/defaults/lte40000_limits.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ server_limits:
4848
interval: 100ms
4949
burst: 40
5050
max: 80
51-
pgp_retieval_limit:
51+
pgp_retrieval_limit:
5252
interval: 0.5ms
5353
burst: 4000
5454
max: 8000

‎internal/pkg/config/defaults/lte5000_limits.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ server_limits:
4949
interval: 100ms
5050
burst: 20
5151
max: 40
52-
pgp_retieval_limit:
52+
pgp_retrieval_limit:
5353
interval: 2ms
5454
burst: 1000
5555
max: 2000

‎internal/pkg/config/defaults/max_limits.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ server_limits:
4747
interval: 100ms
4848
burst: 40
4949
max: 80
50-
pgp_retieval_limit:
50+
pgp_retrieval_limit:
5151
interval: 0.25ms
5252
burst: 8000
5353
max: 16000

‎internal/pkg/config/env_defaults_test.go‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5-
// Code generated by dev-tools/cmd/buildlimits/buildlimits.go - DO NOT EDIT.
6-
75
package config
86

97
import (
8+
"io"
9+
"io/fs"
10+
"reflect"
11+
"strings"
1012
"testing"
1113

1214
testlog "github.com/elastic/fleet-server/v7/internal/pkg/testing/log"
1315

1416
"github.com/rs/zerolog"
17+
"github.com/stretchr/testify/assert"
1518
"github.com/stretchr/testify/require"
19+
goyaml "gopkg.in/yaml.v3"
1620
)
1721

1822
func TestLoadLimits(t *testing.T) {
@@ -39,3 +43,46 @@ func TestLoadLimits(t *testing.T) {
3943
})
4044
}
4145
}
46+
47+
// TestDefaultLimitsYAML keys verifies that all embedded .yml files have keys that match go struct tags.
48+
// A typo in a yml key, e.g. "pgp_retieval_limit" instead of "pgp_retrieval_limit" causes a test failure.
49+
func TestDefaultLimitsYAMLKeys(t *testing.T) {
50+
rt := reflect.TypeOf(serverLimitDefaults{})
51+
validTags := make([]string, 0, rt.NumField())
52+
for field := range rt.Fields() {
53+
if tag := field.Tag.Get("config"); tag != "" {
54+
validTags = append(validTags, tag)
55+
}
56+
}
57+
58+
require.NotEmpty(t, defaults, "embedded defaults should be loaded")
59+
err := fs.WalkDir(defaultsFS, ".", func(path string, d fs.DirEntry, walkErr error) error {
60+
if walkErr != nil {
61+
return walkErr
62+
}
63+
if d.IsDir() {
64+
return nil
65+
}
66+
67+
name := strings.TrimSuffix(strings.TrimPrefix(path, "defaults/"), "_limits.yml")
68+
t.Run(name, func(t *testing.T) {
69+
f, err := defaultsFS.Open(path)
70+
require.NoError(t, err)
71+
data, err := io.ReadAll(f)
72+
require.NoError(t, err)
73+
74+
var raw map[string]any
75+
require.NoError(t, goyaml.Unmarshal(data, &raw))
76+
77+
require.Containsf(t, raw, "server_limits", "%s does not contain server_limits attribute", path)
78+
serverLimits, ok := raw["server_limits"].(map[string]any)
79+
require.Truef(t, ok, "server_limits in %s is not type map[string]any detected type: %T", path, raw["server_limits"])
80+
81+
for key := range serverLimits {
82+
assert.Contains(t, validTags, key, "YAML key %q in %s has no matching config struct tag on serverLimitDefaults", key, path)
83+
}
84+
})
85+
return nil
86+
})
87+
require.NoError(t, err)
88+
}

0 commit comments

Comments
 (0)