Skip to content

Commit 9060ba6

Browse files
authored
Add IsPlus to Telemetry (#5571)
1 parent 0c54622 commit 9060ba6

File tree

8 files changed

+119
-0
lines changed

8 files changed

+119
-0
lines changed

docs/content/overview/product-telemetry.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ These are the data points collected and reported by NGINX Ingress Controller:
4848
- **WAFPolicies** Number of WAF policies.
4949
- **GlobalConfiguration** Represents the use of a GlobalConfiguration resource.
5050
- **AppProtectVersion** The AppProtect version
51+
- **IsPlus** Represents whether NGINX is Plus or OSS
5152

5253
## Opt out
5354

internal/k8s/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
374374
Name: os.Getenv("POD_NAME"),
375375
},
376376
Policies: lbc.getAllPolicies,
377+
IsPlus: lbc.isNginxPlus,
377378
}
378379
collector, err := telemetry.NewCollector(
379380
collectorConfig,

internal/telemetry/cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ func (c *Collector) AppProtectVersion() string {
197197
return c.Config.AppProtectVersion
198198
}
199199

200+
// IsPlusEnabled returns true or false depending on if NGINX is Plus or OSS
201+
func (c *Collector) IsPlusEnabled() bool {
202+
return c.Config.IsPlus
203+
}
204+
200205
// lookupPlatform takes a string representing a K8s PlatformID
201206
// retrieved from a cluster node and returns a string
202207
// representing the platform name.

internal/telemetry/collector.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type CollectorConfig struct {
7474

7575
// AppProtectVersion represents the version of App Protect.
7676
AppProtectVersion string
77+
78+
// IsPlus represents whether NGINX is Plus or OSS
79+
IsPlus bool
7780
}
7881

7982
// NewCollector takes 0 or more options and creates a new TraceReporter.
@@ -137,6 +140,7 @@ func (c *Collector) Collect(ctx context.Context) {
137140
GlobalConfiguration: report.GlobalConfiguration,
138141
IngressAnnotations: report.IngressAnnotations,
139142
AppProtectVersion: report.AppProtectVersion,
143+
IsPlus: report.IsPlus,
140144
},
141145
}
142146

@@ -178,6 +182,7 @@ type Report struct {
178182
GlobalConfiguration bool
179183
IngressAnnotations []string
180184
AppProtectVersion string
185+
IsPlus bool
181186
}
182187

183188
// BuildReport takes context, collects telemetry data and builds the report.
@@ -248,6 +253,8 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
248253

249254
appProtectVersion := c.AppProtectVersion()
250255

256+
isPlus := c.IsPlusEnabled()
257+
251258
return Report{
252259
Name: "NIC",
253260
Version: c.Config.Version,
@@ -276,5 +283,6 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
276283
GlobalConfiguration: c.Config.GlobalConfiguration,
277284
IngressAnnotations: ingressAnnotations,
278285
AppProtectVersion: appProtectVersion,
286+
IsPlus: isPlus,
279287
}, err
280288
}

internal/telemetry/collector_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,104 @@ func TestCollectPoliciesReport(t *testing.T) {
389389
}
390390
}
391391

392+
func TestCollectIsPlus(t *testing.T) {
393+
t.Parallel()
394+
395+
testCases := []struct {
396+
name string
397+
isPlus bool
398+
want bool
399+
}{
400+
{
401+
name: "Plus enabled",
402+
isPlus: true,
403+
want: true,
404+
},
405+
{
406+
name: "Plus disabled",
407+
isPlus: false,
408+
want: false,
409+
},
410+
}
411+
412+
for _, tc := range testCases {
413+
t.Run(tc.name, func(t *testing.T) {
414+
buf := &bytes.Buffer{}
415+
exp := &telemetry.StdoutExporter{Endpoint: buf}
416+
417+
configurator := newConfiguratorWithIngress(t)
418+
419+
cfg := telemetry.CollectorConfig{
420+
Configurator: configurator,
421+
K8sClientReader: newTestClientset(node1, kubeNS),
422+
Version: telemetryNICData.ProjectVersion,
423+
IsPlus: tc.isPlus,
424+
}
425+
426+
c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
427+
if err != nil {
428+
t.Fatal(err)
429+
}
430+
c.Collect(context.Background())
431+
432+
ver := c.IsPlusEnabled()
433+
434+
if tc.want != ver {
435+
t.Errorf("want: %t, got: %t", tc.want, ver)
436+
}
437+
})
438+
}
439+
}
440+
441+
func TestCollectInvalidIsPlus(t *testing.T) {
442+
t.Parallel()
443+
444+
testCases := []struct {
445+
name string
446+
isPlus bool
447+
want bool
448+
}{
449+
{
450+
name: "Plus disabled but want enabled",
451+
isPlus: false,
452+
want: true,
453+
},
454+
{
455+
name: "Plus disabled but want enabled",
456+
isPlus: false,
457+
want: true,
458+
},
459+
}
460+
461+
for _, tc := range testCases {
462+
t.Run(tc.name, func(t *testing.T) {
463+
buf := &bytes.Buffer{}
464+
exp := &telemetry.StdoutExporter{Endpoint: buf}
465+
466+
configurator := newConfiguratorWithIngress(t)
467+
468+
cfg := telemetry.CollectorConfig{
469+
Configurator: configurator,
470+
K8sClientReader: newTestClientset(node1, kubeNS),
471+
Version: telemetryNICData.ProjectVersion,
472+
IsPlus: tc.isPlus,
473+
}
474+
475+
c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
476+
if err != nil {
477+
t.Fatal(err)
478+
}
479+
c.Collect(context.Background())
480+
481+
ver := c.IsPlusEnabled()
482+
483+
if tc.want == ver {
484+
t.Errorf("want: %t, got: %t", tc.want, ver)
485+
}
486+
})
487+
}
488+
}
489+
392490
func TestIngressCountReportsNoDeployedIngresses(t *testing.T) {
393491
t.Parallel()
394492

internal/telemetry/data.avdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,8 @@ It is the UID of the `kube-system` Namespace. */
9090
/** AppProtectVersion represents the version of AppProtect. */
9191
string? AppProtectVersion = null;
9292

93+
/** IsPlus represents whether NGINX is Plus or OSS */
94+
boolean? IsPlus = null;
95+
9396
}
9497
}

internal/telemetry/exporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ type NICResourceCounts struct {
103103
IngressAnnotations []string
104104
// AppProtectVersion represents the version of AppProtect.
105105
AppProtectVersion string
106+
// IsPlus represents whether NGINX is Plus or OSS
107+
IsPlus bool
106108
}

internal/telemetry/nicresourcecounts_attributes_generated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
3232
attrs = append(attrs, attribute.Bool("GlobalConfiguration", d.GlobalConfiguration))
3333
attrs = append(attrs, attribute.StringSlice("IngressAnnotations", d.IngressAnnotations))
3434
attrs = append(attrs, attribute.String("AppProtectVersion", d.AppProtectVersion))
35+
attrs = append(attrs, attribute.Bool("IsPlus", d.IsPlus))
3536

3637
return attrs
3738
}

0 commit comments

Comments
 (0)