Skip to content

Commit d1cc306

Browse files
committed
Change all instances of contextDirective to directiveContext naming
1 parent 8e25b8c commit d1cc306

File tree

7 files changed

+75
-63
lines changed

7 files changed

+75
-63
lines changed

internal/mode/static/telemetry/collector.go

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ type Data struct {
5050
// at the same index.
5151
// Each value is either 'true' or 'false' for boolean flags and 'default' or 'user-defined' for non-boolean flags.
5252
FlagValues []string
53-
// SnippetsFiltersContextDirectives contains the context-directive strings of all applied SnippetsFilters.
54-
// Both lists are ordered first by count, then by lexicographical order on the context-directive string.
55-
SnippetsFiltersContextDirectives []string
56-
// SnippetsFiltersContextDirectivesCount contains the count of the context-directive strings, where each count
57-
// corresponds to the string from SnippetsFiltersContextDirectives at the same index. Both lists are ordered
58-
// first by count, then by lexicographical order on the context-directive string.
59-
SnippetsFiltersContextDirectivesCount []int64
53+
// SnippetsFiltersDirectiveContexts contains the context-directive strings of all applied SnippetsFilters.
54+
// Both lists are ordered first by count, then by lexicographical order of the context string,
55+
// then lastly by directive string.
56+
SnippetsFiltersDirectiveContexts []string
57+
// SnippetsFiltersDirectiveContextsCount contains the count of the directive-context strings, where each count
58+
// corresponds to the string from SnippetsFiltersDirectiveContexts at the same index.
59+
// Both lists are ordered first by count, then by lexicographical order of the context string,
60+
// then lastly by directive string.
61+
SnippetsFiltersDirectiveContextsCount []int64
6062
NGFResourceCounts // embedding is required by the generator.
6163
// NGFReplicaCount is the number of replicas of the NGF Pod.
6264
NGFReplicaCount int64
@@ -156,8 +158,8 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
156158
return Data{}, fmt.Errorf("failed to get NGF deploymentID: %w", err)
157159
}
158160

159-
snippetsFiltersContextDirectives,
160-
snippetsFiltersContextDirectivesCount,
161+
snippetsFiltersDirectiveContexts,
162+
snippetsFiltersDirectiveContextsCount,
161163
err := collectSnippetsFilterSnippetsInfo(c.cfg.GraphGetter)
162164
if err != nil {
163165
return Data{}, fmt.Errorf("failed to collect snippet filter directive info: %w", err)
@@ -180,8 +182,8 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
180182
FlagValues: c.cfg.Flags.Values,
181183
NGFReplicaCount: int64(replicaCount),
182184
// maybe SnippetValues?
183-
SnippetsFiltersContextDirectives: snippetsFiltersContextDirectives,
184-
SnippetsFiltersContextDirectivesCount: snippetsFiltersContextDirectivesCount,
185+
SnippetsFiltersDirectiveContexts: snippetsFiltersDirectiveContexts,
186+
SnippetsFiltersDirectiveContextsCount: snippetsFiltersDirectiveContextsCount,
185187
}
186188

187189
return data, nil
@@ -403,7 +405,7 @@ func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (cl
403405
return clusterInfo, nil
404406
}
405407

406-
type sfContextDirective struct {
408+
type sfDirectiveContext struct {
407409
context string
408410
directive string
409411
}
@@ -414,7 +416,7 @@ func collectSnippetsFilterSnippetsInfo(graphGetter GraphGetter) ([]string, []int
414416
return nil, nil, errors.New("latest graph cannot be nil")
415417
}
416418

417-
contextDirectiveMap := make(map[sfContextDirective]int)
419+
directiveContextMap := make(map[sfDirectiveContext]int)
418420

419421
for _, sf := range g.SnippetsFilters {
420422
if sf == nil {
@@ -439,18 +441,18 @@ func collectSnippetsFilterSnippetsInfo(graphGetter GraphGetter) ([]string, []int
439441

440442
directives := parseSnippetValueIntoDirectives(snippetValue)
441443
for _, directive := range directives {
442-
contextDirective := sfContextDirective{
444+
directiveContext := sfDirectiveContext{
443445
context: parsedContext,
444446
directive: directive,
445447
}
446-
contextDirectiveMap[contextDirective]++
448+
directiveContextMap[directiveContext]++
447449
}
448450
}
449451
}
450452

451-
contextDirectiveList, countList := parseContextDirectiveMapIntoLists(contextDirectiveMap)
453+
directiveContextList, countList := parseDirectiveContextMapIntoLists(directiveContextMap)
452454

453-
return contextDirectiveList, countList, nil
455+
return directiveContextList, countList, nil
454456
}
455457

456458
func parseSnippetValueIntoDirectives(snippetValue string) []string {
@@ -471,37 +473,41 @@ func parseSnippetValueIntoDirectives(snippetValue string) []string {
471473
return directives
472474
}
473475

474-
// parseContextDirectiveMapIntoLists returns two same-length lists where the elements at each corresponding index
476+
// parseDirectiveContextMapIntoLists returns two same-length lists where the elements at each corresponding index
475477
// are paired together.
476-
// The first list contains strings which are the NGINX context and directive of a Snippet joined with a hyphen.
477-
// The second list contains ints which are the count of total same context-directive values of the first list.
478-
// Both lists are ordered based off of count first, then lexicographically on the context-directive string.
479-
func parseContextDirectiveMapIntoLists(contextDirectiveMap map[sfContextDirective]int) ([]string, []int64) {
480-
type sfContextDirectiveCount struct {
481-
contextDirective string
482-
count int64
478+
// The first list contains strings which are the NGINX directive and context of a Snippet joined with a hyphen.
479+
// The second list contains ints which are the count of total same directive-context values of the first list.
480+
// Both lists are ordered first by count, then by lexicographical order of the context string,
481+
// then lastly by directive string.
482+
func parseDirectiveContextMapIntoLists(directiveContextMap map[sfDirectiveContext]int) ([]string, []int64) {
483+
type sfDirectiveContextCount struct {
484+
directive, context string
485+
count int64
483486
}
484487

485-
kvPairs := make([]sfContextDirectiveCount, 0, len(contextDirectiveMap))
488+
kvPairs := make([]sfDirectiveContextCount, 0, len(directiveContextMap))
486489

487-
for k, v := range contextDirectiveMap {
488-
kvPairs = append(kvPairs, sfContextDirectiveCount{k.context + "-" + k.directive, int64(v)})
490+
for k, v := range directiveContextMap {
491+
kvPairs = append(kvPairs, sfDirectiveContextCount{k.directive, k.context, int64(v)})
489492
}
490493

491494
sort.Slice(kvPairs, func(i, j int) bool {
492495
if kvPairs[i].count == kvPairs[j].count {
493-
return kvPairs[i].contextDirective < kvPairs[j].contextDirective
496+
if kvPairs[i].context == kvPairs[j].context {
497+
return kvPairs[i].directive < kvPairs[j].directive
498+
}
499+
return kvPairs[i].context < kvPairs[j].context
494500
}
495501
return kvPairs[i].count > kvPairs[j].count
496502
})
497503

498-
contextDirectiveList := make([]string, len(kvPairs))
504+
directiveContextList := make([]string, len(kvPairs))
499505
countList := make([]int64, len(kvPairs))
500506

501507
for i, pair := range kvPairs {
502-
contextDirectiveList[i] = pair.contextDirective
508+
directiveContextList[i] = pair.directive + "-" + pair.context
503509
countList[i] = pair.count
504510
}
505511

506-
return contextDirectiveList, countList
512+
return directiveContextList, countList
507513
}

internal/mode/static/telemetry/collector_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ var _ = Describe("Collector", Ordered, func() {
174174
ImageSource: "local",
175175
FlagNames: flags.Names,
176176
FlagValues: flags.Values,
177-
SnippetsFiltersContextDirectives: []string{},
178-
SnippetsFiltersContextDirectivesCount: []int64{},
177+
SnippetsFiltersDirectiveContexts: []string{},
178+
SnippetsFiltersDirectiveContextsCount: []int64{},
179179
}
180180

181181
k8sClientReader = &eventsfakes.FakeReader{}
@@ -354,6 +354,8 @@ var _ = Describe("Collector", Ordered, func() {
354354
},
355355
{Namespace: "test", Name: "sf-3"}: {
356356
Snippets: map[ngfAPI.NginxContext]string{
357+
// Tests lexicographical ordering when count and context is the same
358+
ngfAPI.NginxContextMain: "worker_rlimit_core 1m;",
357359
ngfAPI.NginxContextHTTPServer: "auth_delay 10s;",
358360
},
359361
},
@@ -414,17 +416,18 @@ var _ = Describe("Collector", Ordered, func() {
414416
expData.ClusterVersion = "1.29.2"
415417
expData.ClusterPlatform = "kind"
416418

417-
expData.SnippetsFiltersContextDirectives = []string{
418-
"server-auth_delay",
419-
"http-aio",
420-
"location-keepalive_time",
421-
"main-worker_priority",
422-
"http-client_body_timeout",
423-
"location-allow",
424-
"main-worker_rlimit_nofile",
425-
"server-ignore_invalid_headers",
419+
expData.SnippetsFiltersDirectiveContexts = []string{
420+
"auth_delay-server",
421+
"aio-http",
422+
"keepalive_time-location",
423+
"worker_priority-main",
424+
"client_body_timeout-http",
425+
"allow-location",
426+
"worker_rlimit_core-main",
427+
"worker_rlimit_nofile-main",
428+
"ignore_invalid_headers-server",
426429
}
427-
expData.SnippetsFiltersContextDirectivesCount = []int64{
430+
expData.SnippetsFiltersDirectiveContextsCount = []int64{
428431
3,
429432
2,
430433
2,
@@ -433,6 +436,7 @@ var _ = Describe("Collector", Ordered, func() {
433436
1,
434437
1,
435438
1,
439+
1,
436440
}
437441

438442
data, err := dataCollector.Collect(ctx)

internal/mode/static/telemetry/data.avdl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ at the same index.
4545
Each value is either 'true' or 'false' for boolean flags and 'default' or 'user-defined' for non-boolean flags. */
4646
union {null, array<string>} FlagValues = null;
4747

48-
/** SnippetsFiltersContextDirectives contains the context-directive strings of all applied SnippetsFilters.
49-
Both lists are ordered first by count, then by lexicographical order on the context-directive string. */
50-
union {null, array<string>} SnippetsFiltersContextDirectives = null;
51-
52-
/** SnippetsFiltersContextDirectivesCount contains the count of the context-directive strings, where each count
53-
corresponds to the string from SnippetsFiltersContextDirectives at the same index. Both lists are ordered
54-
first by count, then by lexicographical order on the context-directive string. */
55-
union {null, array<long>} SnippetsFiltersContextDirectivesCount = null;
48+
/** SnippetsFiltersDirectiveContexts contains the context-directive strings of all applied SnippetsFilters.
49+
Both lists are ordered first by count, then by lexicographical order of the context string,
50+
then lastly by directive string. */
51+
union {null, array<string>} SnippetsFiltersDirectiveContexts = null;
52+
53+
/** SnippetsFiltersDirectiveContextsCount contains the count of the directive-context strings, where each count
54+
corresponds to the string from SnippetsFiltersDirectiveContexts at the same index.
55+
Both lists are ordered first by count, then by lexicographical order of the context string,
56+
then lastly by directive string. */
57+
union {null, array<long>} SnippetsFiltersDirectiveContextsCount = null;
5658

5759
/** GatewayCount is the number of relevant Gateways. */
5860
long? GatewayCount = null;

internal/mode/static/telemetry/data_attributes_generated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func (d *Data) Attributes() []attribute.KeyValue {
1717
attrs = append(attrs, d.Data.Attributes()...)
1818
attrs = append(attrs, attribute.StringSlice("FlagNames", d.FlagNames))
1919
attrs = append(attrs, attribute.StringSlice("FlagValues", d.FlagValues))
20-
attrs = append(attrs, attribute.StringSlice("SnippetsFiltersContextDirectives", d.SnippetsFiltersContextDirectives))
21-
attrs = append(attrs, attribute.Int64Slice("SnippetsFiltersContextDirectivesCount", d.SnippetsFiltersContextDirectivesCount))
20+
attrs = append(attrs, attribute.StringSlice("SnippetsFiltersDirectiveContexts", d.SnippetsFiltersDirectiveContexts))
21+
attrs = append(attrs, attribute.Int64Slice("SnippetsFiltersDirectiveContextsCount", d.SnippetsFiltersDirectiveContextsCount))
2222
attrs = append(attrs, d.NGFResourceCounts.Attributes()...)
2323
attrs = append(attrs, attribute.Int64("NGFReplicaCount", d.NGFReplicaCount))
2424

internal/mode/static/telemetry/data_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func TestDataAttributes(t *testing.T) {
4141
SnippetsFilterCount: 13,
4242
},
4343
NGFReplicaCount: 3,
44-
SnippetsFiltersContextDirectives: []string{"main-three-count", "http-two-count", "server-one-count"},
45-
SnippetsFiltersContextDirectivesCount: []int64{3, 2, 1},
44+
SnippetsFiltersDirectiveContexts: []string{"main-three-count", "http-two-count", "server-one-count"},
45+
SnippetsFiltersDirectiveContextsCount: []int64{3, 2, 1},
4646
}
4747

4848
expected := []attribute.KeyValue{
@@ -59,10 +59,10 @@ func TestDataAttributes(t *testing.T) {
5959
attribute.StringSlice("FlagNames", []string{"test-flag"}),
6060
attribute.StringSlice("FlagValues", []string{"test-value"}),
6161
attribute.StringSlice(
62-
"SnippetsFiltersContextDirectives",
62+
"SnippetsFiltersDirectiveContexts",
6363
[]string{"main-three-count", "http-two-count", "server-one-count"},
6464
),
65-
attribute.IntSlice("SnippetsFiltersContextDirectivesCount", []int{3, 2, 1}),
65+
attribute.IntSlice("SnippetsFiltersDirectiveContextsCount", []int{3, 2, 1}),
6666
attribute.Int64("GatewayCount", 1),
6767
attribute.Int64("GatewayClassCount", 2),
6868
attribute.Int64("HTTPRouteCount", 3),
@@ -103,8 +103,8 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
103103
attribute.Int64("ClusterNodeCount", 0),
104104
attribute.StringSlice("FlagNames", nil),
105105
attribute.StringSlice("FlagValues", nil),
106-
attribute.StringSlice("SnippetsFiltersContextDirectives", nil),
107-
attribute.IntSlice("SnippetsFiltersContextDirectivesCount", nil),
106+
attribute.StringSlice("SnippetsFiltersDirectiveContexts", nil),
107+
attribute.IntSlice("SnippetsFiltersDirectiveContextsCount", nil),
108108
attribute.Int64("GatewayCount", 0),
109109
attribute.Int64("GatewayClassCount", 0),
110110
attribute.Int64("HTTPRouteCount", 0),

site/content/overview/product-telemetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Telemetry data is collected once every 24 hours and sent to a service managed by
2828
- **Image Build Source:** whether the image was built by GitHub or locally (values are `gha`, `local`, or `unknown`). The source repository of the images is **not** collected.
2929
- **Deployment Flags:** a list of NGINX Gateway Fabric Deployment flags that are specified by a user. The actual values of non-boolean flags are **not** collected; we only record that they are either `true` or `false` for boolean flags and `default` or `user-defined` for the rest.
3030
- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`,`GRPCRoutes`, `TLSRoutes`, `Secrets`, `Services`, `BackendTLSPolicies`, `ClientSettingsPolicies`, `NginxProxies`, `ObservabilityPolicies`, `SnippetsFilters`, and `Endpoints`. The data within these resources is **not** collected.
31-
- **SnippetsFilters Info**a list of context-directive strings from applied SnippetFilters and a total count per strings. The actual value of any NGINX directive is **not** collected.
31+
- **SnippetsFilters Info**a list of directive-context strings from applied SnippetFilters and a total count per strings. The actual value of any NGINX directive is **not** collected.
3232
This data is used to identify the following information:
3333

3434
- The flavors of Kubernetes environments that are most popular among our users.

tests/suite/telemetry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
7272
fmt.Sprintf("ClusterNodeCount: Int(%d)", info.NodeCount),
7373
"FlagNames: Slice",
7474
"FlagValues: Slice",
75-
"SnippetsFiltersContextDirectives: Slice",
76-
"SnippetsFiltersContextDirectivesCount: Slice",
75+
"SnippetsFiltersDirectiveContexts: Slice",
76+
"SnippetsFiltersDirectiveContextsCount: Slice",
7777
"GatewayCount: Int(0)",
7878
"GatewayClassCount: Int(1)",
7979
"HTTPRouteCount: Int(0)",

0 commit comments

Comments
 (0)