Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/overview/product-telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ These are the data points collected and reported by NGINX Ingress Controller:
- **WAFPolicies** Number of WAF policies.
- **GlobalConfiguration** Represents the use of a GlobalConfiguration resource.
- **AppProtectVersion** The AppProtect version
- **IsPlus** Represents whether NGINX is Plus or OSS

## Opt out

Expand Down
1 change: 1 addition & 0 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
Name: os.Getenv("POD_NAME"),
},
Policies: lbc.getAllPolicies,
IsPlus: lbc.isNginxPlus,
}
collector, err := telemetry.NewCollector(
collectorConfig,
Expand Down
5 changes: 5 additions & 0 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func (c *Collector) AppProtectVersion() string {
return c.Config.AppProtectVersion
}

// IsPlusEnabled returns true or false depending on if NGINX is Plus or OSS
func (c *Collector) IsPlusEnabled() bool {
return c.Config.IsPlus
}

// lookupPlatform takes a string representing a K8s PlatformID
// retrieved from a cluster node and returns a string
// representing the platform name.
Expand Down
8 changes: 8 additions & 0 deletions internal/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type CollectorConfig struct {

// AppProtectVersion represents the version of App Protect.
AppProtectVersion string

// IsPlus represents whether NGINX is Plus or OSS
IsPlus bool
}

// NewCollector takes 0 or more options and creates a new TraceReporter.
Expand Down Expand Up @@ -137,6 +140,7 @@ func (c *Collector) Collect(ctx context.Context) {
GlobalConfiguration: report.GlobalConfiguration,
IngressAnnotations: report.IngressAnnotations,
AppProtectVersion: report.AppProtectVersion,
IsPlus: report.IsPlus,
},
}

Expand Down Expand Up @@ -178,6 +182,7 @@ type Report struct {
GlobalConfiguration bool
IngressAnnotations []string
AppProtectVersion string
IsPlus bool
}

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

appProtectVersion := c.AppProtectVersion()

isPlus := c.IsPlusEnabled()

return Report{
Name: "NIC",
Version: c.Config.Version,
Expand Down Expand Up @@ -276,5 +283,6 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
GlobalConfiguration: c.Config.GlobalConfiguration,
IngressAnnotations: ingressAnnotations,
AppProtectVersion: appProtectVersion,
IsPlus: isPlus,
}, err
}
98 changes: 98 additions & 0 deletions internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,104 @@ func TestCollectPoliciesReport(t *testing.T) {
}
}

func TestCollectIsPlus(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
isPlus bool
want bool
}{
{
name: "Plus enabled",
isPlus: true,
want: true,
},
{
name: "Plus disabled",
isPlus: false,
want: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
buf := &bytes.Buffer{}
exp := &telemetry.StdoutExporter{Endpoint: buf}

configurator := newConfiguratorWithIngress(t)

cfg := telemetry.CollectorConfig{
Configurator: configurator,
K8sClientReader: newTestClientset(node1, kubeNS),
Version: telemetryNICData.ProjectVersion,
IsPlus: tc.isPlus,
}

c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
if err != nil {
t.Fatal(err)
}
c.Collect(context.Background())

ver := c.IsPlusEnabled()

if tc.want != ver {
t.Errorf("want: %t, got: %t", tc.want, ver)
}
})
}
}

func TestCollectInvalidIsPlus(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
isPlus bool
want bool
}{
{
name: "Plus disabled but want enabled",
isPlus: false,
want: true,
},
{
name: "Plus disabled but want enabled",
isPlus: false,
want: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
buf := &bytes.Buffer{}
exp := &telemetry.StdoutExporter{Endpoint: buf}

configurator := newConfiguratorWithIngress(t)

cfg := telemetry.CollectorConfig{
Configurator: configurator,
K8sClientReader: newTestClientset(node1, kubeNS),
Version: telemetryNICData.ProjectVersion,
IsPlus: tc.isPlus,
}

c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
if err != nil {
t.Fatal(err)
}
c.Collect(context.Background())

ver := c.IsPlusEnabled()

if tc.want == ver {
t.Errorf("want: %t, got: %t", tc.want, ver)
}
})
}
}

func TestIngressCountReportsNoDeployedIngresses(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 3 additions & 0 deletions internal/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ It is the UID of the `kube-system` Namespace. */
/** AppProtectVersion represents the version of AppProtect. */
string? AppProtectVersion = null;

/** IsPlus represents whether NGINX is Plus or OSS */
boolean? IsPlus = null;

}
}
2 changes: 2 additions & 0 deletions internal/telemetry/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ type NICResourceCounts struct {
IngressAnnotations []string
// AppProtectVersion represents the version of AppProtect.
AppProtectVersion string
// IsPlus represents whether NGINX is Plus or OSS
IsPlus bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.Bool("GlobalConfiguration", d.GlobalConfiguration))
attrs = append(attrs, attribute.StringSlice("IngressAnnotations", d.IngressAnnotations))
attrs = append(attrs, attribute.String("AppProtectVersion", d.AppProtectVersion))
attrs = append(attrs, attribute.Bool("IsPlus", d.IsPlus))

return attrs
}
Expand Down