Skip to content

Commit

Permalink
Fix httproute counts (#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciarams87 committed May 2, 2024
1 parent 8505f8b commit 8dc7329
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func collectGraphResourceCount(
ngfResourceCounts.GatewayCount++
}

ngfResourceCounts.HTTPRouteCount = int64(len(g.Routes))
ngfResourceCounts.HTTPRouteCount = computeRouteCount(g.Routes)
ngfResourceCounts.SecretCount = int64(len(g.ReferencedSecrets))
ngfResourceCounts.ServiceCount = int64(len(g.ReferencedServices))

Expand All @@ -187,6 +187,15 @@ func collectGraphResourceCount(
return ngfResourceCounts, nil
}

func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount int64) {
for _, r := range routes {
if r.RouteType == graph.RouteTypeHTTP {
httpRouteCount = httpRouteCount + 1
}
}
return httpRouteCount
}

func getPodReplicaSet(
ctx context.Context,
k8sClient client.Reader,
Expand Down
9 changes: 5 additions & 4 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ var _ = Describe("Collector", Ordered, func() {
{Name: "ignoredGw2"}: {},
},
Routes: map[graph.RouteKey]*graph.L7Route{
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}, RouteType: graph.RouteTypeHTTP}: {},
{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: "hr-1"}}: {RouteType: graph.RouteTypeHTTP},
{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},
},
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
client.ObjectKeyFromObject(secret1): {
Expand Down Expand Up @@ -476,7 +477,7 @@ var _ = Describe("Collector", Ordered, func() {
GatewayClass: &graph.GatewayClass{},
Gateway: &graph.Gateway{},
Routes: map[graph.RouteKey]*graph.L7Route{
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}, RouteType: graph.RouteTypeHTTP}: {},
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}}: {RouteType: graph.RouteTypeHTTP},
},
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
client.ObjectKeyFromObject(secret): {
Expand Down

0 comments on commit 8dc7329

Please sign in to comment.