Skip to content

Commit

Permalink
Update telemetry data types from int to int64 (#5185)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-nx authored Feb 29, 2024
1 parent 1fefb7d commit b82c2e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

// NodeCount returns the total number of nodes in the cluster.
// It returns an error if the underlying k8s API client errors.
func (c *Collector) NodeCount(ctx context.Context) (int, error) {
func (c *Collector) NodeCount(ctx context.Context) (int64, error) {
nodes, err := c.Config.K8sClientReader.CoreV1().Nodes().List(ctx, metaV1.ListOptions{})
if err != nil {
return 0, err
}
return len(nodes.Items), nil
return int64(len(nodes.Items)), nil
}

// ClusterID returns the UID of the kube-system namespace representing cluster id.
Expand Down
4 changes: 2 additions & 2 deletions internal/telemetry/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNodeCountInAClusterWithThreeNodes(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := 3
var want int64 = 3
if want != got {
t.Errorf("want %v, got %v", want, got)
}
Expand All @@ -33,7 +33,7 @@ func TestNodeCountInAClusterWithOneNode(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := 1
var want int64 = 1
if want != got {
t.Errorf("want %v, got %v", want, got)
}
Expand Down
18 changes: 7 additions & 11 deletions internal/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,21 @@ func (c *Collector) BuildReport(ctx context.Context) (Data, error) {
var err error

if c.Config.Configurator != nil {
d.NICResourceCounts.VirtualServers, d.NICResourceCounts.VirtualServerRoutes = c.Config.Configurator.GetVirtualServerCounts()
d.NICResourceCounts.TransportServers = c.Config.Configurator.GetTransportServerCounts()
vsCount, vsrCount := c.Config.Configurator.GetVirtualServerCounts()
d.VirtualServers, d.VirtualServerRoutes = int64(vsCount), int64(vsrCount)
d.TransportServers = int64(c.Config.Configurator.GetTransportServerCounts())
}
nc, err := c.NodeCount(ctx)
if err != nil {

if d.NodeCount, err = c.NodeCount(ctx); err != nil {
glog.Errorf("Error collecting telemetry data: Nodes: %v", err)
}
d.NodeCount = nc

cID, err := c.ClusterID(ctx)
if err != nil {
if d.ClusterID, err = c.ClusterID(ctx); err != nil {
glog.Errorf("Error collecting telemetry data: ClusterID: %v", err)
}
d.ClusterID = cID

k8s, err := c.K8sVersion()
if err != nil {
if d.K8sVersion, err = c.K8sVersion(); err != nil {
glog.Errorf("Error collecting telemetry data: K8s Version: %v", err)
}
d.K8sVersion = k8s
return d, err
}
18 changes: 9 additions & 9 deletions internal/telemetry/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func (e *StdoutExporter) Export(_ context.Context, data Data) error {

// Data holds collected telemetry data.
type Data struct {
ProjectMeta ProjectMeta
NICResourceCounts NICResourceCounts
NodeCount int
ClusterID string
K8sVersion string
Arch string
ProjectMeta
NICResourceCounts
NodeCount int64
ClusterID string
K8sVersion string
Arch string
}

// ProjectMeta holds metadata for the project.
Expand All @@ -43,9 +43,9 @@ type ProjectMeta struct {

// NICResourceCounts holds a count of NIC specific resource.
type NICResourceCounts struct {
VirtualServers int
VirtualServerRoutes int
TransportServers int
VirtualServers int64
VirtualServerRoutes int64
TransportServers int64
}

// Attributes is a placeholder function.
Expand Down

0 comments on commit b82c2e1

Please sign in to comment.