Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exoscale tiers to SOS #80

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pkg/exoscale/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
k8s "sigs.k8s.io/controller-runtime/pkg/client"
)

const productIdStorage = "appcat-exoscale-objectstorage-storage"
const productIdStorageTier1 = "appcat-exoscale-objectstorage-storage-tier-1"
const productIdStorageTier2 = "appcat-exoscale-objectstorage-storage-tier-2"
const productIdStorageTier3 = "appcat-exoscale-objectstorage-storage-tier-3"

// ObjectStorage gathers bucket data from exoscale provider and cluster and saves to the database
type ObjectStorage struct {
Expand Down Expand Up @@ -125,7 +127,7 @@ func (o *ObjectStorage) getOdooMeteredBillingRecords(ctx context.Context, sosBuc
}

o := odoo.OdooMeteredBillingRecord{
ProductID: productIdStorage,
ProductID: getProductId(value),
InstanceID: instanceId + "/storage",
ItemDescription: bucketDetail.BucketName,
ItemGroupDescription: itemGroup,
Expand All @@ -147,6 +149,20 @@ func (o *ObjectStorage) getOdooMeteredBillingRecords(ctx context.Context, sosBuc
return aggregatedBuckets, nil
}

// getProductId calculates the tier based on the bucket storage consumption
// For more details https://www.exoscale.com/object-storage/
// Value is passed as GiB
func getProductId(value float64) string {
valueTB := value / 1024
if valueTB < 512 {
return productIdStorageTier1
} else if valueTB > 1024 {
return productIdStorageTier3
} else {
return productIdStorageTier2
}
}

func (o *ObjectStorage) fetchManagedBucketsAndNamespaces(ctx context.Context) ([]BucketDetail, error) {
logger := log.Logger(ctx)
logger.Info("Fetching buckets and namespaces from cluster")
Expand Down
37 changes: 37 additions & 0 deletions pkg/exoscale/objectstorage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package exoscale

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestObjectStorage_getProductId(t *testing.T) {
tests := map[string]struct {
value float64 // in GiB
expectTier string
}{
"given SOS with below 512TiB capacity, we should get the Product Tier 1": {
value: 300.1, // in GiB
expectTier: productIdStorageTier1,
},
"given SOS with above 512 TiB and below 1Pib capacity, we should get the Product Tier 2": {
value: 813000.4, // in GiB
expectTier: productIdStorageTier2,
},
"given SOS with above 1Pib capacity, we should get the Product Tier 3": {
value: 1300345.6, // in GiB
expectTier: productIdStorageTier3,
},
"given SOS with below 0 capacity, we should get the Product Tier 1": {
value: 0, // in GiB
expectTier: productIdStorageTier1,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
tier := getProductId(tc.value)
assert.Equal(t, tc.expectTier, tier)
})
}
}
Loading