Skip to content

Commit 696f8e4

Browse files
sarthypartybjee19
authored andcommitted
Add NGF telemetry data for TLSRoute
Problem: NGF did not support telemetry for TLSRoute Solution: I counted the number of TLSRoutes in the graph and added it to the telemetry data
1 parent a781c49 commit 696f8e4

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
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,

0 commit comments

Comments
 (0)