Skip to content

Commit

Permalink
Add Granular Ingress Counts to Telemetry (nginxinc#5608)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexFenlon authored and ssrahul96 committed Jun 20, 2024
1 parent fc79984 commit aa82e83
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 28 deletions.
4 changes: 3 additions & 1 deletion docs/content/overview/product-telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ These are the data points collected and reported by NGINX Ingress Controller:
- **Replicas** Number of Deployment replicas, or Daemonset instances.
- **Secrets** Number of Secret resources managed by NGINX Ingress Controller.
- **Services** Number of Services referenced by VirtualServers, VirtualServerRoutes, TransportServers and Ingresses.
- **Ingresses** The number of Ingress resources managed by the NGINX Ingress Controller.
- **RegularIngressCount** The number of Regular Ingress resources managed by NGINX Ingress Controller.
- **MasterIngressCount** The number of Master Ingress resources managed by NGINX Ingress Controller.
- **MinionIngressCount** The number of Minion Ingress resources managed by NGINX Ingress Controller.
- **IngressClasses** Number of Ingress Classes in the cluster.
- **IngressAnnotations** List of Ingress annotations managed by NGINX Ingress Controller
- **AccessControlPolicies** Number of AccessControl policies.
Expand Down
27 changes: 16 additions & 11 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,22 @@ func (c *Collector) Secrets() (int, error) {
return len(c.Config.SecretStore.GetSecretReferenceMap()), nil
}

// IngressCount returns number of Ingresses in the namespaces watched by NIC.
func (c *Collector) IngressCount() int {
if c.Config.Configurator == nil {
return 0
}
ic := c.Config.Configurator.GetIngressCounts()
total := 0
for _, v := range ic {
total += v
}
return total
// RegularIngressCount returns number of Minion Ingresses in the namespaces watched by NIC.
func (c *Collector) RegularIngressCount() int {
ingressCount := c.Config.Configurator.GetIngressCounts()
return ingressCount["regular"]
}

// MasterIngressCount returns number of Minion Ingresses in the namespaces watched by NIC.
func (c *Collector) MasterIngressCount() int {
ingressCount := c.Config.Configurator.GetIngressCounts()
return ingressCount["master"]
}

// MinionIngressCount returns number of Minion Ingresses in the namespaces watched by NIC.
func (c *Collector) MinionIngressCount() int {
ingressCount := c.Config.Configurator.GetIngressCounts()
return ingressCount["minion"]
}

// IngressAnnotations returns a list of all the unique annotations found in Ingresses.
Expand Down
17 changes: 13 additions & 4 deletions internal/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func (c *Collector) Collect(ctx context.Context) {
Replicas: int64(report.NICReplicaCount),
Secrets: int64(report.Secrets),
Services: int64(report.ServiceCount),
Ingresses: int64(report.IngressCount),
RegularIngressCount: int64(report.RegularIngressCount),
MasterIngressCount: int64(report.MasterIngressCount),
MinionIngressCount: int64(report.MinionIngressCount),
IngressClasses: int64(report.IngressClassCount),
AccessControlPolicies: int64(report.AccessControlCount),
RateLimitPolicies: int64(report.RateLimitCount),
Expand Down Expand Up @@ -173,7 +175,9 @@ type Report struct {
ServiceCount int
TransportServers int
Secrets int
IngressCount int
RegularIngressCount int
MasterIngressCount int
MinionIngressCount int
IngressClassCount int
AccessControlCount int
RateLimitCount int
Expand Down Expand Up @@ -237,7 +241,10 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
if err != nil {
glog.V(3).Infof("Unable to collect telemetry data: Secrets: %v", err)
}
ingressCount := c.IngressCount()

regularIngressCount := c.RegularIngressCount()
masterIngressCount := c.MasterIngressCount()
minionIngressCount := c.MinionIngressCount()
ingressClassCount, err := c.IngressClassCount(ctx)
if err != nil {
glog.V(3).Infof("Unable to collect telemetry data: Ingress Classes: %v", err)
Expand Down Expand Up @@ -277,7 +284,9 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
ServiceCount: serviceCount,
TransportServers: tsCount,
Secrets: secretCount,
IngressCount: ingressCount,
RegularIngressCount: regularIngressCount,
MasterIngressCount: masterIngressCount,
MinionIngressCount: minionIngressCount,
IngressClassCount: ingressClassCount,
AccessControlCount: accessControlCount,
RateLimitCount: rateLimitCount,
Expand Down
73 changes: 66 additions & 7 deletions internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func TestIngressCountReportsNoDeployedIngresses(t *testing.T) {
VirtualServers: 0,
VirtualServerRoutes: 0,
TransportServers: 0,
Ingresses: 0,
RegularIngressCount: 0,
}

td := telemetry.Data{
Expand Down Expand Up @@ -747,7 +747,7 @@ func TestIngressCountReportsNumberOfDeployedIngresses(t *testing.T) {
VirtualServers: 0,
VirtualServerRoutes: 0,
TransportServers: 0,
Ingresses: 1,
RegularIngressCount: 1,
Services: 2,
}

Expand All @@ -763,6 +763,57 @@ func TestIngressCountReportsNumberOfDeployedIngresses(t *testing.T) {
}
}

func TestMasterMinionIngressCountReportsNumberOfDeployedIngresses(t *testing.T) {
t.Parallel()
buf := &bytes.Buffer{}
exp := &telemetry.StdoutExporter{Endpoint: buf}

configurator := newConfiguratorWithMergeableIngress(t)

cfg := telemetry.CollectorConfig{
Configurator: configurator,
K8sClientReader: newTestClientset(node1, kubeNS),
Version: telemetryNICData.ProjectVersion,
}

c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
if err != nil {
t.Fatal(err)
}
c.Collect(context.Background())

telData := tel.Data{
ProjectName: telemetryNICData.ProjectName,
ProjectVersion: telemetryNICData.ProjectVersion,
ProjectArchitecture: telemetryNICData.ProjectArchitecture,
ClusterNodeCount: 1,
ClusterID: telemetryNICData.ClusterID,
ClusterVersion: telemetryNICData.ClusterVersion,
ClusterPlatform: "other",
}

nicResourceCounts := telemetry.NICResourceCounts{
VirtualServers: 0,
VirtualServerRoutes: 0,
TransportServers: 0,
MasterIngressCount: 1,
MinionIngressCount: 2,
Services: 2,
IngressAnnotations: []string{"nginx.org/mergeable-ingress-type"},
}

td := telemetry.Data{
Data: telData,
NICResourceCounts: nicResourceCounts,
}

want := fmt.Sprintf("%+v", &td)
got := buf.String()
if !cmp.Equal(want, got) {
t.Error(cmp.Diff(want, got))
}
}

func TestCollectAppProtectVersion(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -951,11 +1002,7 @@ func TestCollectInstallationFlags(t *testing.T) {
}

nicResourceCounts := telemetry.NICResourceCounts{
VirtualServers: 0,
VirtualServerRoutes: 0,
TransportServers: 0,
Ingresses: 0,
InstallationFlags: tc.wantFlags,
InstallationFlags: tc.wantFlags,
}

td := telemetry.Data{
Expand Down Expand Up @@ -2342,6 +2389,18 @@ func newConfiguratorWithIngressWithCustomAnnotations(t *testing.T, annotations m
return c
}

func newConfiguratorWithMergeableIngress(t *testing.T) *configs.Configurator {
t.Helper()

ingressEx := createMergeableCafeIngress()
c := newConfigurator(t)
_, err := c.AddOrUpdateMergeableIngress(ingressEx)
if err != nil {
t.Fatal(err)
}
return c
}

func newConfiguratorWithMergeableIngressCustomAnnotations(t *testing.T, masterAnnotations, coffeeAnnotations, teaAnnotations map[string]string) *configs.Configurator {
t.Helper()

Expand Down
10 changes: 8 additions & 2 deletions internal/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ It is the UID of the `kube-system` Namespace. */
/** Services is the number of services referenced by NGINX Ingress Controller in the cluster */
long? Services = null;

/** Ingresses is the number of Ingress resources managed by the NGINX Ingress Controller. */
long? Ingresses = null;
/** RegularIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */
long? RegularIngressCount = null;

/** MasterIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */
long? MasterIngressCount = null;

/** MinionIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller. */
long? MinionIngressCount = null;

/** IngressClasses is the number of Ingress Classes. */
long? IngressClasses = null;
Expand Down
8 changes: 6 additions & 2 deletions internal/telemetry/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ type NICResourceCounts struct {
Secrets int64
// Services is the number of services referenced by NGINX Ingress Controller in the cluster
Services int64
// Ingresses is the number of Ingress resources managed by the NGINX Ingress Controller.
Ingresses int64
// RegularIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller.
RegularIngressCount int64
// MasterIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller.
MasterIngressCount int64
// MinionIngressCount is the number of Regular Ingress resources managed by NGINX Ingress Controller.
MinionIngressCount int64
// IngressClasses is the number of Ingress Classes.
IngressClasses int64
// AccessControlPolicies is the number of AccessControl policies managed by NGINX Ingress Controller
Expand Down
4 changes: 3 additions & 1 deletion internal/telemetry/nicresourcecounts_attributes_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.Int64("Replicas", d.Replicas))
attrs = append(attrs, attribute.Int64("Secrets", d.Secrets))
attrs = append(attrs, attribute.Int64("Services", d.Services))
attrs = append(attrs, attribute.Int64("Ingresses", d.Ingresses))
attrs = append(attrs, attribute.Int64("RegularIngressCount", d.RegularIngressCount))
attrs = append(attrs, attribute.Int64("MasterIngressCount", d.MasterIngressCount))
attrs = append(attrs, attribute.Int64("MinionIngressCount", d.MinionIngressCount))
attrs = append(attrs, attribute.Int64("IngressClasses", d.IngressClasses))
attrs = append(attrs, attribute.Int64("AccessControlPolicies", d.AccessControlPolicies))
attrs = append(attrs, attribute.Int64("RateLimitPolicies", d.RateLimitPolicies))
Expand Down

0 comments on commit aa82e83

Please sign in to comment.