Skip to content

Commit 962d4ae

Browse files
add cache policy to telemetry (#8267)
1 parent 034a065 commit 962d4ae

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

internal/telemetry/cluster.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ func (c *Collector) PolicyCount() map[string]int {
267267
policyCounters["WAF"]++
268268
case spec.APIKey != nil:
269269
policyCounters["APIKey"]++
270+
case spec.Cache != nil:
271+
policyCounters["Cache"]++
270272
}
271273
}
272274
return policyCounters

internal/telemetry/collector.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (c *Collector) Collect(ctx context.Context) {
165165
EgressMTLSPolicies: int64(report.EgressMTLSCount),
166166
OIDCPolicies: int64(report.OIDCCount),
167167
WAFPolicies: int64(report.WAFCount),
168+
CachePolicies: int64(report.CacheCount),
168169
GlobalConfiguration: report.GlobalConfiguration,
169170
IngressAnnotations: report.IngressAnnotations,
170171
AppProtectVersion: report.AppProtectVersion,
@@ -219,6 +220,7 @@ type Report struct {
219220
EgressMTLSCount int
220221
OIDCCount int
221222
WAFCount int
223+
CacheCount int
222224
GlobalConfiguration bool
223225
IngressAnnotations []string
224226
AppProtectVersion string
@@ -297,6 +299,7 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
297299
egressMTLSCount int
298300
oidcCount int
299301
wafCount int
302+
cacheCount int
300303
)
301304
// Collect Custom Resources (Policies) only if CR enabled at startup.
302305
if c.Config.CustomResourcesEnabled {
@@ -312,6 +315,7 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
312315
egressMTLSCount = policies["EgressMTLS"]
313316
oidcCount = policies["OIDC"]
314317
wafCount = policies["WAF"]
318+
cacheCount = policies["Cache"]
315319
}
316320

317321
ingressAnnotations := c.IngressAnnotations()
@@ -374,6 +378,7 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
374378
EgressMTLSCount: egressMTLSCount,
375379
OIDCCount: oidcCount,
376380
WAFCount: wafCount,
381+
CacheCount: cacheCount,
377382
GlobalConfiguration: c.Config.GlobalConfiguration,
378383
IngressAnnotations: ingressAnnotations,
379384
AppProtectVersion: appProtectVersion,

internal/telemetry/collector_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ func TestCollectPolicyCountOnCustomResourcesEnabled(t *testing.T) {
268268
},
269269
want: 1,
270270
},
271+
{
272+
name: "CachePolicy",
273+
policies: func() []*conf_v1.Policy {
274+
return []*conf_v1.Policy{cachePolicy}
275+
},
276+
want: 1,
277+
},
271278
{
272279
name: "MultiplePolicies",
273280
policies: func() []*conf_v1.Policy {
@@ -419,6 +426,7 @@ func TestCollectPoliciesReportOnEnabledCustomResources(t *testing.T) {
419426
wafPolicy,
420427
wafPolicy,
421428
oidcPolicy,
429+
cachePolicy,
422430
}
423431
},
424432
CustomResourcesEnabled: true,
@@ -445,6 +453,7 @@ func TestCollectPoliciesReportOnEnabledCustomResources(t *testing.T) {
445453
WAFPolicies: 2,
446454
OIDCPolicies: 1,
447455
EgressMTLSPolicies: 2,
456+
CachePolicies: 1,
448457
}
449458

450459
td := telemetry.Data{
@@ -530,6 +539,7 @@ func TestCollectPoliciesReportOnDisabledCustomResources(t *testing.T) {
530539
wafPolicy,
531540
wafPolicy,
532541
oidcPolicy,
542+
cachePolicy,
533543
}
534544
},
535545
CustomResourcesEnabled: false,
@@ -556,6 +566,7 @@ func TestCollectPoliciesReportOnDisabledCustomResources(t *testing.T) {
556566
WAFPolicies: 0,
557567
OIDCPolicies: 0,
558568
EgressMTLSPolicies: 0,
569+
CachePolicies: 0,
559570
}
560571

561572
td := telemetry.Data{
@@ -2834,4 +2845,19 @@ var (
28342845
},
28352846
Status: conf_v1.PolicyStatus{},
28362847
}
2848+
2849+
cachePolicy = &conf_v1.Policy{
2850+
TypeMeta: metaV1.TypeMeta{
2851+
Kind: "Policy",
2852+
APIVersion: "k8s.nginx.org/v1",
2853+
},
2854+
ObjectMeta: metaV1.ObjectMeta{
2855+
Name: "cache-policy",
2856+
Namespace: "default",
2857+
},
2858+
Spec: conf_v1.PolicySpec{
2859+
Cache: &conf_v1.Cache{},
2860+
},
2861+
Status: conf_v1.PolicyStatus{},
2862+
}
28372863
)

internal/telemetry/data.avdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,8 @@ It is the UID of the `kube-system` Namespace. */
130130
/** VariablesRateLimitPolicies is the number of Variables Condition RateLimit policies managed by NGINX Ingress Controller */
131131
long? VariablesRateLimitPolicies = null;
132132

133+
/** CachePolicies is the number of Cache policies managed by NGINX Ingress Controller */
134+
long? CachePolicies = null;
135+
133136
}
134137
}

internal/telemetry/exporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ type NICResourceCounts struct {
144144
JWTRateLimitPolicies int64
145145
// VariablesRateLimitPolicies is the number of Variables Condition RateLimit policies managed by NGINX Ingress Controller
146146
VariablesRateLimitPolicies int64
147+
// CachePolicies is the number of Cache policies managed by NGINX Ingress Controller
148+
CachePolicies int64
147149
}

internal/telemetry/nicresourcecounts_attributes_generated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
4444
attrs = append(attrs, attribute.StringSlice("MGMTConfigMapKeys", d.MGMTConfigMapKeys))
4545
attrs = append(attrs, attribute.Int64("JWTRateLimitPolicies", d.JWTRateLimitPolicies))
4646
attrs = append(attrs, attribute.Int64("VariablesRateLimitPolicies", d.VariablesRateLimitPolicies))
47+
attrs = append(attrs, attribute.Int64("CachePolicies", d.CachePolicies))
4748

4849
return attrs
4950
}

0 commit comments

Comments
 (0)