-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add number of NIC replicas to telemetry data #5245
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a test with this branch using Daemonset as the deployment kind.
In this case, Replicas is 0 since we don't have any ReplicaSets to pull from.
So we will need some way to know if NIC is deployed as a Daemonset or a Deployment for this.
Exported telemetry data: {Data:{ProjectName:NIC ProjectVersion:3.5.0-SNAPSHOT ProjectArchitecture:amd64 ClusterID:a5419913-6bca-47b0-b7b8-e6f28ff5a1be ClusterVersion:v1.27.4+k3s1 ClusterPlatform:k3s InstallationID: ClusterNodeCount:1} NICResourceCounts:{VirtualServers:1 VirtualServerRoutes:0 TransportServers:0 Replicas:0}}
One approach we can take is to check the CurrentNumberScheduled field for a Daemonset
Here is a code snippet of what I tried:
// ReplicaCount returns a number of running NIC replicas.
func (c *Collector) ReplicaCount(ctx context.Context) (int, error) {
var rs *appsV1.ReplicaSet
var ds *appsV1.DaemonSet
var replicas int
pod, err := c.Config.K8sClientReader.CoreV1().Pods(c.Config.PodNSName.Namespace).Get(ctx, c.Config.PodNSName.Name, metaV1.GetOptions{})
if err != nil {
return 0, err
}
podRef := pod.GetOwnerReferences()
if len(podRef) != 1 {
return 0, fmt.Errorf("expected pod owner reference to be 1, got %d", len(podRef))
}
// Switch based on the owner reference
switch podRef[0].Kind {
case "ReplicaSet":
rs, err = c.Config.K8sClientReader.AppsV1().ReplicaSets(c.Config.PodNSName.Namespace).Get(ctx, podRef[0].Name, metaV1.GetOptions{})
if err != nil {
return 0, err
}
replicas = int(*rs.Spec.Replicas)
case "DaemonSet":
ds, err = c.Config.K8sClientReader.AppsV1().DaemonSets(c.Config.PodNSName.Namespace).Get(ctx, podRef[0].Name, metaV1.GetOptions{})
if err != nil {
return 0, err
}
replicas = int(ds.Status.CurrentNumberScheduled)
default:
return 0, fmt.Errorf("expected pod owner reference to be either ReplicaSet or DaemonSet, got %s", pod.OwnerReferences[0].Kind)
}
return replicas, nil
}
If we do go with this approach, we will need to add more permissions to our RBAC:
E0313 18:44:02.647830 1 collector.go:94] Error collecting telemetry data: daemonsets.apps "test-nginx-ingress-controller" is forbidden: User "system:serviceaccount:default:test-nginx-ingress" cannot get resource "daemonsets" in API group "apps" in the namespace "default"
NIC logs on multinode cluster, I0313 20:43:27.718603 1 collector.go:91] Collecting telemetry data
I0313 20:43:27.732759 1 collector.go:119] Exported telemetry data: {Data:{ProjectName:NIC ProjectVersion:3.5.0-SNAPSHOT ProjectArchitecture:amd64 ClusterID:2bbabd21-3a0f-48cd-9e02-eb3f1fa2febd ClusterVersion:v1.29.2 ClusterPlatform:kind InstallationID: ClusterNodeCount:3} NICResourceCounts:{VirtualServers:0 VirtualServerRoutes:0 TransportServers:0 Replicas:2}} |
Thanks for catching this @shaun-nx ! Added DaemonSet to the telemetry. |
Proposed changes
This PR adds NIC
replica count
information to the telemetry data.commands
NIC log:
Checklist
Before creating a PR, run through this checklist and mark each as complete.