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/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{}, + } ) diff --git a/internal/telemetry/data.avdl b/internal/telemetry/data.avdl index 4b43aacef8..d809b13746 100644 --- a/internal/telemetry/data.avdl +++ b/internal/telemetry/data.avdl @@ -130,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 a59f466ed0..5dd210a507 100644 --- a/internal/telemetry/exporter.go +++ b/internal/telemetry/exporter.go @@ -144,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 c16d339659..5a36ead335 100644 --- a/internal/telemetry/nicresourcecounts_attributes_generated.go +++ b/internal/telemetry/nicresourcecounts_attributes_generated.go @@ -44,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 }