Skip to content

Commit

Permalink
Update sub-item template
Browse files Browse the repository at this point in the history
Very hacky for now. I will introduce a display name upstream and look
for an alternative for the special whitespace unicode
  • Loading branch information
glrf committed May 9, 2022
1 parent 0e4c020 commit 369b83e
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 21 deletions.
6 changes: 3 additions & 3 deletions description_templates/_usage.gotmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- define "_usage" -}}
Qty: {{.Quantity | printf "%.2f"}} {{.Unit}}-Minutes
Average Usage: {{.QuantityAvg | perMinute | printf "%.2f"}} {{.Unit}} / Minute
{{ range .SubItems -}}
Average {{.Description}}: {{.QuantityAvg | perMinute | printf "%.2f"}} {{.Unit}} / Minute
{{ end -}}
{{- range .SubItems }}
 {{ . | displayName }}: {{.QuantityAvg | perMinute | printf "%.2f"}} {{.Unit}} / Minute
{{- end }}
Unit Price: CHF {{.PricePerUnit | printf "%.10f"}} / {{.Unit}} / Minute
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Service Type LoadBalancer

Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Service Type LoadBalancer

Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute

Services of type LoadBalancer are not supported on "Exoscale - CH-GVA-2 0".
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Compute

Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Compute

Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Persistent Storage
Storage Type: RWO [bulk]
Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Persistent Storage
Storage Type: RWX [cephfs-fspool-cluster]
Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Persistent Storage
Storage Type: RWO [ssd]
Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Persistent Storage
Storage Type: RWX [cephfs-fspool-cluster]
Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Persistent Storage
Storage Type: RWO [rbd-storagepool-cluster]
Qty: 87955674.09 UNIT-Minutes
Average Usage: 7.61 UNIT / Minute
Average Memory requests: 0.70 TPS / Minute
Average CPU requests in memory request equivalent: 0.70 TPS / Minute
 default_sub_query_1: 0.70 TPS / Minute
 default_sub_query_2: 0.70 TPS / Minute
Unit Price: CHF 0.0000007460 / UNIT / Minute
3 changes: 3 additions & 0 deletions description_templates/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestGenerateGolden(t *testing.T) {

baseItem := invoice.Item{
Description: "Long form query description",
QueryName: "default_query",
ProductRef: invoice.ProductRef{
Target: "1919",
Source: "SET ME",
Expand All @@ -62,6 +63,7 @@ func TestGenerateGolden(t *testing.T) {
SubItems: []invoice.SubItem{
{
Description: "Memory requests",
QueryName: "default_sub_query_1",
Quantity: 34923234.04433424,
QuantityMin: 2.251,
QuantityAvg: 42.2,
Expand All @@ -70,6 +72,7 @@ func TestGenerateGolden(t *testing.T) {
},
{
Description: "CPU requests in memory request equivalent",
QueryName: "default_sub_query_2",
Quantity: 34923234.04433424,
QuantityMin: 2.251,
QuantityAvg: 42.2,
Expand Down
12 changes: 12 additions & 0 deletions invoice/desctmpl/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ import (
"github.com/appuio/appuio-cloud-reporting/pkg/invoice"
)

var displayNames = map[string]string{
"appuio_cloud_memory_subquery_memory_request": "Memory Requests",
"appuio_cloud_memory_subquery_cpu_request": "CPU Requests",
}

var rootTemplate = template.New("root").Funcs(template.FuncMap{
"perMinute": func(v float64) float64 { return v / float64(60) },
"displayName": func(item invoice.SubItem) string {
n, ok := displayNames[item.QueryName]
if ok {
return n
}
return item.QueryName
},
}).Funcs(sprig.TxtFuncMap())

// ItemDescriptionTemplateRenderer renders item descriptions using the golang template engine.
Expand Down

0 comments on commit 369b83e

Please sign in to comment.