Skip to content

Commit

Permalink
Adjust other provider
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Mar 11, 2024
1 parent 011477b commit f23eb67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
return Data{}, fmt.Errorf("failed to collect cluster information: %w", err)
}

nodeCount := len(clusterInfo.Nodes.Items)
nodeCount, err := CollectNodeCount(ctx, c.cfg.K8sClientReader)
if err != nil {
return Data{}, fmt.Errorf("failed to collect node count: %w", err)
}

graphResourceCount, err := collectGraphResourceCount(c.cfg.GraphGetter, c.cfg.ConfigurationGetter)
if err != nil {
Expand Down Expand Up @@ -274,7 +277,6 @@ type clusterInformation struct {
Platform string
Version string
ClusterID string
Nodes v1.NodeList
}

func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (clusterInformation, error) {
Expand All @@ -289,8 +291,6 @@ func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (cl
return clusterInformation{}, errors.New("failed to collect cluster information: NodeList length is zero")
}

clusterInfo.Nodes = nodes

var clusterID string
if clusterID, err = CollectClusterID(ctx, k8sClient); err != nil {
return clusterInformation{}, fmt.Errorf("failed to collect cluster information: %w", err)
Expand Down
12 changes: 6 additions & 6 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ var _ = Describe("Collector", Ordered, func() {
})

When("platform is none of the above", func() {
It("marks the platform as 'other: ' with whatever was in the providerID's providerName", func() {
It("marks the platform as 'other_' with whatever was in the providerID's providerName", func() {
nodes := &v1.NodeList{
Items: []v1.Node{
{
Expand All @@ -562,14 +562,14 @@ var _ = Describe("Collector", Ordered, func() {

k8sClientReader.ListCalls(createListCallsFunc(nodes))
expData.ClusterVersion = "1.29.2"
expData.ClusterPlatform = "other: other-cloud-provider"
expData.ClusterPlatform = "other_other-cloud-provider"

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(expData).To(Equal(data))
})
It("marks the platform as 'other: ' when providerID is empty", func() {
It("marks the platform as 'other' when providerID is empty", func() {
nodes := &v1.NodeList{
Items: []v1.Node{
{
Expand All @@ -587,14 +587,14 @@ var _ = Describe("Collector", Ordered, func() {

k8sClientReader.ListCalls(createListCallsFunc(nodes))
expData.ClusterVersion = "1.29.2"
expData.ClusterPlatform = "other: "
expData.ClusterPlatform = "other"

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(expData).To(Equal(data))
})
It("marks the platform as 'other: ' when providerID is missing '://' separator", func() {
It("marks the platform as 'other' when providerID is missing '://' separator", func() {
nodes := &v1.NodeList{
Items: []v1.Node{
{
Expand All @@ -615,7 +615,7 @@ var _ = Describe("Collector", Ordered, func() {

k8sClientReader.ListCalls(createListCallsFunc(nodes))
expData.ClusterVersion = "1.29.2"
expData.ClusterPlatform = "other: "
expData.ClusterPlatform = "other"

data, err := dataCollector.Collect(ctx)

Expand Down
9 changes: 7 additions & 2 deletions internal/mode/static/telemetry/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
platformK3S = "k3s"
platformOpenShift = "openshift"
platformRancher = "rancher"
platformOther = "other"
)

var multiDistributionPlatformExtractors = []platformExtractor{
Expand Down Expand Up @@ -76,10 +77,14 @@ func getPlatform(node v1.Node, namespaces v1.NamespaceList) string {

var providerName string
if prefix, _, found := strings.Cut(node.Spec.ProviderID, "://"); found {
providerName = prefix
providerName = strings.TrimSpace(prefix)
}

return "other: " + providerName
if providerName == "" {
return platformOther
}

return platformOther + "_" + providerName
}

func openShiftExtractor(state k8sState) (string, bool) {
Expand Down

0 comments on commit f23eb67

Please sign in to comment.