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

Fix wrong timeRange for cloudscale.ch bucket metrics #77

Merged
merged 1 commit into from
Jan 23, 2024
Merged
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
19 changes: 11 additions & 8 deletions pkg/cloudscale/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (o *ObjectStorage) GetMetrics(ctx context.Context, billingDate time.Time) (
continue
}
}
records, err := o.createOdooRecord(bucketMetricsData, bd, appuioManaged, salesOrder)
records, err := o.createOdooRecord(bucketMetricsData, bd, appuioManaged, salesOrder, billingDate)
if err != nil {
logger.Error(err, "unable to create Odoo Record", "namespace", bd.Namespace)
continue
Expand All @@ -107,7 +107,7 @@ func (o *ObjectStorage) GetMetrics(ctx context.Context, billingDate time.Time) (
return allRecords, nil
}

func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetricsData, b BucketDetail, appuioManaged bool, salesOrder string) ([]odoo.OdooMeteredBillingRecord, error) {
func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetricsData, b BucketDetail, appuioManaged bool, salesOrder string, billingDate time.Time) ([]odoo.OdooMeteredBillingRecord, error) {
if len(bucketMetricsData.TimeSeries) != 1 {
return nil, fmt.Errorf("there must be exactly one metrics data point, found %d", len(bucketMetricsData.TimeSeries))
}
Expand All @@ -134,6 +134,9 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr

instanceId := fmt.Sprintf("%s/%s", b.Zone, bucketMetricsData.Subject.BucketName)

billingStart := time.Date(billingDate.Year(), billingDate.Month(), billingDate.Day(), 0, 0, 0, 0, time.UTC)
billingEnd := time.Date(billingDate.Year(), billingDate.Month(), billingDate.Day()+1, 0, 0, 0, 0, time.UTC)

return []odoo.OdooMeteredBillingRecord{
{
ProductID: productIdStorage,
Expand All @@ -144,8 +147,8 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr
UnitID: o.uomMapping[units[productIdStorage]],
ConsumedUnits: storageBytesValue,
TimeRange: odoo.TimeRange{
From: bucketMetricsData.TimeSeries[0].Start,
To: bucketMetricsData.TimeSeries[0].End,
From: billingStart,
To: billingEnd,
},
},
{
Expand All @@ -157,8 +160,8 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr
UnitID: o.uomMapping[units[productIdTrafficOut]],
ConsumedUnits: trafficOutValue,
TimeRange: odoo.TimeRange{
From: bucketMetricsData.TimeSeries[0].Start,
To: bucketMetricsData.TimeSeries[0].End,
From: billingStart,
To: billingEnd,
},
},
{
Expand All @@ -170,8 +173,8 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr
UnitID: o.uomMapping[units[productIdQueryRequests]],
ConsumedUnits: queryRequestsValue,
TimeRange: odoo.TimeRange{
From: bucketMetricsData.TimeSeries[0].Start,
To: bucketMetricsData.TimeSeries[0].End,
From: billingStart,
To: billingEnd,
},
},
}, nil
Expand Down