瀏覽代碼

removing dedup log and logging information only at the end of the loop as well as listing cluster name and disk name in the log

Signed-off-by: Alan Rodrigues <alanr5691@yahoo.com>
Alan Rodrigues 3 年之前
父節點
當前提交
e44a7ab3e9
共有 1 個文件被更改,包括 11 次插入1 次删除
  1. 11 1
      pkg/costmodel/cluster.go

+ 11 - 1
pkg/costmodel/cluster.go

@@ -7,6 +7,7 @@ import (
 
 	"github.com/opencost/opencost/pkg/kubecost"
 	"github.com/opencost/opencost/pkg/util/timeutil"
+	"golang.org/x/exp/slices"
 
 	"github.com/opencost/opencost/pkg/cloud"
 	"github.com/opencost/opencost/pkg/env"
@@ -305,6 +306,7 @@ func ClusterDisks(client prometheus.Client, provider cloud.Provider, start, end
 		diskMap[key].Minutes = mins
 	}
 
+	var unTracedDiskLogData []DiskIdentifier
 	//Iterating through Persistent Volume given by custom metrics kubecost_pv_info and assign the storage class if known and __unknown__ if not populated.
 	for _, result := range resPVStorageClass {
 		cluster, err := result.GetString(env.GetPromClusterLabel())
@@ -316,7 +318,9 @@ func ClusterDisks(client prometheus.Client, provider cloud.Provider, start, end
 
 		key := DiskIdentifier{cluster, name}
 		if _, ok := diskMap[key]; !ok {
-			log.DedupedWarningf(5, "ClusterDisks: Storage class information for unidentified disk or disk deleted from analysis")
+			if !slices.Contains(unTracedDiskLogData, key) {
+				unTracedDiskLogData = append(unTracedDiskLogData, key)
+			}
 			continue
 		}
 
@@ -333,6 +337,12 @@ func ClusterDisks(client prometheus.Client, provider cloud.Provider, start, end
 		}
 	}
 
+	// Logging the unidentified disk information outside the loop
+
+	for _, unIdentifiedDisk := range unTracedDiskLogData {
+		log.Warnf("ClusterDisks: Cluster %s has Storage Class information for unidentified disk %s or disk deleted from analysis", unIdentifiedDisk.Cluster, unIdentifiedDisk.Name)
+	}
+
 	for _, disk := range diskMap {
 		// Apply all remaining RAM to Idle
 		disk.Breakdown.Idle = 1.0 - (disk.Breakdown.System + disk.Breakdown.Other + disk.Breakdown.User)