Skip to content

Commit

Permalink
Add NGF telemetry data for TLSRoute (#2387)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bjee19 and sarthyparty authored Aug 15, 2024
1 parent a781c49 commit 074f96e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
29 changes: 26 additions & 3 deletions internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type NGFResourceCounts struct {
GatewayClassCount int64
// HTTPRouteCount is the number of relevant HTTPRoutes.
HTTPRouteCount int64
// TLSRouteCount is the number of relevant TLSRoutes.
TLSRouteCount int64
// SecretCount is the number of relevant Secrets.
SecretCount int64
// ServiceCount is the number of relevant Services.
Expand Down Expand Up @@ -188,7 +190,11 @@ func collectGraphResourceCount(
ngfResourceCounts.GatewayCount++
}

ngfResourceCounts.HTTPRouteCount, ngfResourceCounts.GRPCRouteCount = computeRouteCount(g.Routes)
routeCounts := computeRouteCount(g.Routes, g.L4Routes)
ngfResourceCounts.HTTPRouteCount = routeCounts.HTTPRouteCount
ngfResourceCounts.GRPCRouteCount = routeCounts.GRPCRouteCount
ngfResourceCounts.TLSRouteCount = routeCounts.TLSRouteCount

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

Expand Down Expand Up @@ -224,7 +230,19 @@ func collectGraphResourceCount(
return ngfResourceCounts, nil
}

func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount, grpcRouteCount int64) {
type RouteCounts struct {
HTTPRouteCount int64
GRPCRouteCount int64
TLSRouteCount int64
}

func computeRouteCount(
routes map[graph.RouteKey]*graph.L7Route,
l4routes map[graph.L4RouteKey]*graph.L4Route,
) RouteCounts {
httpRouteCount := int64(0)
grpcRouteCount := int64(0)

for _, r := range routes {
if r.RouteType == graph.RouteTypeHTTP {
httpRouteCount = httpRouteCount + 1
Expand All @@ -233,7 +251,12 @@ func computeRouteCount(routes map[graph.RouteKey]*graph.L7Route) (httpRouteCount
grpcRouteCount = grpcRouteCount + 1
}
}
return httpRouteCount, grpcRouteCount

return RouteCounts{
HTTPRouteCount: httpRouteCount,
GRPCRouteCount: grpcRouteCount,
TLSRouteCount: int64(len(l4routes)),
}
}

func getPodReplicaSet(
Expand Down
11 changes: 11 additions & 0 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ var _ = Describe("Collector", Ordered, func() {
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-1"}}: {RouteType: graph.RouteTypeGRPC},
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-2"}}: {RouteType: graph.RouteTypeGRPC},
},
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-1"}}: {},
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-2"}}: {},
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-3"}}: {},
},
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
client.ObjectKeyFromObject(secret1): {
Source: secret1,
Expand Down Expand Up @@ -366,6 +371,7 @@ var _ = Describe("Collector", Ordered, func() {
GatewayCount: 3,
GatewayClassCount: 3,
HTTPRouteCount: 3,
TLSRouteCount: 3,
SecretCount: 3,
ServiceCount: 3,
EndpointCount: 4,
Expand Down Expand Up @@ -512,6 +518,9 @@ var _ = Describe("Collector", Ordered, func() {
Routes: map[graph.RouteKey]*graph.L7Route{
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "hr-1"}}: {RouteType: graph.RouteTypeHTTP},
},
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "tr-1"}}: {},
},
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
client.ObjectKeyFromObject(secret): {
Source: secret,
Expand Down Expand Up @@ -604,6 +613,7 @@ var _ = Describe("Collector", Ordered, func() {
GatewayCount: 1,
GatewayClassCount: 1,
HTTPRouteCount: 1,
TLSRouteCount: 1,
SecretCount: 1,
ServiceCount: 1,
EndpointCount: 1,
Expand All @@ -626,6 +636,7 @@ var _ = Describe("Collector", Ordered, func() {
GatewayCount: 0,
GatewayClassCount: 0,
HTTPRouteCount: 0,
TLSRouteCount: 0,
SecretCount: 0,
ServiceCount: 0,
EndpointCount: 0,
Expand Down
3 changes: 3 additions & 0 deletions internal/mode/static/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Each value is either 'true' or 'false' for boolean flags and 'default' or 'user-
/** HTTPRouteCount is the number of relevant HTTPRoutes. */
long? HTTPRouteCount = null;

/** TLSRouteCount is the number of relevant TLSRoutes. */
long? TLSRouteCount = null;

/** SecretCount is the number of relevant Secrets. */
long? SecretCount = null;

Expand Down
3 changes: 3 additions & 0 deletions internal/mode/static/telemetry/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestDataAttributes(t *testing.T) {
ServiceCount: 5,
EndpointCount: 6,
GRPCRouteCount: 7,
TLSRouteCount: 5,
BackendTLSPolicyCount: 8,
GatewayAttachedClientSettingsPolicyCount: 9,
RouteAttachedClientSettingsPolicyCount: 10,
Expand All @@ -56,6 +57,7 @@ func TestDataAttributes(t *testing.T) {
attribute.Int64("GatewayCount", 1),
attribute.Int64("GatewayClassCount", 2),
attribute.Int64("HTTPRouteCount", 3),
attribute.Int64("TLSRouteCount", 5),
attribute.Int64("SecretCount", 4),
attribute.Int64("ServiceCount", 5),
attribute.Int64("EndpointCount", 6),
Expand Down Expand Up @@ -93,6 +95,7 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
attribute.Int64("GatewayCount", 0),
attribute.Int64("GatewayClassCount", 0),
attribute.Int64("HTTPRouteCount", 0),
attribute.Int64("TLSRouteCount", 0),
attribute.Int64("SecretCount", 0),
attribute.Int64("ServiceCount", 0),
attribute.Int64("EndpointCount", 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (d *NGFResourceCounts) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.Int64("GatewayCount", d.GatewayCount))
attrs = append(attrs, attribute.Int64("GatewayClassCount", d.GatewayClassCount))
attrs = append(attrs, attribute.Int64("HTTPRouteCount", d.HTTPRouteCount))
attrs = append(attrs, attribute.Int64("TLSRouteCount", d.TLSRouteCount))
attrs = append(attrs, attribute.Int64("SecretCount", d.SecretCount))
attrs = append(attrs, attribute.Int64("ServiceCount", d.ServiceCount))
attrs = append(attrs, attribute.Int64("EndpointCount", d.EndpointCount))
Expand Down
2 changes: 1 addition & 1 deletion site/content/overview/product-telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Telemetry data is collected once every 24 hours and sent to a service managed by
- **Deployment Replica Count:** the count of NGINX Gateway Fabric Pods.
- **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.
- **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.
- **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.
- **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.

This data is used to identify the following information:

Expand Down
1 change: 1 addition & 0 deletions tests/suite/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
"GatewayCount: Int(0)",
"GatewayClassCount: Int(1)",
"HTTPRouteCount: Int(0)",
"TLSRouteCount: Int(0)",
"SecretCount: Int(0)",
"ServiceCount: Int(0)",
"EndpointCount: Int(0)",
Expand Down

0 comments on commit 074f96e

Please sign in to comment.