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

Migrating GCE Billing to BigQuery based Bill Calculations #505

Merged
merged 2 commits into from
Oct 11, 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
31 changes: 13 additions & 18 deletions src/decisionengine_modules/GCE/sources/GCEBillingInfo.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
# SPDX-FileCopyrightText: 2017 Fermi Research Alliance, LLC
# SPDX-License-Identifier: Apache-2.0

# standard library imports
import pandas as pd

# related third party imports
from bill_calculator_hep.GCEBillAnalysis import GCEBillCalculator

# local application/library specific imports
from decisionengine.framework.modules import Source
from decisionengine.framework.modules.Source import Parameter


@Source.supports_config(
Parameter("projectId", type=str),
Parameter("credentialsProfileName", type=str, comment="not currently used"),
Parameter("accountNumber", type=int, comment="not currently used"),
Parameter("lastKnownBillDate", type=str, comment="in the form '%m/%d/%y %H:%M'"),
Parameter("balanceAtData", type=float, comment="in dollars"),
Parameter("balanceAtDate", type=float, comment="in dollars"),
Parameter("applyDiscount", type=bool, comment="DLT discount does not apply to credits"),
Parameter("botoConfig", comment="not currently used"),
Parameter("localFileDir", type=dir, comment="location for downloaded billing files"),
Parameter("sumToDate", type=str, comment="in the form '%m/%d/%y %H:%M'"),
)
@Source.produces(GCE_Billing_Info=pd.DataFrame)
class GCEBillingInfo(Source.Source):
def __init__(self, config):
super().__init__(config)
# Load configuration "constants"
self.projectId = config.get("projectId")
self.credentialsProfileName = config.get("credentialsProfileName") # NOT CURRENTLY USED
self.accountNumber = config.get("accountNumber") # NOT CURRENTLY USED
self.lastKnownBillDate = config.get("lastKnownBillDate") # '%m/%d/%y %H:%M'
self.balanceAtDate = config.get("balanceAtDate") # $
# Onix does not provide discounts
self.applyDiscount = config.get("applyDiscount")
self.botoConfig = config.get("botoConfig") # BOTO_CONFIG env
# location for downloaded billing files
self.localFileDir = config.get("localFileDir")
self.sumToDate = config.get("sumToDate")

def acquire(self):
"""
Expand All @@ -44,26 +40,25 @@ def acquire(self):
self.logger.debug("in GCEBillingInfo acquire")
constantsDict = {
"projectId": self.projectId,
"credentialsProfileName": self.credentialsProfileName,
"accountNumber": self.accountNumber,
"bucketBillingName": "billing-" + str(self.projectId),
"lastKnownBillDate": self.lastKnownBillDate,
"balanceAtDate": self.balanceAtDate,
"applyDiscount": self.applyDiscount,
"sumToDate": self.sumToDate,
}
globalConf = {"graphite_host": "dummy", "graphite_context_billing": "dummy", "outputPath": self.localFileDir}
globalConf = {"graphite_host": "dummy", "graphite_context_billing": "dummy"}
bill_summary = pd.DataFrame()
try:
calculator = GCEBillCalculator(None, globalConf, constantsDict, self.logger)

lastStartDateBilledConsideredDatetime, CorrectedBillSummaryDict = calculator.CalculateBill()
bill_summary = calculator.CalculateBill()

self.logger.info("Calculated corrected bill summary for google")
self.logger.info(CorrectedBillSummaryDict)
self.logger.info("Calculated corrected bill summary for Google (using BigQuery)")
self.logger.debug(bill_summary)

except Exception:
self.logger.exception("Exception in GCEBillingInfo call to acquire")

return {"GCE_Billing_Info": pd.DataFrame([CorrectedBillSummaryDict])}
return {"GCE_Billing_Info": bill_summary}


Source.describe(GCEBillingInfo)
Loading