Skip to content

Commit 074f96e

Browse files
bjee19sarthyparty
andauthored
Add NGF telemetry data for TLSRoute (#2387)
Problem: NGF did not support telemetry for TLSRoute. Solution: Add telemetry collection of TLSRoute. Testing: Added unit tests for the updated code. Co-authored-by: Sarthak Agrawal <s.agrawal@f5.com>
1 parent a781c49 commit 074f96e

File tree

7 files changed

+46
-4
lines changed

7 files changed

+46
-4
lines changed

internal/mode/static/telemetry/collector.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type NGFResourceCounts struct {
6262
GatewayClassCount int64
6363
// HTTPRouteCount is the number of relevant HTTPRoutes.
6464
HTTPRouteCount int64
65+
// TLSRouteCount is the number of relevant TLSRoutes.
66+
TLSRouteCount int64
6567
// SecretCount is the number of relevant Secrets.
6668
SecretCount int64
6769
// ServiceCount is the number of relevant Services.
@@ -188,7 +190,11 @@ func collectGraphResourceCount(
188190
ngfResourceCounts.GatewayCount++
189191
}
190192

191-
ngfResourceCounts.HTTPRouteCount, ngfResourceCounts.GRPCRouteCount = computeRouteCount(g.Routes)
193+
routeCounts := computeRouteCount(g.Routes, g.L4Routes)
194+
ngfResourceCounts.HTTPRouteCount = routeCounts.HTTPRouteCount
195+
ngfResourceCounts.GRPCRouteCount = routeCounts.GRPCRouteCount
196+
ngfResourceCounts.TLSRouteCount = routeCounts.TLSRouteCount
197+
192198
ngfResourceCounts.SecretCount = int64(len(g.ReferencedSecrets))
193199
ngfResourceCounts.ServiceCount = int64(len(g.ReferencedServices))
194200

@@ -224,7 +230,19 @@ func collectGraphResourceCount(
224230
return ngfResourceCounts, nil
225231
}
226232

227-
func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount, grpcRouteCount int64) {
233+
type RouteCounts struct {
234+
HTTPRouteCount int64
235+
GRPCRouteCount int64
236+
TLSRouteCount int64
237+
}
238+
239+
func computeRouteCount(
240+
routes map[graph.RouteKey]*graph.L7Route,
241+
l4routes map[graph.L4RouteKey]*graph.L4Route,
242+
) RouteCounts {
243+
httpRouteCount := int64(0)
244+
grpcRouteCount := int64(0)
245+
228246
for _, r := range routes {
229247
if r.RouteType == graph.RouteTypeHTTP {
230248
httpRouteCount = httpRouteCount + 1
@@ -233,7 +251,12 @@ func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount
233251
grpcRouteCount = grpcRouteCount + 1
234252
}
235253
}
236-
return httpRouteCount, grpcRouteCount
254+
255+
return RouteCounts{
256+
HTTPRouteCount: httpRouteCount,
257+
GRPCRouteCount: grpcRouteCount,
258+
TLSRouteCount: int64(len(l4routes)),
259+
}
237260
}
238261

239262
func getPodReplicaSet(

internal/mode/static/telemetry/collector_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ var _ = Describe("Collector", Ordered, func() {
287287
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-1"}}: {RouteType: graph.RouteTypeGRPC},
288288
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-2"}}: {RouteType: graph.RouteTypeGRPC},
289289
},
290+
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
291+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-1"}}: {},
292+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-2"}}: {},
293+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-3"}}: {},
294+
},
290295
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
291296
client.ObjectKeyFromObject(secret1): {
292297
Source: secret1,
@@ -366,6 +371,7 @@ var _ = Describe("Collector", Ordered, func() {
366371
GatewayCount: 3,
367372
GatewayClassCount: 3,
368373
HTTPRouteCount: 3,
374+
TLSRouteCount: 3,
369375
SecretCount: 3,
370376
ServiceCount: 3,
371377
EndpointCount: 4,
@@ -512,6 +518,9 @@ var _ = Describe("Collector", Ordered, func() {
512518
Routes: map[graph.RouteKey]*graph.L7Route{
513519
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}}: {RouteType: graph.RouteTypeHTTP},
514520
},
521+
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
522+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-1"}}: {},
523+
},
515524
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
516525
client.ObjectKeyFromObject(secret): {
517526
Source: secret,
@@ -604,6 +613,7 @@ var _ = Describe("Collector", Ordered, func() {
604613
GatewayCount: 1,
605614
GatewayClassCount: 1,
606615
HTTPRouteCount: 1,
616+
TLSRouteCount: 1,
607617
SecretCount: 1,
608618
ServiceCount: 1,
609619
EndpointCount: 1,
@@ -626,6 +636,7 @@ var _ = Describe("Collector", Ordered, func() {
626636
GatewayCount: 0,
627637
GatewayClassCount: 0,
628638
HTTPRouteCount: 0,
639+
TLSRouteCount: 0,
629640
SecretCount: 0,
630641
ServiceCount: 0,
631642
EndpointCount: 0,

internal/mode/static/telemetry/data.avdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Each value is either 'true' or 'false' for boolean flags and 'default' or 'user-
5454
/** HTTPRouteCount is the number of relevant HTTPRoutes. */
5555
long? HTTPRouteCount = null;
5656

57+
/** TLSRouteCount is the number of relevant TLSRoutes. */
58+
long? TLSRouteCount = null;
59+
5760
/** SecretCount is the number of relevant Secrets. */
5861
long? SecretCount = null;
5962

internal/mode/static/telemetry/data_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestDataAttributes(t *testing.T) {
3131
ServiceCount: 5,
3232
EndpointCount: 6,
3333
GRPCRouteCount: 7,
34+
TLSRouteCount: 5,
3435
BackendTLSPolicyCount: 8,
3536
GatewayAttachedClientSettingsPolicyCount: 9,
3637
RouteAttachedClientSettingsPolicyCount: 10,
@@ -56,6 +57,7 @@ func TestDataAttributes(t *testing.T) {
5657
attribute.Int64("GatewayCount", 1),
5758
attribute.Int64("GatewayClassCount", 2),
5859
attribute.Int64("HTTPRouteCount", 3),
60+
attribute.Int64("TLSRouteCount", 5),
5961
attribute.Int64("SecretCount", 4),
6062
attribute.Int64("ServiceCount", 5),
6163
attribute.Int64("EndpointCount", 6),
@@ -93,6 +95,7 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
9395
attribute.Int64("GatewayCount", 0),
9496
attribute.Int64("GatewayClassCount", 0),
9597
attribute.Int64("HTTPRouteCount", 0),
98+
attribute.Int64("TLSRouteCount", 0),
9699
attribute.Int64("SecretCount", 0),
97100
attribute.Int64("ServiceCount", 0),
98101
attribute.Int64("EndpointCount", 0),

internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (d *NGFResourceCounts) Attributes() []attribute.KeyValue {
1515
attrs = append(attrs, attribute.Int64("GatewayCount", d.GatewayCount))
1616
attrs = append(attrs, attribute.Int64("GatewayClassCount", d.GatewayClassCount))
1717
attrs = append(attrs, attribute.Int64("HTTPRouteCount", d.HTTPRouteCount))
18+
attrs = append(attrs, attribute.Int64("TLSRouteCount", d.TLSRouteCount))
1819
attrs = append(attrs, attribute.Int64("SecretCount", d.SecretCount))
1920
attrs = append(attrs, attribute.Int64("ServiceCount", d.ServiceCount))
2021
attrs = append(attrs, attribute.Int64("EndpointCount", d.EndpointCount))

site/content/overview/product-telemetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Telemetry data is collected once every 24 hours and sent to a service managed by
2727
- **Deployment Replica Count:** the count of NGINX Gateway Fabric Pods.
2828
- **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.
2929
- **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.
30-
- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`,`GRPCRoutes`, `Secrets`, `Services`, `BackendTLSPolicies`, `ClientSettingsPolicies`, `NginxProxies`, `ObservabilityPolicies`, and `Endpoints`. The data within these resources is **not** collected.
30+
- **Count of Resources:** the total count of resources related to NGINX Gateway Fabric. This includes `GatewayClasses`, `Gateways`, `HTTPRoutes`,`GRPCRoutes`, `TLSRoutes`, `Secrets`, `Services`, `BackendTLSPolicies`, `ClientSettingsPolicies`, `NginxProxies`, `ObservabilityPolicies`, and `Endpoints`. The data within these resources is **not** collected.
3131

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

tests/suite/telemetry_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
7575
"GatewayCount: Int(0)",
7676
"GatewayClassCount: Int(1)",
7777
"HTTPRouteCount: Int(0)",
78+
"TLSRouteCount: Int(0)",
7879
"SecretCount: Int(0)",
7980
"ServiceCount: Int(0)",
8081
"EndpointCount: Int(0)",

0 commit comments

Comments
 (0)