-
Notifications
You must be signed in to change notification settings - Fork 435
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
feat: Add Cost Calculation for DigitalOcean Volumes #1190
Merged
mlabouardy
merged 5 commits into
tailwarden:develop
from
bishal7679:feature/add-cost-digitalocean-volume
Nov 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6958325
added cost calculation for digitalocean volumes
bishal7679 1714ad4
updated cost calculation for digitalocean volumes
bishal7679 674789e
updated cost calculation for digitalocean volumes
bishal7679 77d7e87
Update providers/digitalocean/storage/volumes.go
bishal7679 09d25ae
Merge branch 'develop' into feature/add-cost-digitalocean-volume
mlabouardy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ import ( | |
"github.com/tailwarden/komiser/providers" | ||
) | ||
|
||
var hourlyPrice float64 | ||
const createdLayout = "2006-01-02T15:04:05Z" // 2020-07-21T18:37:44Z | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the comment |
||
|
||
func Volumes(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { | ||
resources := make([]models.Resource, 0) | ||
volumes, _, err := client.DigitalOceanClient.Storage.ListVolumes(ctx, &godo.ListVolumeParams{}) | ||
|
@@ -37,13 +40,41 @@ func Volumes(ctx context.Context, client providers.ProviderClient) ([]models.Res | |
} | ||
} | ||
|
||
sizeInGB := volume.SizeGigaBytes | ||
if sizeInGB <= 100 { | ||
hourlyPrice = 0.015 | ||
} | ||
if sizeInGB <= 500 && sizeInGB > 100 { | ||
hourlyPrice = 0.075 | ||
} else { | ||
hourlyPrice = 0.150 | ||
} | ||
bishal7679 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
currentTime := time.Now() | ||
currentMonth := time.Date(currentTime.Year(), currentTime.Month(), 1, 0, 0, 0, 0, time.UTC) | ||
|
||
created, err := time.Parse(createdLayout, volume.CreatedAt.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var duration time.Duration | ||
if created.Before(currentMonth) { | ||
duration = currentTime.Sub(currentMonth) | ||
} else { | ||
duration = currentTime.Sub(created) | ||
} | ||
|
||
monthlyCost := hourlyPrice * float64(duration.Hours()) | ||
|
||
resources = append(resources, models.Resource{ | ||
Provider: "DigitalOcean", | ||
Account: client.Name, | ||
Service: "Volume", | ||
ResourceId: volume.ID, | ||
Region: volume.Region.Name, | ||
Name: volume.Name, | ||
Cost: monthlyCost, | ||
Tags: tags, | ||
FetchedAt: time.Now(), | ||
Link: fmt.Sprintf("https://cloud.digitalocean.com/volumes/%s", volume.ID), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please shift this var definition inside func