-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added reusable GenerateDesc function across all providers (#343)
Implement a Uniform Approach for Defining Metric Descriptions **Description:** - This PR refines the definition of metric descriptions in the `cloudcost-exporter` project by implementing a consistent and uniform approach. - Added new constants and generic reusable method in utils. - Changed defining metric across all available providers - closes #222
- Loading branch information
1 parent
1bee25b
commit 414f655
Showing
5 changed files
with
104 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package utils | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
const ( | ||
HoursInMonth = 24.35 * 30 // 24.35 is the average amount of hours in a day over a year | ||
HoursInMonth = 24.35 * 30 // 24.35 is the average amount of hours in a day over a year | ||
InstanceCPUCostSuffix = "instance_cpu_usd_per_core_hour" | ||
InstanceMemoryCostSuffix = "instance_memory_usd_per_gib_hour" | ||
InstanceTotalCostSuffix = "instance_total_usd_per_hour" | ||
PersistentVolumeCostSuffix = "persistent_volume_usd_per_hour" | ||
) | ||
|
||
func GenerateDesc(prefix, subsystem, suffix, description string, labels []string) *prometheus.Desc { | ||
return prometheus.NewDesc( | ||
prometheus.BuildFQName(prefix, subsystem, suffix), | ||
description, | ||
labels, | ||
nil, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package utils | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func TestGenerateDesc(t *testing.T) { | ||
prefix := "test_prefix" | ||
subsystem := "test_subsystem" | ||
suffix := "test_suffix" | ||
description := "This is a test description" | ||
labels := []string{"label1", "label2"} | ||
|
||
desc := GenerateDesc(prefix, subsystem, suffix, description, labels) | ||
|
||
// Expected values | ||
expectedFQName := prometheus.BuildFQName(prefix, subsystem, suffix) | ||
|
||
if !strings.Contains(desc.String(), expectedFQName) { | ||
t.Errorf("Expected FQName %s in desc, but got %s", expectedFQName, desc.String()) | ||
} | ||
|
||
if !strings.Contains(desc.String(), description) { | ||
t.Errorf("Expected description %s in desc, but got %s", description, desc.String()) | ||
} | ||
|
||
for _, label := range labels { | ||
if !strings.Contains(desc.String(), label) { | ||
t.Errorf("Expected label %s in desc, but got %s", label, desc.String()) | ||
} | ||
} | ||
} |