Skip to content

Commit 8dc7329

Browse files
authored
Fix httproute counts (#1922)
1 parent 8505f8b commit 8dc7329

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

internal/mode/static/telemetry/collector.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func collectGraphResourceCount(
174174
ngfResourceCounts.GatewayCount++
175175
}
176176

177-
ngfResourceCounts.HTTPRouteCount = int64(len(g.Routes))
177+
ngfResourceCounts.HTTPRouteCount = computeRouteCount(g.Routes)
178178
ngfResourceCounts.SecretCount = int64(len(g.ReferencedSecrets))
179179
ngfResourceCounts.ServiceCount = int64(len(g.ReferencedServices))
180180

@@ -187,6 +187,15 @@ func collectGraphResourceCount(
187187
return ngfResourceCounts, nil
188188
}
189189

190+
func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount int64) {
191+
for _, r := range routes {
192+
if r.RouteType == graph.RouteTypeHTTP {
193+
httpRouteCount = httpRouteCount + 1
194+
}
195+
}
196+
return httpRouteCount
197+
}
198+
190199
func getPodReplicaSet(
191200
ctx context.Context,
192201
k8sClient client.Reader,

internal/mode/static/telemetry/collector_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ var _ = Describe("Collector", Ordered, func() {
279279
{Name: "ignoredGw2"}: {},
280280
},
281281
Routes: map[graph.RouteKey]*graph.L7Route{
282-
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}, RouteType: graph.RouteTypeHTTP}: {},
283-
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-2"}, RouteType: graph.RouteTypeHTTP}: {},
284-
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-3"}, RouteType: graph.RouteTypeHTTP}: {},
282+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}}: {RouteType: graph.RouteTypeHTTP},
283+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-2"}}: {RouteType: graph.RouteTypeHTTP},
284+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-3"}}: {RouteType: graph.RouteTypeHTTP},
285+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-1"}}: {RouteType: graph.RouteTypeGRPC},
285286
},
286287
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
287288
client.ObjectKeyFromObject(secret1): {
@@ -476,7 +477,7 @@ var _ = Describe("Collector", Ordered, func() {
476477
GatewayClass: &graph.GatewayClass{},
477478
Gateway: &graph.Gateway{},
478479
Routes: map[graph.RouteKey]*graph.L7Route{
479-
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}, RouteType: graph.RouteTypeHTTP}: {},
480+
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}}: {RouteType: graph.RouteTypeHTTP},
480481
},
481482
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
482483
client.ObjectKeyFromObject(secret): {

0 commit comments

Comments
 (0)