Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Granular Ingress Counts to Telemetry #5608

Merged
merged 23 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
203ff59
Add Installation Flags to Telemetry - all comparison tests break need…
AlexFenlon May 17, 2024
a3b4966
Add tests for installation flags - dont work at the moment
AlexFenlon May 20, 2024
a455218
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 20, 2024
7cc10b9
Add catch for tests
AlexFenlon May 20, 2024
50b9014
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 20, 2024
3104ab4
Remove non working test
AlexFenlon May 20, 2024
ae501e1
Merge branch 'main' into feat/telemetry-flags
AlexFenlon May 20, 2024
8acff3b
Add tests and use lbc instead of os.args
AlexFenlon May 20, 2024
147e35e
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 21, 2024
8f3dc7f
Add tests, refactor and get os.Args at main
AlexFenlon May 21, 2024
ad3dad7
Merge branch 'main' into feat/telemetry-flags
jjngx May 21, 2024
3d3851c
Merge branch 'main' into feat/telemetry-flags
jjngx May 21, 2024
7d205e7
Merge branch 'main' into feat/telemetry-flags
jjngx May 21, 2024
12069aa
Fix Doc change from PR and associated changes
AlexFenlon May 22, 2024
7f4501d
Update docs/content/overview/product-telemetry.md
AlexFenlon May 22, 2024
26bde6c
Add Granular Ingress Counts to Telemetry
AlexFenlon May 22, 2024
a2ae400
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 22, 2024
df0c079
Fix doc and comment.
AlexFenlon May 23, 2024
2416458
Fix data.avdl
AlexFenlon May 23, 2024
bbfc1db
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 23, 2024
c163cf5
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 23, 2024
e49e8ba
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 27, 2024
c8bbe0f
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 28, 2024
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
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
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
Loading