From b832039a4b9a2cc0f0fd07acd2935e8d55037391 Mon Sep 17 00:00:00 2001 From: Venktesh Date: Fri, 12 Sep 2025 14:26:55 +0100 Subject: [PATCH 1/4] add cache policy to telemetry --- internal/telemetry/cluster.go | 2 ++ internal/telemetry/collector.go | 5 +++++ internal/telemetry/data.avdl | 5 ++++- internal/telemetry/exporter.go | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/telemetry/cluster.go b/internal/telemetry/cluster.go index f92a66876d..fe2ee8bb99 100644 --- a/internal/telemetry/cluster.go +++ b/internal/telemetry/cluster.go @@ -267,6 +267,8 @@ func (c *Collector) PolicyCount() map[string]int { policyCounters["WAF"]++ case spec.APIKey != nil: policyCounters["APIKey"]++ + case spec.Cache != nil: + policyCounters["Cache"]++ } } return policyCounters diff --git a/internal/telemetry/collector.go b/internal/telemetry/collector.go index 1553b661c5..52260d8917 100644 --- a/internal/telemetry/collector.go +++ b/internal/telemetry/collector.go @@ -165,6 +165,7 @@ func (c *Collector) Collect(ctx context.Context) { EgressMTLSPolicies: int64(report.EgressMTLSCount), OIDCPolicies: int64(report.OIDCCount), WAFPolicies: int64(report.WAFCount), + CachePolicies: int64(report.CacheCount), GlobalConfiguration: report.GlobalConfiguration, IngressAnnotations: report.IngressAnnotations, AppProtectVersion: report.AppProtectVersion, @@ -219,6 +220,7 @@ type Report struct { EgressMTLSCount int OIDCCount int WAFCount int + CacheCount int GlobalConfiguration bool IngressAnnotations []string AppProtectVersion string @@ -297,6 +299,7 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) { egressMTLSCount int oidcCount int wafCount int + cacheCount int ) // Collect Custom Resources (Policies) only if CR enabled at startup. if c.Config.CustomResourcesEnabled { @@ -312,6 +315,7 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) { egressMTLSCount = policies["EgressMTLS"] oidcCount = policies["OIDC"] wafCount = policies["WAF"] + cacheCount = policies["Cache"] } ingressAnnotations := c.IngressAnnotations() @@ -374,6 +378,7 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) { EgressMTLSCount: egressMTLSCount, OIDCCount: oidcCount, WAFCount: wafCount, + CacheCount: cacheCount, GlobalConfiguration: c.Config.GlobalConfiguration, IngressAnnotations: ingressAnnotations, AppProtectVersion: appProtectVersion, diff --git a/internal/telemetry/data.avdl b/internal/telemetry/data.avdl index 4b43aacef8..141ea91fd2 100644 --- a/internal/telemetry/data.avdl +++ b/internal/telemetry/data.avdl @@ -99,7 +99,10 @@ It is the UID of the `kube-system` Namespace. */ /** WAFPolicies is the number of WAF policies managed by NGINX Ingress Controller */ long? WAFPolicies = null; - + + /** CachePolicies is the number of Cache policies managed by NGINX Ingress Controller */ + long? CachePolicies = null; + /** GlobalConfiguration indicates if a GlobalConfiguration resource is used. */ boolean? GlobalConfiguration = null; diff --git a/internal/telemetry/exporter.go b/internal/telemetry/exporter.go index a59f466ed0..a6ee4929ba 100644 --- a/internal/telemetry/exporter.go +++ b/internal/telemetry/exporter.go @@ -124,6 +124,8 @@ type NICResourceCounts struct { OIDCPolicies int64 // WAFPolicies is the number of WAF policies managed by NGINX Ingress Controller WAFPolicies int64 + // CachePolicies is the number of Cache policies managed by NGINX Ingress Controller + CachePolicies int64 // GlobalConfiguration indicates if a GlobalConfiguration resource is used. GlobalConfiguration bool // IngressAnnotations is the list of annotations resources managed by NGINX Ingress Controller From 82651b8dd8a7fa11d9f50e47b4dadee6e4a2eeba Mon Sep 17 00:00:00 2001 From: Venktesh Date: Fri, 12 Sep 2025 14:34:31 +0100 Subject: [PATCH 2/4] update schema --- internal/telemetry/data.avdl | 4 ++-- internal/telemetry/nicresourcecounts_attributes_generated.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/telemetry/data.avdl b/internal/telemetry/data.avdl index 141ea91fd2..325d9b0a5f 100644 --- a/internal/telemetry/data.avdl +++ b/internal/telemetry/data.avdl @@ -99,10 +99,10 @@ It is the UID of the `kube-system` Namespace. */ /** WAFPolicies is the number of WAF policies managed by NGINX Ingress Controller */ long? WAFPolicies = null; - + /** CachePolicies is the number of Cache policies managed by NGINX Ingress Controller */ long? CachePolicies = null; - + /** GlobalConfiguration indicates if a GlobalConfiguration resource is used. */ boolean? GlobalConfiguration = null; diff --git a/internal/telemetry/nicresourcecounts_attributes_generated.go b/internal/telemetry/nicresourcecounts_attributes_generated.go index c16d339659..a77c290855 100644 --- a/internal/telemetry/nicresourcecounts_attributes_generated.go +++ b/internal/telemetry/nicresourcecounts_attributes_generated.go @@ -34,6 +34,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue { attrs = append(attrs, attribute.Int64("EgressMTLSPolicies", d.EgressMTLSPolicies)) attrs = append(attrs, attribute.Int64("OIDCPolicies", d.OIDCPolicies)) attrs = append(attrs, attribute.Int64("WAFPolicies", d.WAFPolicies)) + attrs = append(attrs, attribute.Int64("CachePolicies", d.CachePolicies)) attrs = append(attrs, attribute.Bool("GlobalConfiguration", d.GlobalConfiguration)) attrs = append(attrs, attribute.StringSlice("IngressAnnotations", d.IngressAnnotations)) attrs = append(attrs, attribute.String("AppProtectVersion", d.AppProtectVersion)) From aaa71630538fd1766cebddbb2c95db326e19d3a1 Mon Sep 17 00:00:00 2001 From: Venktesh Date: Fri, 12 Sep 2025 14:49:09 +0100 Subject: [PATCH 3/4] add unit test --- internal/telemetry/collector_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/telemetry/collector_test.go b/internal/telemetry/collector_test.go index 89d2675789..389b08e835 100644 --- a/internal/telemetry/collector_test.go +++ b/internal/telemetry/collector_test.go @@ -268,6 +268,13 @@ func TestCollectPolicyCountOnCustomResourcesEnabled(t *testing.T) { }, want: 1, }, + { + name: "CachePolicy", + policies: func() []*conf_v1.Policy { + return []*conf_v1.Policy{cachePolicy} + }, + want: 1, + }, { name: "MultiplePolicies", policies: func() []*conf_v1.Policy { @@ -419,6 +426,7 @@ func TestCollectPoliciesReportOnEnabledCustomResources(t *testing.T) { wafPolicy, wafPolicy, oidcPolicy, + cachePolicy, } }, CustomResourcesEnabled: true, @@ -445,6 +453,7 @@ func TestCollectPoliciesReportOnEnabledCustomResources(t *testing.T) { WAFPolicies: 2, OIDCPolicies: 1, EgressMTLSPolicies: 2, + CachePolicies: 1, } td := telemetry.Data{ @@ -530,6 +539,7 @@ func TestCollectPoliciesReportOnDisabledCustomResources(t *testing.T) { wafPolicy, wafPolicy, oidcPolicy, + cachePolicy, } }, CustomResourcesEnabled: false, @@ -556,6 +566,7 @@ func TestCollectPoliciesReportOnDisabledCustomResources(t *testing.T) { WAFPolicies: 0, OIDCPolicies: 0, EgressMTLSPolicies: 0, + CachePolicies: 0, } td := telemetry.Data{ @@ -2834,4 +2845,19 @@ var ( }, Status: conf_v1.PolicyStatus{}, } + + cachePolicy = &conf_v1.Policy{ + TypeMeta: metaV1.TypeMeta{ + Kind: "Policy", + APIVersion: "k8s.nginx.org/v1", + }, + ObjectMeta: metaV1.ObjectMeta{ + Name: "cache-policy", + Namespace: "default", + }, + Spec: conf_v1.PolicySpec{ + Cache: &conf_v1.Cache{}, + }, + Status: conf_v1.PolicyStatus{}, + } ) From 0c03b3a288615f013ea8a4112b9ad6b933512872 Mon Sep 17 00:00:00 2001 From: Venktesh Date: Fri, 12 Sep 2025 15:03:25 +0100 Subject: [PATCH 4/4] fix ordering --- internal/telemetry/data.avdl | 6 +++--- internal/telemetry/exporter.go | 4 ++-- .../telemetry/nicresourcecounts_attributes_generated.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/telemetry/data.avdl b/internal/telemetry/data.avdl index 325d9b0a5f..d809b13746 100644 --- a/internal/telemetry/data.avdl +++ b/internal/telemetry/data.avdl @@ -100,9 +100,6 @@ It is the UID of the `kube-system` Namespace. */ /** WAFPolicies is the number of WAF policies managed by NGINX Ingress Controller */ long? WAFPolicies = null; - /** CachePolicies is the number of Cache policies managed by NGINX Ingress Controller */ - long? CachePolicies = null; - /** GlobalConfiguration indicates if a GlobalConfiguration resource is used. */ boolean? GlobalConfiguration = null; @@ -133,5 +130,8 @@ It is the UID of the `kube-system` Namespace. */ /** VariablesRateLimitPolicies is the number of Variables Condition RateLimit policies managed by NGINX Ingress Controller */ long? VariablesRateLimitPolicies = null; + /** CachePolicies is the number of Cache policies managed by NGINX Ingress Controller */ + long? CachePolicies = null; + } } diff --git a/internal/telemetry/exporter.go b/internal/telemetry/exporter.go index a6ee4929ba..5dd210a507 100644 --- a/internal/telemetry/exporter.go +++ b/internal/telemetry/exporter.go @@ -124,8 +124,6 @@ type NICResourceCounts struct { OIDCPolicies int64 // WAFPolicies is the number of WAF policies managed by NGINX Ingress Controller WAFPolicies int64 - // CachePolicies is the number of Cache policies managed by NGINX Ingress Controller - CachePolicies int64 // GlobalConfiguration indicates if a GlobalConfiguration resource is used. GlobalConfiguration bool // IngressAnnotations is the list of annotations resources managed by NGINX Ingress Controller @@ -146,4 +144,6 @@ type NICResourceCounts struct { JWTRateLimitPolicies int64 // VariablesRateLimitPolicies is the number of Variables Condition RateLimit policies managed by NGINX Ingress Controller VariablesRateLimitPolicies int64 + // CachePolicies is the number of Cache policies managed by NGINX Ingress Controller + CachePolicies int64 } diff --git a/internal/telemetry/nicresourcecounts_attributes_generated.go b/internal/telemetry/nicresourcecounts_attributes_generated.go index a77c290855..5a36ead335 100644 --- a/internal/telemetry/nicresourcecounts_attributes_generated.go +++ b/internal/telemetry/nicresourcecounts_attributes_generated.go @@ -34,7 +34,6 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue { attrs = append(attrs, attribute.Int64("EgressMTLSPolicies", d.EgressMTLSPolicies)) attrs = append(attrs, attribute.Int64("OIDCPolicies", d.OIDCPolicies)) attrs = append(attrs, attribute.Int64("WAFPolicies", d.WAFPolicies)) - attrs = append(attrs, attribute.Int64("CachePolicies", d.CachePolicies)) attrs = append(attrs, attribute.Bool("GlobalConfiguration", d.GlobalConfiguration)) attrs = append(attrs, attribute.StringSlice("IngressAnnotations", d.IngressAnnotations)) attrs = append(attrs, attribute.String("AppProtectVersion", d.AppProtectVersion)) @@ -45,6 +44,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue { attrs = append(attrs, attribute.StringSlice("MGMTConfigMapKeys", d.MGMTConfigMapKeys)) attrs = append(attrs, attribute.Int64("JWTRateLimitPolicies", d.JWTRateLimitPolicies)) attrs = append(attrs, attribute.Int64("VariablesRateLimitPolicies", d.VariablesRateLimitPolicies)) + attrs = append(attrs, attribute.Int64("CachePolicies", d.CachePolicies)) return attrs }