From b724879d153335f4fa2af6f884458da191b35500 Mon Sep 17 00:00:00 2001 From: AlexFenlon Date: Tue, 28 May 2024 15:17:48 +0100 Subject: [PATCH] Add Granular Ingress Counts to Telemetry (#5608) --- docs/content/overview/product-telemetry.md | 4 +- internal/telemetry/cluster.go | 27 ++++--- internal/telemetry/collector.go | 17 ++++- internal/telemetry/collector_test.go | 73 +++++++++++++++++-- internal/telemetry/data.avdl | 10 ++- internal/telemetry/exporter.go | 8 +- .../nicresourcecounts_attributes_generated.go | 4 +- 7 files changed, 115 insertions(+), 28 deletions(-) diff --git a/docs/content/overview/product-telemetry.md b/docs/content/overview/product-telemetry.md index c461b127f9..753a8477e3 100644 --- a/docs/content/overview/product-telemetry.md +++ b/docs/content/overview/product-telemetry.md @@ -35,7 +35,9 @@ These are the data points collected and reported by NGINX Ingress Controller: - **Replicas** Number of Deployment replicas, or Daemonset instances. - **Secrets** Number of Secret resources managed by NGINX Ingress Controller. - **Services** Number of Services referenced by VirtualServers, VirtualServerRoutes, TransportServers and Ingresses. -- **Ingresses** The number of Ingress resources managed by the NGINX Ingress Controller. +- **RegularIngressCount** The number of Regular Ingress resources managed by NGINX Ingress Controller. +- **MasterIngressCount** The number of Master Ingress resources managed by NGINX Ingress Controller. +- **MinionIngressCount** The number of Minion Ingress resources managed by NGINX Ingress Controller. - **IngressClasses** Number of Ingress Classes in the cluster. - **IngressAnnotations** List of Ingress annotations managed by NGINX Ingress Controller - **AccessControlPolicies** Number of AccessControl policies. diff --git a/internal/telemetry/cluster.go b/internal/telemetry/cluster.go index 191694a509..8125f098b0 100644 --- a/internal/telemetry/cluster.go +++ b/internal/telemetry/cluster.go @@ -123,17 +123,22 @@ func (c *Collector) Secrets() (int, error) { return len(c.Config.SecretStore.GetSecretReferenceMap()), nil } -// IngressCount returns number of Ingresses in the namespaces watched by NIC. -func (c *Collector) IngressCount() int { - if c.Config.Configurator == nil { - return 0 - } - ic := c.Config.Configurator.GetIngressCounts() - total := 0 - for _, v := range ic { - total += v - } - return total +// RegularIngressCount returns number of Minion Ingresses in the namespaces watched by NIC. +func (c *Collector) RegularIngressCount() int { + ingressCount := c.Config.Configurator.GetIngressCounts() + return ingressCount["regular"] +} + +// MasterIngressCount returns number of Minion Ingresses in the namespaces watched by NIC. +func (c *Collector) MasterIngressCount() int { + ingressCount := c.Config.Configurator.GetIngressCounts() + return ingressCount["master"] +} + +// MinionIngressCount returns number of Minion Ingresses in the namespaces watched by NIC. +func (c *Collector) MinionIngressCount() int { + ingressCount := c.Config.Configurator.GetIngressCounts() + return ingressCount["minion"] } // IngressAnnotations returns a list of all the unique annotations found in Ingresses. diff --git a/internal/telemetry/collector.go b/internal/telemetry/collector.go index 5fa5249e46..a032f57e55 100644 --- a/internal/telemetry/collector.go +++ b/internal/telemetry/collector.go @@ -130,7 +130,9 @@ func (c *Collector) Collect(ctx context.Context) { Replicas: int64(report.NICReplicaCount), Secrets: int64(report.Secrets), Services: int64(report.ServiceCount), - Ingresses: int64(report.IngressCount), + RegularIngressCount: int64(report.RegularIngressCount), + MasterIngressCount: int64(report.MasterIngressCount), + MinionIngressCount: int64(report.MinionIngressCount), IngressClasses: int64(report.IngressClassCount), AccessControlPolicies: int64(report.AccessControlCount), RateLimitPolicies: int64(report.RateLimitCount), @@ -173,7 +175,9 @@ type Report struct { ServiceCount int TransportServers int Secrets int - IngressCount int + RegularIngressCount int + MasterIngressCount int + MinionIngressCount int IngressClassCount int AccessControlCount int RateLimitCount int @@ -237,7 +241,10 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) { if err != nil { glog.V(3).Infof("Unable to collect telemetry data: Secrets: %v", err) } - ingressCount := c.IngressCount() + + regularIngressCount := c.RegularIngressCount() + masterIngressCount := c.MasterIngressCount() + minionIngressCount := c.MinionIngressCount() ingressClassCount, err := c.IngressClassCount(ctx) if err != nil { glog.V(3).Infof("Unable to collect telemetry data: Ingress Classes: %v", err) @@ -277,7 +284,9 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) { ServiceCount: serviceCount, TransportServers: tsCount, Secrets: secretCount, - IngressCount: ingressCount, + RegularIngressCount: regularIngressCount, + MasterIngressCount: masterIngressCount, + MinionIngressCount: minionIngressCount, IngressClassCount: ingressClassCount, AccessControlCount: accessControlCount, RateLimitCount: rateLimitCount, diff --git a/internal/telemetry/collector_test.go b/internal/telemetry/collector_test.go index 69aea3c5ee..e2ce8a9ae8 100644 --- a/internal/telemetry/collector_test.go +++ b/internal/telemetry/collector_test.go @@ -518,7 +518,7 @@ func TestIngressCountReportsNoDeployedIngresses(t *testing.T) { VirtualServers: 0, VirtualServerRoutes: 0, TransportServers: 0, - Ingresses: 0, + RegularIngressCount: 0, } td := telemetry.Data{ @@ -747,7 +747,7 @@ func TestIngressCountReportsNumberOfDeployedIngresses(t *testing.T) { VirtualServers: 0, VirtualServerRoutes: 0, TransportServers: 0, - Ingresses: 1, + RegularIngressCount: 1, Services: 2, } @@ -763,6 +763,57 @@ func TestIngressCountReportsNumberOfDeployedIngresses(t *testing.T) { } } +func TestMasterMinionIngressCountReportsNumberOfDeployedIngresses(t *testing.T) { + t.Parallel() + buf := &bytes.Buffer{} + exp := &telemetry.StdoutExporter{Endpoint: buf} + + configurator := newConfiguratorWithMergeableIngress(t) + + cfg := telemetry.CollectorConfig{ + Configurator: configurator, + K8sClientReader: newTestClientset(node1, kubeNS), + Version: telemetryNICData.ProjectVersion, + } + + c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp)) + if err != nil { + t.Fatal(err) + } + c.Collect(context.Background()) + + telData := tel.Data{ + ProjectName: telemetryNICData.ProjectName, + ProjectVersion: telemetryNICData.ProjectVersion, + ProjectArchitecture: telemetryNICData.ProjectArchitecture, + ClusterNodeCount: 1, + ClusterID: telemetryNICData.ClusterID, + ClusterVersion: telemetryNICData.ClusterVersion, + ClusterPlatform: "other", + } + + nicResourceCounts := telemetry.NICResourceCounts{ + VirtualServers: 0, + VirtualServerRoutes: 0, + TransportServers: 0, + MasterIngressCount: 1, + MinionIngressCount: 2, + Services: 2, + IngressAnnotations: []string{"nginx.org/mergeable-ingress-type"}, + } + + td := telemetry.Data{ + Data: telData, + NICResourceCounts: nicResourceCounts, + } + + want := fmt.Sprintf("%+v", &td) + got := buf.String() + if !cmp.Equal(want, got) { + t.Error(cmp.Diff(want, got)) + } +} + func TestCollectAppProtectVersion(t *testing.T) { t.Parallel() @@ -951,11 +1002,7 @@ func TestCollectInstallationFlags(t *testing.T) { } nicResourceCounts := telemetry.NICResourceCounts{ - VirtualServers: 0, - VirtualServerRoutes: 0, - TransportServers: 0, - Ingresses: 0, - InstallationFlags: tc.wantFlags, + InstallationFlags: tc.wantFlags, } td := telemetry.Data{ @@ -2342,6 +2389,18 @@ func newConfiguratorWithIngressWithCustomAnnotations(t *testing.T, annotations m return c } +func newConfiguratorWithMergeableIngress(t *testing.T) *configs.Configurator { + t.Helper() + + ingressEx := createMergeableCafeIngress() + c := newConfigurator(t) + _, err := c.AddOrUpdateMergeableIngress(ingressEx) + if err != nil { + t.Fatal(err) + } + return c +} + func newConfiguratorWithMergeableIngressCustomAnnotations(t *testing.T, masterAnnotations, coffeeAnnotations, teaAnnotations map[string]string) *configs.Configurator { t.Helper() diff --git a/internal/telemetry/data.avdl b/internal/telemetry/data.avdl index 36c46b4484..4b96dfe9de 100644 --- a/internal/telemetry/data.avdl +++ b/internal/telemetry/data.avdl @@ -51,8 +51,14 @@ It is the UID of the `kube-system` Namespace. */ /** Services is the number of services referenced by NGINX Ingress Controller in the cluster */ long? Services = null; - /** Ingresses is the number of Ingress resources managed by the NGINX Ingress Controller. */ - long? Ingresses = null; + /** RegularIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */ + long? RegularIngressCount = null; + + /** MasterIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */ + long? MasterIngressCount = null; + + /** MinionIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */ + long? MinionIngressCount = null; /** IngressClasses is the number of Ingress Classes. */ long? IngressClasses = null; diff --git a/internal/telemetry/exporter.go b/internal/telemetry/exporter.go index ccdf703664..16067c527a 100644 --- a/internal/telemetry/exporter.go +++ b/internal/telemetry/exporter.go @@ -77,8 +77,12 @@ type NICResourceCounts struct { Secrets int64 // Services is the number of services referenced by NGINX Ingress Controller in the cluster Services int64 - // Ingresses is the number of Ingress resources managed by the NGINX Ingress Controller. - Ingresses int64 + // RegularIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. + RegularIngressCount int64 + // MasterIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. + MasterIngressCount int64 + // MinionIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. + MinionIngressCount int64 // IngressClasses is the number of Ingress Classes. IngressClasses int64 // AccessControlPolicies is the number of AccessControl policies managed by NGINX Ingress Controller diff --git a/internal/telemetry/nicresourcecounts_attributes_generated.go b/internal/telemetry/nicresourcecounts_attributes_generated.go index 6d11eab24f..36361cf574 100644 --- a/internal/telemetry/nicresourcecounts_attributes_generated.go +++ b/internal/telemetry/nicresourcecounts_attributes_generated.go @@ -19,7 +19,9 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue { attrs = append(attrs, attribute.Int64("Replicas", d.Replicas)) attrs = append(attrs, attribute.Int64("Secrets", d.Secrets)) attrs = append(attrs, attribute.Int64("Services", d.Services)) - attrs = append(attrs, attribute.Int64("Ingresses", d.Ingresses)) + attrs = append(attrs, attribute.Int64("RegularIngressCount", d.RegularIngressCount)) + attrs = append(attrs, attribute.Int64("MasterIngressCount", d.MasterIngressCount)) + attrs = append(attrs, attribute.Int64("MinionIngressCount", d.MinionIngressCount)) attrs = append(attrs, attribute.Int64("IngressClasses", d.IngressClasses)) attrs = append(attrs, attribute.Int64("AccessControlPolicies", d.AccessControlPolicies)) attrs = append(attrs, attribute.Int64("RateLimitPolicies", d.RateLimitPolicies))