Skip to content

Commit 18c4f4c

Browse files
authored
Collect backendTLSPolicy and GRPCRoute Count (#1954)
Problem: I want to collect the GRPCRoute and BackendTLSPolicy count from all NGF/NIC installations. Solution: Adding two new fields GRPCRouteCount, BackendTLSPolicyCount to telemetry data collector.
1 parent 59c8f50 commit 18c4f4c

File tree

7 files changed

+57
-23
lines changed

7 files changed

+57
-23
lines changed

internal/mode/static/telemetry/collector.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ type NGFResourceCounts struct {
6767
ServiceCount int64
6868
// EndpointCount include the total count of Endpoints(IP:port) across all referenced services.
6969
EndpointCount int64
70+
// GRPCRouteCount is the number of relevant GRPCRoutes.
71+
GRPCRouteCount int64
72+
// BackendTLSPolicyCount is the number of relevant BackendTLSPolicies.
73+
BackendTLSPolicyCount int64
7074
}
7175

7276
// DataCollectorConfig holds configuration parameters for DataCollectorImpl.
@@ -174,7 +178,7 @@ func collectGraphResourceCount(
174178
ngfResourceCounts.GatewayCount++
175179
}
176180

177-
ngfResourceCounts.HTTPRouteCount = computeRouteCount(g.Routes)
181+
ngfResourceCounts.HTTPRouteCount, ngfResourceCounts.GRPCRouteCount = computeRouteCount(g.Routes)
178182
ngfResourceCounts.SecretCount = int64(len(g.ReferencedSecrets))
179183
ngfResourceCounts.ServiceCount = int64(len(g.ReferencedServices))
180184

@@ -184,16 +188,21 @@ func collectGraphResourceCount(
184188
}
185189
}
186190

191+
ngfResourceCounts.BackendTLSPolicyCount = int64(len(g.BackendTLSPolicies))
192+
187193
return ngfResourceCounts, nil
188194
}
189195

190-
func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount int64) {
196+
func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount, grpcRouteCount int64) {
191197
for _, r := range routes {
192198
if r.RouteType == graph.RouteTypeHTTP {
193199
httpRouteCount = httpRouteCount + 1
194200
}
201+
if r.RouteType == graph.RouteTypeGRPC {
202+
grpcRouteCount = grpcRouteCount + 1
203+
}
195204
}
196-
return httpRouteCount
205+
return httpRouteCount, grpcRouteCount
197206
}
198207

199208
func getPodReplicaSet(

internal/mode/static/telemetry/collector_test.go

+22-12
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ var _ = Describe("Collector", Ordered, func() {
283283
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-2"}}: {RouteType: graph.RouteTypeHTTP},
284284
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-3"}}: {RouteType: graph.RouteTypeHTTP},
285285
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-1"}}: {RouteType: graph.RouteTypeGRPC},
286+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-2"}}: {RouteType: graph.RouteTypeGRPC},
286287
},
287288
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
288289
client.ObjectKeyFromObject(secret1): {
@@ -298,6 +299,11 @@ var _ = Describe("Collector", Ordered, func() {
298299
client.ObjectKeyFromObject(svc2): {},
299300
client.ObjectKeyFromObject(nilsvc): {},
300301
},
302+
BackendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
303+
{Namespace: "test", Name: "backendTLSPolicy-1"}: {},
304+
{Namespace: "test", Name: "backendTLSPolicy-2"}: {},
305+
{Namespace: "test", Name: "backendTLSPolicy-3"}: {},
306+
},
301307
}
302308

303309
config := &dataplane.Configuration{
@@ -336,12 +342,14 @@ var _ = Describe("Collector", Ordered, func() {
336342

337343
expData.ClusterNodeCount = 3
338344
expData.NGFResourceCounts = telemetry.NGFResourceCounts{
339-
GatewayCount: 3,
340-
GatewayClassCount: 3,
341-
HTTPRouteCount: 3,
342-
SecretCount: 3,
343-
ServiceCount: 3,
344-
EndpointCount: 4,
345+
GatewayCount: 3,
346+
GatewayClassCount: 3,
347+
HTTPRouteCount: 3,
348+
SecretCount: 3,
349+
ServiceCount: 3,
350+
EndpointCount: 4,
351+
GRPCRouteCount: 2,
352+
BackendTLSPolicyCount: 3,
345353
}
346354
expData.ClusterVersion = "1.29.2"
347355
expData.ClusterPlatform = "kind"
@@ -567,12 +575,14 @@ var _ = Describe("Collector", Ordered, func() {
567575
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
568576
fakeConfigurationGetter.GetLatestConfigurationReturns(invalidUpstreamsConfig)
569577
expData.NGFResourceCounts = telemetry.NGFResourceCounts{
570-
GatewayCount: 0,
571-
GatewayClassCount: 0,
572-
HTTPRouteCount: 0,
573-
SecretCount: 0,
574-
ServiceCount: 0,
575-
EndpointCount: 0,
578+
GatewayCount: 0,
579+
GatewayClassCount: 0,
580+
HTTPRouteCount: 0,
581+
SecretCount: 0,
582+
ServiceCount: 0,
583+
EndpointCount: 0,
584+
GRPCRouteCount: 0,
585+
BackendTLSPolicyCount: 0,
576586
}
577587

578588
data, err := dataCollector.Collect(ctx)

internal/mode/static/telemetry/data.avdl

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Each value is either 'true' or 'false' for boolean flags and 'default' or 'user-
6262
/** EndpointCount include the total count of Endpoints(IP:port) across all referenced services. */
6363
long? EndpointCount = null;
6464

65+
/** GRPCRouteCount is the number of relevant GRPCRoutes. */
66+
long? GRPCRouteCount = null;
67+
68+
/** BackendTLSPolicyCount is the number of relevant BackendTLSPolicies. */
69+
long? BackendTLSPolicyCount = null;
70+
6571
/** NGFReplicaCount is the number of replicas of the NGF Pod. */
6672
long? NGFReplicaCount = null;
6773

internal/mode/static/telemetry/data_test.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ func TestDataAttributes(t *testing.T) {
2424
FlagNames: []string{"test-flag"},
2525
FlagValues: []string{"test-value"},
2626
NGFResourceCounts: NGFResourceCounts{
27-
GatewayCount: 1,
28-
GatewayClassCount: 2,
29-
HTTPRouteCount: 3,
30-
SecretCount: 4,
31-
ServiceCount: 5,
32-
EndpointCount: 6,
27+
GatewayCount: 1,
28+
GatewayClassCount: 2,
29+
HTTPRouteCount: 3,
30+
SecretCount: 4,
31+
ServiceCount: 5,
32+
EndpointCount: 6,
33+
GRPCRouteCount: 7,
34+
BackendTLSPolicyCount: 8,
3335
},
3436
NGFReplicaCount: 3,
3537
}
@@ -53,13 +55,14 @@ func TestDataAttributes(t *testing.T) {
5355
attribute.Int64("SecretCount", 4),
5456
attribute.Int64("ServiceCount", 5),
5557
attribute.Int64("EndpointCount", 6),
58+
attribute.Int64("GRPCRouteCount", 7),
59+
attribute.Int64("BackendTLSPolicyCount", 8),
5660
attribute.Int64("NGFReplicaCount", 3),
5761
}
5862

5963
result := data.Attributes()
6064

6165
g := NewWithT(t)
62-
6366
g.Expect(result).To(Equal(expected))
6467
}
6568

@@ -85,6 +88,8 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
8588
attribute.Int64("SecretCount", 0),
8689
attribute.Int64("ServiceCount", 0),
8790
attribute.Int64("EndpointCount", 0),
91+
attribute.Int64("GRPCRouteCount", 0),
92+
attribute.Int64("BackendTLSPolicyCount", 0),
8893
attribute.Int64("NGFReplicaCount", 0),
8994
}
9095

internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func (d *NGFResourceCounts) Attributes() []attribute.KeyValue {
2121
attrs = append(attrs, attribute.Int64("SecretCount", d.SecretCount))
2222
attrs = append(attrs, attribute.Int64("ServiceCount", d.ServiceCount))
2323
attrs = append(attrs, attribute.Int64("EndpointCount", d.EndpointCount))
24+
attrs = append(attrs, attribute.Int64("GRPCRouteCount", d.GRPCRouteCount))
25+
attrs = append(attrs, attribute.Int64("BackendTLSPolicyCount", d.BackendTLSPolicyCount))
2426

2527

2628
return attrs

site/content/overview/product-telemetry.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Telemetry data is collected once every 24 hours and sent to a service managed by
2626
- **Deployment Replica Count:** the count of NGINX Gateway Fabric Pods.
2727
- **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.
2828
- **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.
29-
- **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.
29+
- **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.
3030

3131
This data is used to identify the following information:
3232

tests/suite/telemetry_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
9595
"SecretCount: Int(0)",
9696
"ServiceCount: Int(0)",
9797
"EndpointCount: Int(0)",
98+
"GRPCRouteCount: Int(0)",
99+
"BackendTLSPolicyCount: Int(0)",
98100
"NGFReplicaCount: Int(1)",
99101
},
100102
)

0 commit comments

Comments
 (0)