Skip to content

Commit b724879

Browse files
authored
Add Granular Ingress Counts to Telemetry (#5608)
1 parent 1870e14 commit b724879

File tree

7 files changed

+115
-28
lines changed

7 files changed

+115
-28
lines changed

docs/content/overview/product-telemetry.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ These are the data points collected and reported by NGINX Ingress Controller:
3535
- **Replicas** Number of Deployment replicas, or Daemonset instances.
3636
- **Secrets** Number of Secret resources managed by NGINX Ingress Controller.
3737
- **Services** Number of Services referenced by VirtualServers, VirtualServerRoutes, TransportServers and Ingresses.
38-
- **Ingresses** The number of Ingress resources managed by the NGINX Ingress Controller.
38+
- **RegularIngressCount** The number of Regular Ingress resources managed by NGINX Ingress Controller.
39+
- **MasterIngressCount** The number of Master Ingress resources managed by NGINX Ingress Controller.
40+
- **MinionIngressCount** The number of Minion Ingress resources managed by NGINX Ingress Controller.
3941
- **IngressClasses** Number of Ingress Classes in the cluster.
4042
- **IngressAnnotations** List of Ingress annotations managed by NGINX Ingress Controller
4143
- **AccessControlPolicies** Number of AccessControl policies.

internal/telemetry/cluster.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,22 @@ func (c *Collector) Secrets() (int, error) {
123123
return len(c.Config.SecretStore.GetSecretReferenceMap()), nil
124124
}
125125

126-
// IngressCount returns number of Ingresses in the namespaces watched by NIC.
127-
func (c *Collector) IngressCount() int {
128-
if c.Config.Configurator == nil {
129-
return 0
130-
}
131-
ic := c.Config.Configurator.GetIngressCounts()
132-
total := 0
133-
for _, v := range ic {
134-
total += v
135-
}
136-
return total
126+
// RegularIngressCount returns number of Minion Ingresses in the namespaces watched by NIC.
127+
func (c *Collector) RegularIngressCount() int {
128+
ingressCount := c.Config.Configurator.GetIngressCounts()
129+
return ingressCount["regular"]
130+
}
131+
132+
// MasterIngressCount returns number of Minion Ingresses in the namespaces watched by NIC.
133+
func (c *Collector) MasterIngressCount() int {
134+
ingressCount := c.Config.Configurator.GetIngressCounts()
135+
return ingressCount["master"]
136+
}
137+
138+
// MinionIngressCount returns number of Minion Ingresses in the namespaces watched by NIC.
139+
func (c *Collector) MinionIngressCount() int {
140+
ingressCount := c.Config.Configurator.GetIngressCounts()
141+
return ingressCount["minion"]
137142
}
138143

139144
// IngressAnnotations returns a list of all the unique annotations found in Ingresses.

internal/telemetry/collector.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ func (c *Collector) Collect(ctx context.Context) {
130130
Replicas: int64(report.NICReplicaCount),
131131
Secrets: int64(report.Secrets),
132132
Services: int64(report.ServiceCount),
133-
Ingresses: int64(report.IngressCount),
133+
RegularIngressCount: int64(report.RegularIngressCount),
134+
MasterIngressCount: int64(report.MasterIngressCount),
135+
MinionIngressCount: int64(report.MinionIngressCount),
134136
IngressClasses: int64(report.IngressClassCount),
135137
AccessControlPolicies: int64(report.AccessControlCount),
136138
RateLimitPolicies: int64(report.RateLimitCount),
@@ -173,7 +175,9 @@ type Report struct {
173175
ServiceCount int
174176
TransportServers int
175177
Secrets int
176-
IngressCount int
178+
RegularIngressCount int
179+
MasterIngressCount int
180+
MinionIngressCount int
177181
IngressClassCount int
178182
AccessControlCount int
179183
RateLimitCount int
@@ -237,7 +241,10 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
237241
if err != nil {
238242
glog.V(3).Infof("Unable to collect telemetry data: Secrets: %v", err)
239243
}
240-
ingressCount := c.IngressCount()
244+
245+
regularIngressCount := c.RegularIngressCount()
246+
masterIngressCount := c.MasterIngressCount()
247+
minionIngressCount := c.MinionIngressCount()
241248
ingressClassCount, err := c.IngressClassCount(ctx)
242249
if err != nil {
243250
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) {
277284
ServiceCount: serviceCount,
278285
TransportServers: tsCount,
279286
Secrets: secretCount,
280-
IngressCount: ingressCount,
287+
RegularIngressCount: regularIngressCount,
288+
MasterIngressCount: masterIngressCount,
289+
MinionIngressCount: minionIngressCount,
281290
IngressClassCount: ingressClassCount,
282291
AccessControlCount: accessControlCount,
283292
RateLimitCount: rateLimitCount,

internal/telemetry/collector_test.go

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func TestIngressCountReportsNoDeployedIngresses(t *testing.T) {
518518
VirtualServers: 0,
519519
VirtualServerRoutes: 0,
520520
TransportServers: 0,
521-
Ingresses: 0,
521+
RegularIngressCount: 0,
522522
}
523523

524524
td := telemetry.Data{
@@ -747,7 +747,7 @@ func TestIngressCountReportsNumberOfDeployedIngresses(t *testing.T) {
747747
VirtualServers: 0,
748748
VirtualServerRoutes: 0,
749749
TransportServers: 0,
750-
Ingresses: 1,
750+
RegularIngressCount: 1,
751751
Services: 2,
752752
}
753753

@@ -763,6 +763,57 @@ func TestIngressCountReportsNumberOfDeployedIngresses(t *testing.T) {
763763
}
764764
}
765765

766+
func TestMasterMinionIngressCountReportsNumberOfDeployedIngresses(t *testing.T) {
767+
t.Parallel()
768+
buf := &bytes.Buffer{}
769+
exp := &telemetry.StdoutExporter{Endpoint: buf}
770+
771+
configurator := newConfiguratorWithMergeableIngress(t)
772+
773+
cfg := telemetry.CollectorConfig{
774+
Configurator: configurator,
775+
K8sClientReader: newTestClientset(node1, kubeNS),
776+
Version: telemetryNICData.ProjectVersion,
777+
}
778+
779+
c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
780+
if err != nil {
781+
t.Fatal(err)
782+
}
783+
c.Collect(context.Background())
784+
785+
telData := tel.Data{
786+
ProjectName: telemetryNICData.ProjectName,
787+
ProjectVersion: telemetryNICData.ProjectVersion,
788+
ProjectArchitecture: telemetryNICData.ProjectArchitecture,
789+
ClusterNodeCount: 1,
790+
ClusterID: telemetryNICData.ClusterID,
791+
ClusterVersion: telemetryNICData.ClusterVersion,
792+
ClusterPlatform: "other",
793+
}
794+
795+
nicResourceCounts := telemetry.NICResourceCounts{
796+
VirtualServers: 0,
797+
VirtualServerRoutes: 0,
798+
TransportServers: 0,
799+
MasterIngressCount: 1,
800+
MinionIngressCount: 2,
801+
Services: 2,
802+
IngressAnnotations: []string{"nginx.org/mergeable-ingress-type"},
803+
}
804+
805+
td := telemetry.Data{
806+
Data: telData,
807+
NICResourceCounts: nicResourceCounts,
808+
}
809+
810+
want := fmt.Sprintf("%+v", &td)
811+
got := buf.String()
812+
if !cmp.Equal(want, got) {
813+
t.Error(cmp.Diff(want, got))
814+
}
815+
}
816+
766817
func TestCollectAppProtectVersion(t *testing.T) {
767818
t.Parallel()
768819

@@ -951,11 +1002,7 @@ func TestCollectInstallationFlags(t *testing.T) {
9511002
}
9521003

9531004
nicResourceCounts := telemetry.NICResourceCounts{
954-
VirtualServers: 0,
955-
VirtualServerRoutes: 0,
956-
TransportServers: 0,
957-
Ingresses: 0,
958-
InstallationFlags: tc.wantFlags,
1005+
InstallationFlags: tc.wantFlags,
9591006
}
9601007

9611008
td := telemetry.Data{
@@ -2342,6 +2389,18 @@ func newConfiguratorWithIngressWithCustomAnnotations(t *testing.T, annotations m
23422389
return c
23432390
}
23442391

2392+
func newConfiguratorWithMergeableIngress(t *testing.T) *configs.Configurator {
2393+
t.Helper()
2394+
2395+
ingressEx := createMergeableCafeIngress()
2396+
c := newConfigurator(t)
2397+
_, err := c.AddOrUpdateMergeableIngress(ingressEx)
2398+
if err != nil {
2399+
t.Fatal(err)
2400+
}
2401+
return c
2402+
}
2403+
23452404
func newConfiguratorWithMergeableIngressCustomAnnotations(t *testing.T, masterAnnotations, coffeeAnnotations, teaAnnotations map[string]string) *configs.Configurator {
23462405
t.Helper()
23472406

internal/telemetry/data.avdl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ It is the UID of the `kube-system` Namespace. */
5151
/** Services is the number of services referenced by NGINX Ingress Controller in the cluster */
5252
long? Services = null;
5353

54-
/** Ingresses is the number of Ingress resources managed by the NGINX Ingress Controller. */
55-
long? Ingresses = null;
54+
/** RegularIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */
55+
long? RegularIngressCount = null;
56+
57+
/** MasterIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */
58+
long? MasterIngressCount = null;
59+
60+
/** MinionIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */
61+
long? MinionIngressCount = null;
5662

5763
/** IngressClasses is the number of Ingress Classes. */
5864
long? IngressClasses = null;

internal/telemetry/exporter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ type NICResourceCounts struct {
7777
Secrets int64
7878
// Services is the number of services referenced by NGINX Ingress Controller in the cluster
7979
Services int64
80-
// Ingresses is the number of Ingress resources managed by the NGINX Ingress Controller.
81-
Ingresses int64
80+
// RegularIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller.
81+
RegularIngressCount int64
82+
// MasterIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller.
83+
MasterIngressCount int64
84+
// MinionIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller.
85+
MinionIngressCount int64
8286
// IngressClasses is the number of Ingress Classes.
8387
IngressClasses int64
8488
// AccessControlPolicies is the number of AccessControl policies managed by NGINX Ingress Controller

internal/telemetry/nicresourcecounts_attributes_generated.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
1919
attrs = append(attrs, attribute.Int64("Replicas", d.Replicas))
2020
attrs = append(attrs, attribute.Int64("Secrets", d.Secrets))
2121
attrs = append(attrs, attribute.Int64("Services", d.Services))
22-
attrs = append(attrs, attribute.Int64("Ingresses", d.Ingresses))
22+
attrs = append(attrs, attribute.Int64("RegularIngressCount", d.RegularIngressCount))
23+
attrs = append(attrs, attribute.Int64("MasterIngressCount", d.MasterIngressCount))
24+
attrs = append(attrs, attribute.Int64("MinionIngressCount", d.MinionIngressCount))
2325
attrs = append(attrs, attribute.Int64("IngressClasses", d.IngressClasses))
2426
attrs = append(attrs, attribute.Int64("AccessControlPolicies", d.AccessControlPolicies))
2527
attrs = append(attrs, attribute.Int64("RateLimitPolicies", d.RateLimitPolicies))

0 commit comments

Comments
 (0)