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

DRAFT: Attempt to fix gcp last-of-the-month issue #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.4.16"
__version__ = "4.4.17"

VERSION = __version__.split(".")
1 change: 1 addition & 0 deletions nise/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ def _load_static_report_data(options):
options["start_date"] = min(start_dates)
latest_date = max(end_dates)
last_day_of_month = calendar.monthrange(year=latest_date.year, month=latest_date.month)[1]
# TODO WHY IS THIS HERE?
options["end_date"] = latest_date.replace(day=last_day_of_month, hour=0, minute=0)
options["static_report_data"] = static_report_data

Expand Down
21 changes: 8 additions & 13 deletions nise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def _create_month_list(start_date, end_date):
tzinfo=timezone.utc,
),
}

if current.year == start_date.year and current.month == start_date.month:
# First month start with start_date
month["start"] = start_date.replace(tzinfo=timezone.utc)
Expand Down Expand Up @@ -1059,7 +1060,6 @@ def gcp_create_report(options): # noqa: C901

start_date = options.get("start_date")
end_date = options.get("end_date")

static_report_data = options.get("static_report_data")
resource_level = options.get("gcp_resource_level", False)

Expand Down Expand Up @@ -1153,37 +1153,32 @@ def gcp_create_report(options): # noqa: C901
months = _create_month_list(start_date, end_date)
monthly_files = []
output_files = []

for month in months:
data = []
gen_start_date = month.get("start")
gen_end_date = month.get("end")

for project in projects:
num_gens = len(generators)
ten_percent = int(num_gens * 0.1) if num_gens > 50 else 5
LOG.info(
f"Producing data for {num_gens} generators for start: {gen_start_date} and end: {gen_end_date}."
)
LOG.info(f"Producing data for {num_gens} generators for start: {start_date} and end: {end_date}.")
for count, generator in enumerate(generators):
attributes = generator.get("attributes", {})
if attributes:
start_date = attributes.get("start_date", start_date)
end_date = attributes.get("end_date", end_date)
start_date, end_date = _create_generator_dates_from_yaml(attributes, month)
currency = default_currency(options.get("currency"), attributes.get("currency"))
else:
currency = default_currency(options.get("currency"), None)
if gen_end_date > end_date:
gen_end_date = end_date
attributes["resource_level"] = resource_level

generator_cls = generator.get("generator")
gen = generator_cls(gen_start_date, gen_end_date, currency, project, attributes=attributes)

gen = generator_cls(start_date, end_date, currency, project, attributes=attributes)
for hour in gen.generate_data():
data += [hour]
count += 1
if count % ten_percent == 0:
LOG.info(f"Done with {count} of {num_gens} generators.")

local_file_path, output_file_name = write_gcp_file(gen_start_date, gen_end_date, data, options)
local_file_path, output_file_name = write_gcp_file(start_date, end_date, data, options)
output_files.append(output_file_name)
monthly_files.append(local_file_path)

Expand Down
Loading