From 9b4e6a42ff55e1b7be92c94cd215caa22bb7e91f Mon Sep 17 00:00:00 2001 From: Saloni Date: Thu, 9 May 2024 17:29:53 -0600 Subject: [PATCH 1/7] collect backendTLSPolicy and GRPCRoute Count --- internal/mode/static/telemetry/collector.go | 26 ++++++++++++-- .../mode/static/telemetry/collector_test.go | 34 ++++++++++++------- internal/mode/static/telemetry/data.avdl | 6 ++++ internal/mode/static/telemetry/data_test.go | 19 +++++++---- .../ngfresourcecounts_attributes_generated.go | 2 ++ site/content/overview/product-telemetry.md | 2 +- 6 files changed, 66 insertions(+), 23 deletions(-) diff --git a/internal/mode/static/telemetry/collector.go b/internal/mode/static/telemetry/collector.go index 477eaef731..de206c2126 100644 --- a/internal/mode/static/telemetry/collector.go +++ b/internal/mode/static/telemetry/collector.go @@ -67,6 +67,10 @@ type NGFResourceCounts struct { ServiceCount int64 // EndpointCount include the total count of Endpoints(IP:port) across all referenced services. EndpointCount int64 + // GRPCRouteCount is the number of relevant GRPCRoutes. + GRPCRouteCount int64 + // BackendTLSPolicyCount is the number of relevant BackendTLSPolicies. + BackendTLSPolicyCount int64 } // DataCollectorConfig holds configuration parameters for DataCollectorImpl. @@ -174,7 +178,7 @@ func collectGraphResourceCount( ngfResourceCounts.GatewayCount++ } - ngfResourceCounts.HTTPRouteCount = computeRouteCount(g.Routes) + ngfResourceCounts.HTTPRouteCount, ngfResourceCounts.GRPCRouteCount = computeRouteCount(g.Routes) ngfResourceCounts.SecretCount = int64(len(g.ReferencedSecrets)) ngfResourceCounts.ServiceCount = int64(len(g.ReferencedServices)) @@ -184,16 +188,21 @@ func collectGraphResourceCount( } } + ngfResourceCounts.BackendTLSPolicyCount = computeBackendTLSPolicyCount(g.BackendTLSPolicies) + return ngfResourceCounts, nil } -func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount int64) { +func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount, grpcRouteCount int64) { for _, r := range routes { if r.RouteType == graph.RouteTypeHTTP { httpRouteCount = httpRouteCount + 1 } + if r.RouteType == graph.RouteTypeGRPC { + grpcRouteCount = grpcRouteCount + 1 + } } - return httpRouteCount + return httpRouteCount, grpcRouteCount } func getPodReplicaSet( @@ -315,3 +324,14 @@ func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (cl return clusterInfo, nil } + +func computeBackendTLSPolicyCount(policies map[types.NamespacedName]*graph.BackendTLSPolicy) ( + backendTLSPolicyCount int64, +) { + for _, policy := range policies { + if policy.Valid { + backendTLSPolicyCount = backendTLSPolicyCount + 1 + } + } + return backendTLSPolicyCount +} diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 35475c0394..4485f20bd1 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -283,6 +283,7 @@ var _ = Describe("Collector", Ordered, func() { {NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-2"}}: {RouteType: graph.RouteTypeHTTP}, {NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-3"}}: {RouteType: graph.RouteTypeHTTP}, {NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-1"}}: {RouteType: graph.RouteTypeGRPC}, + {NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-2"}}: {RouteType: graph.RouteTypeGRPC}, }, ReferencedSecrets: map[types.NamespacedName]*graph.Secret{ client.ObjectKeyFromObject(secret1): { @@ -298,6 +299,11 @@ var _ = Describe("Collector", Ordered, func() { client.ObjectKeyFromObject(svc2): {}, client.ObjectKeyFromObject(nilsvc): {}, }, + BackendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{ + {Namespace: "test", Name: "bgPolicy-1"}: {Valid: true}, + {Namespace: "test", Name: "bgPolicy-2"}: {Valid: true}, + {Namespace: "test", Name: "bgPolicy-3"}: {}, + }, } config := &dataplane.Configuration{ @@ -336,12 +342,14 @@ var _ = Describe("Collector", Ordered, func() { expData.ClusterNodeCount = 3 expData.NGFResourceCounts = telemetry.NGFResourceCounts{ - GatewayCount: 3, - GatewayClassCount: 3, - HTTPRouteCount: 3, - SecretCount: 3, - ServiceCount: 3, - EndpointCount: 4, + GatewayCount: 3, + GatewayClassCount: 3, + HTTPRouteCount: 3, + SecretCount: 3, + ServiceCount: 3, + EndpointCount: 4, + GRPCRouteCount: 2, + BackendTLSPolicyCount: 2, } expData.ClusterVersion = "1.29.2" expData.ClusterPlatform = "kind" @@ -567,12 +575,14 @@ var _ = Describe("Collector", Ordered, func() { fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{}) fakeConfigurationGetter.GetLatestConfigurationReturns(invalidUpstreamsConfig) expData.NGFResourceCounts = telemetry.NGFResourceCounts{ - GatewayCount: 0, - GatewayClassCount: 0, - HTTPRouteCount: 0, - SecretCount: 0, - ServiceCount: 0, - EndpointCount: 0, + GatewayCount: 0, + GatewayClassCount: 0, + HTTPRouteCount: 0, + SecretCount: 0, + ServiceCount: 0, + EndpointCount: 0, + GRPCRouteCount: 0, + BackendTLSPolicyCount: 0, } data, err := dataCollector.Collect(ctx) diff --git a/internal/mode/static/telemetry/data.avdl b/internal/mode/static/telemetry/data.avdl index 2077d28779..68880f3b4c 100644 --- a/internal/mode/static/telemetry/data.avdl +++ b/internal/mode/static/telemetry/data.avdl @@ -62,6 +62,12 @@ Each value is either 'true' or 'false' for boolean flags and 'default' or 'user- /** EndpointCount include the total count of Endpoints(IP:port) across all referenced services. */ long? EndpointCount = null; + /** GRPCRouteCount is the number of relevant GRPCRoutes. */ + long? GRPCRouteCount = null; + + /** BackendTLSPolicyCount is the number of relevant BackendTLSPolicies. */ + long? BackendTLSPolicyCount = null; + /** NGFReplicaCount is the number of replicas of the NGF Pod. */ long? NGFReplicaCount = null; diff --git a/internal/mode/static/telemetry/data_test.go b/internal/mode/static/telemetry/data_test.go index b18ce17cb9..a8285fc8f2 100644 --- a/internal/mode/static/telemetry/data_test.go +++ b/internal/mode/static/telemetry/data_test.go @@ -24,12 +24,14 @@ func TestDataAttributes(t *testing.T) { FlagNames: []string{"test-flag"}, FlagValues: []string{"test-value"}, NGFResourceCounts: NGFResourceCounts{ - GatewayCount: 1, - GatewayClassCount: 2, - HTTPRouteCount: 3, - SecretCount: 4, - ServiceCount: 5, - EndpointCount: 6, + GatewayCount: 1, + GatewayClassCount: 2, + HTTPRouteCount: 3, + SecretCount: 4, + ServiceCount: 5, + EndpointCount: 6, + GRPCRouteCount: 7, + BackendTLSPolicyCount: 8, }, NGFReplicaCount: 3, } @@ -53,13 +55,14 @@ func TestDataAttributes(t *testing.T) { attribute.Int64("SecretCount", 4), attribute.Int64("ServiceCount", 5), attribute.Int64("EndpointCount", 6), + attribute.Int64("GRPCRouteCount", 7), + attribute.Int64("BackendTLSPolicyCount", 8), attribute.Int64("NGFReplicaCount", 3), } result := data.Attributes() g := NewWithT(t) - g.Expect(result).To(Equal(expected)) } @@ -85,6 +88,8 @@ func TestDataAttributesWithEmptyData(t *testing.T) { attribute.Int64("SecretCount", 0), attribute.Int64("ServiceCount", 0), attribute.Int64("EndpointCount", 0), + attribute.Int64("GRPCRouteCount", 0), + attribute.Int64("BackendTLSPolicyCount", 0), attribute.Int64("NGFReplicaCount", 0), } diff --git a/internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go b/internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go index 19fa4ae744..f32dc40c06 100644 --- a/internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go +++ b/internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go @@ -21,6 +21,8 @@ func (d *NGFResourceCounts) Attributes() []attribute.KeyValue { attrs = append(attrs, attribute.Int64("SecretCount", d.SecretCount)) attrs = append(attrs, attribute.Int64("ServiceCount", d.ServiceCount)) attrs = append(attrs, attribute.Int64("EndpointCount", d.EndpointCount)) + attrs = append(attrs, attribute.Int64("GRPCRouteCount", d.GRPCRouteCount)) + attrs = append(attrs, attribute.Int64("BackendTLSPolicyCount", d.BackendTLSPolicyCount)) return attrs diff --git a/site/content/overview/product-telemetry.md b/site/content/overview/product-telemetry.md index 8db9f360c9..9f0096e9b4 100644 --- a/site/content/overview/product-telemetry.md +++ b/site/content/overview/product-telemetry.md @@ -26,7 +26,7 @@ Telemetry data is collected once every 24 hours and sent to a service managed by - **Deployment Replica Count:** the count of NGINX Gateway Fabric Pods. - **Image Build Source:** whether the image was built by GitHub or locally (values are `gha`, `local`, or `unknown`). The source repository of the images is **not** collected. - **Deployment Flags:** a list of NGINX Gateway Fabric Deployment flags that are specified by a user. The actual values of non-boolean flags are **not** collected; we only record that they are either `true` or `false` for boolean flags and `default` or `user-defined` for the rest. -- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`, `Secrets`, `Services`, and `Endpoints`. The data within these resources is **not** collected. +- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`,`GRPCRoutes`, `Secrets`, `Services`, `BackendTLSPolicy`, and `Endpoints`. The data within these resources is **not** collected. This data is used to identify the following information: From 778f7ed87c07e9be25b2b0975d47da754cd0efca Mon Sep 17 00:00:00 2001 From: Saloni Date: Tue, 14 May 2024 10:15:59 -0600 Subject: [PATCH 2/7] fix unit tests --- tests/suite/telemetry_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/suite/telemetry_test.go b/tests/suite/telemetry_test.go index dab0fca191..ec6cbf0999 100644 --- a/tests/suite/telemetry_test.go +++ b/tests/suite/telemetry_test.go @@ -95,6 +95,8 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func( "SecretCount: Int(0)", "ServiceCount: Int(0)", "EndpointCount: Int(0)", + "GRPCRouteCount: Int(0)", + "BackendTLSPolicyCount: Int(0)", "NGFReplicaCount: Int(1)", }, ) From f6d2061a567b3802c9e2e4bf7ea3fa11a0a7ac69 Mon Sep 17 00:00:00 2001 From: Saloni Date: Wed, 15 May 2024 14:11:18 -0600 Subject: [PATCH 3/7] remove backednTLSPolicy check --- internal/mode/static/telemetry/collector.go | 13 +------------ internal/mode/static/telemetry/collector_test.go | 6 +++--- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/internal/mode/static/telemetry/collector.go b/internal/mode/static/telemetry/collector.go index de206c2126..a3c5cee399 100644 --- a/internal/mode/static/telemetry/collector.go +++ b/internal/mode/static/telemetry/collector.go @@ -188,7 +188,7 @@ func collectGraphResourceCount( } } - ngfResourceCounts.BackendTLSPolicyCount = computeBackendTLSPolicyCount(g.BackendTLSPolicies) + ngfResourceCounts.BackendTLSPolicyCount = int64(len(g.BackendTLSPolicies)) return ngfResourceCounts, nil } @@ -324,14 +324,3 @@ func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (cl return clusterInfo, nil } - -func computeBackendTLSPolicyCount(policies map[types.NamespacedName]*graph.BackendTLSPolicy) ( - backendTLSPolicyCount int64, -) { - for _, policy := range policies { - if policy.Valid { - backendTLSPolicyCount = backendTLSPolicyCount + 1 - } - } - return backendTLSPolicyCount -} diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 4485f20bd1..dbb1f6571a 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -300,8 +300,8 @@ var _ = Describe("Collector", Ordered, func() { client.ObjectKeyFromObject(nilsvc): {}, }, BackendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{ - {Namespace: "test", Name: "bgPolicy-1"}: {Valid: true}, - {Namespace: "test", Name: "bgPolicy-2"}: {Valid: true}, + {Namespace: "test", Name: "bgPolicy-1"}: {}, + {Namespace: "test", Name: "bgPolicy-2"}: {}, {Namespace: "test", Name: "bgPolicy-3"}: {}, }, } @@ -349,7 +349,7 @@ var _ = Describe("Collector", Ordered, func() { ServiceCount: 3, EndpointCount: 4, GRPCRouteCount: 2, - BackendTLSPolicyCount: 2, + BackendTLSPolicyCount: 3, } expData.ClusterVersion = "1.29.2" expData.ClusterPlatform = "kind" From ed92d69cc364e212e78f13b3aec011adb64055db Mon Sep 17 00:00:00 2001 From: salonichf5 <146118978+salonichf5@users.noreply.github.com> Date: Wed, 15 May 2024 15:35:14 -0600 Subject: [PATCH 4/7] Update site/content/overview/product-telemetry.md Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com> --- site/content/overview/product-telemetry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/overview/product-telemetry.md b/site/content/overview/product-telemetry.md index 9f0096e9b4..97c161579d 100644 --- a/site/content/overview/product-telemetry.md +++ b/site/content/overview/product-telemetry.md @@ -26,7 +26,7 @@ Telemetry data is collected once every 24 hours and sent to a service managed by - **Deployment Replica Count:** the count of NGINX Gateway Fabric Pods. - **Image Build Source:** whether the image was built by GitHub or locally (values are `gha`, `local`, or `unknown`). The source repository of the images is **not** collected. - **Deployment Flags:** a list of NGINX Gateway Fabric Deployment flags that are specified by a user. The actual values of non-boolean flags are **not** collected; we only record that they are either `true` or `false` for boolean flags and `default` or `user-defined` for the rest. -- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`,`GRPCRoutes`, `Secrets`, `Services`, `BackendTLSPolicy`, and `Endpoints`. The data within these resources is **not** collected. +- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`,`GRPCRoutes`, `Secrets`, `Services`, `BackendTLSPolicies`, and `Endpoints`. The data within these resources is **not** collected. This data is used to identify the following information: From 900c7835269fbfb821652c0d58a76e10d7a1bacf Mon Sep 17 00:00:00 2001 From: Saloni Date: Wed, 15 May 2024 16:51:08 -0600 Subject: [PATCH 5/7] fix typo --- internal/mode/static/telemetry/collector_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index dbb1f6571a..599ed516d2 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -300,9 +300,9 @@ var _ = Describe("Collector", Ordered, func() { client.ObjectKeyFromObject(nilsvc): {}, }, BackendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{ - {Namespace: "test", Name: "bgPolicy-1"}: {}, - {Namespace: "test", Name: "bgPolicy-2"}: {}, - {Namespace: "test", Name: "bgPolicy-3"}: {}, + {Namespace: "test", Name: "backendTLSPolicy-1"}: {}, + {Namespace: "test", Name: "backendTLSPolicy-2"}: {}, + {Namespace: "test", Name: "backendTLSPolicy-3"}: {}, }, } From 87a12930a69daa90fc3a810e29bd3496d7289853 Mon Sep 17 00:00:00 2001 From: Saloni Date: Wed, 15 May 2024 18:55:41 -0600 Subject: [PATCH 6/7] fix docString removal for data.avdl --- internal/mode/static/telemetry/data.avdl | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/mode/static/telemetry/data.avdl b/internal/mode/static/telemetry/data.avdl index 68880f3b4c..ce707b67c2 100644 --- a/internal/mode/static/telemetry/data.avdl +++ b/internal/mode/static/telemetry/data.avdl @@ -1,4 +1,5 @@ @namespace("gateway.nginx.org") protocol NGFProductTelemetry { + /** Data is the product telemetry data of NGINX Gateway Fabric. */ @df_datatype("ngf-product-telemetry") record Data { /** The field that identifies what type of data this is. */ string dataType; From 836a5c8c467a0a9c3143bafe62d3e8c7c3487b28 Mon Sep 17 00:00:00 2001 From: Saloni Date: Wed, 15 May 2024 19:00:22 -0600 Subject: [PATCH 7/7] redo file changes --- internal/mode/static/telemetry/data.avdl | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/mode/static/telemetry/data.avdl b/internal/mode/static/telemetry/data.avdl index ce707b67c2..68880f3b4c 100644 --- a/internal/mode/static/telemetry/data.avdl +++ b/internal/mode/static/telemetry/data.avdl @@ -1,5 +1,4 @@ @namespace("gateway.nginx.org") protocol NGFProductTelemetry { - /** Data is the product telemetry data of NGINX Gateway Fabric. */ @df_datatype("ngf-product-telemetry") record Data { /** The field that identifies what type of data this is. */ string dataType;