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
2 changes: 2 additions & 0 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -219,6 +220,7 @@ type Report struct {
EgressMTLSCount int
OIDCCount int
WAFCount int
CacheCount int
GlobalConfiguration bool
IngressAnnotations []string
AppProtectVersion string
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -419,6 +426,7 @@ func TestCollectPoliciesReportOnEnabledCustomResources(t *testing.T) {
wafPolicy,
wafPolicy,
oidcPolicy,
cachePolicy,
}
},
CustomResourcesEnabled: true,
Expand All @@ -445,6 +453,7 @@ func TestCollectPoliciesReportOnEnabledCustomResources(t *testing.T) {
WAFPolicies: 2,
OIDCPolicies: 1,
EgressMTLSPolicies: 2,
CachePolicies: 1,
}

td := telemetry.Data{
Expand Down Expand Up @@ -530,6 +539,7 @@ func TestCollectPoliciesReportOnDisabledCustomResources(t *testing.T) {
wafPolicy,
wafPolicy,
oidcPolicy,
cachePolicy,
}
},
CustomResourcesEnabled: false,
Expand All @@ -556,6 +566,7 @@ func TestCollectPoliciesReportOnDisabledCustomResources(t *testing.T) {
WAFPolicies: 0,
OIDCPolicies: 0,
EgressMTLSPolicies: 0,
CachePolicies: 0,
}

td := telemetry.Data{
Expand Down Expand Up @@ -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{},
}
)
3 changes: 3 additions & 0 deletions internal/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}
2 changes: 2 additions & 0 deletions internal/telemetry/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading