Skip to content

Collect backendTLSPolicy and GRPCRoute Count #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type NGFResourceCounts struct {
ServiceCount int64
// EndpointCount include the total count of Endpoints(IP:port) across all referenced services.
EndpointCount int64
// GRPCRouteCount is the number of relevant GRPCRoutes.
GRPCRouteCount int64
// BackendTLSPolicyCount is the number of relevant BackendTLSPolicies.
BackendTLSPolicyCount int64
}

// DataCollectorConfig holds configuration parameters for DataCollectorImpl.
Expand Down Expand Up @@ -174,7 +178,7 @@ func collectGraphResourceCount(
ngfResourceCounts.GatewayCount++
}

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

Expand All @@ -184,16 +188,21 @@ func collectGraphResourceCount(
}
}

ngfResourceCounts.BackendTLSPolicyCount = int64(len(g.BackendTLSPolicies))

return ngfResourceCounts, nil
}

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

func getPodReplicaSet(
Expand Down
34 changes: 22 additions & 12 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ var _ = Describe("Collector", Ordered, func() {
{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},
{NamespacedName: types.NamespacedName{Namespace: "test", Name: "gr-2"}}: {RouteType: graph.RouteTypeGRPC},
},
ReferencedSecrets: map[types.NamespacedName]*graph.Secret{
client.ObjectKeyFromObject(secret1): {
Expand All @@ -298,6 +299,11 @@ var _ = Describe("Collector", Ordered, func() {
client.ObjectKeyFromObject(svc2): {},
client.ObjectKeyFromObject(nilsvc): {},
},
BackendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
{Namespace: "test", Name: "backendTLSPolicy-1"}: {},
{Namespace: "test", Name: "backendTLSPolicy-2"}: {},
{Namespace: "test", Name: "backendTLSPolicy-3"}: {},
},
}

config := &dataplane.Configuration{
Expand Down Expand Up @@ -336,12 +342,14 @@ var _ = Describe("Collector", Ordered, func() {

expData.ClusterNodeCount = 3
expData.NGFResourceCounts = telemetry.NGFResourceCounts{
GatewayCount: 3,
GatewayClassCount: 3,
HTTPRouteCount: 3,
SecretCount: 3,
ServiceCount: 3,
EndpointCount: 4,
GatewayCount: 3,
GatewayClassCount: 3,
HTTPRouteCount: 3,
SecretCount: 3,
ServiceCount: 3,
EndpointCount: 4,
GRPCRouteCount: 2,
BackendTLSPolicyCount: 3,
}
expData.ClusterVersion = "1.29.2"
expData.ClusterPlatform = "kind"
Expand Down Expand Up @@ -567,12 +575,14 @@ var _ = Describe("Collector", Ordered, func() {
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
fakeConfigurationGetter.GetLatestConfigurationReturns(invalidUpstreamsConfig)
expData.NGFResourceCounts = telemetry.NGFResourceCounts{
GatewayCount: 0,
GatewayClassCount: 0,
HTTPRouteCount: 0,
SecretCount: 0,
ServiceCount: 0,
EndpointCount: 0,
GatewayCount: 0,
GatewayClassCount: 0,
HTTPRouteCount: 0,
SecretCount: 0,
ServiceCount: 0,
EndpointCount: 0,
GRPCRouteCount: 0,
BackendTLSPolicyCount: 0,
}

data, err := dataCollector.Collect(ctx)
Expand Down
6 changes: 6 additions & 0 deletions internal/mode/static/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ Each value is either 'true' or 'false' for boolean flags and 'default' or 'user-
/** EndpointCount include the total count of Endpoints(IP:port) across all referenced services. */
long? EndpointCount = null;

/** GRPCRouteCount is the number of relevant GRPCRoutes. */
long? GRPCRouteCount = null;

/** BackendTLSPolicyCount is the number of relevant BackendTLSPolicies. */
long? BackendTLSPolicyCount = null;

/** NGFReplicaCount is the number of replicas of the NGF Pod. */
long? NGFReplicaCount = null;

Expand Down
19 changes: 12 additions & 7 deletions internal/mode/static/telemetry/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ func TestDataAttributes(t *testing.T) {
FlagNames: []string{"test-flag"},
FlagValues: []string{"test-value"},
NGFResourceCounts: NGFResourceCounts{
GatewayCount: 1,
GatewayClassCount: 2,
HTTPRouteCount: 3,
SecretCount: 4,
ServiceCount: 5,
EndpointCount: 6,
GatewayCount: 1,
GatewayClassCount: 2,
HTTPRouteCount: 3,
SecretCount: 4,
ServiceCount: 5,
EndpointCount: 6,
GRPCRouteCount: 7,
BackendTLSPolicyCount: 8,
},
NGFReplicaCount: 3,
}
Expand All @@ -53,13 +55,14 @@ func TestDataAttributes(t *testing.T) {
attribute.Int64("SecretCount", 4),
attribute.Int64("ServiceCount", 5),
attribute.Int64("EndpointCount", 6),
attribute.Int64("GRPCRouteCount", 7),
attribute.Int64("BackendTLSPolicyCount", 8),
attribute.Int64("NGFReplicaCount", 3),
}

result := data.Attributes()

g := NewWithT(t)

g.Expect(result).To(Equal(expected))
}

Expand All @@ -85,6 +88,8 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
attribute.Int64("SecretCount", 0),
attribute.Int64("ServiceCount", 0),
attribute.Int64("EndpointCount", 0),
attribute.Int64("GRPCRouteCount", 0),
attribute.Int64("BackendTLSPolicyCount", 0),
attribute.Int64("NGFReplicaCount", 0),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func (d *NGFResourceCounts) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.Int64("SecretCount", d.SecretCount))
attrs = append(attrs, attribute.Int64("ServiceCount", d.ServiceCount))
attrs = append(attrs, attribute.Int64("EndpointCount", d.EndpointCount))
attrs = append(attrs, attribute.Int64("GRPCRouteCount", d.GRPCRouteCount))
attrs = append(attrs, attribute.Int64("BackendTLSPolicyCount", d.BackendTLSPolicyCount))


return attrs
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 @@ -26,7 +26,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`, `Secrets`, `Services`, 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`, `Secrets`, `Services`, `BackendTLSPolicies`, and `Endpoints`. The data within these resources is **not** collected.

This data is used to identify the following information:

Expand Down
2 changes: 2 additions & 0 deletions tests/suite/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
"SecretCount: Int(0)",
"ServiceCount: Int(0)",
"EndpointCount: Int(0)",
"GRPCRouteCount: Int(0)",
"BackendTLSPolicyCount: Int(0)",
"NGFReplicaCount: Int(1)",
},
)
Expand Down
Loading