Skip to content

Commit

Permalink
Merge pull request #6 from meckstmd/fix-issue-005
Browse files Browse the repository at this point in the history
Filter out entries with no product_region or product_instance.
  • Loading branch information
meckstmd committed Jul 31, 2019
2 parents 9c3251f + a9db654 commit 8328068
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ariel/__init__.py
Expand Up @@ -2,7 +2,7 @@
# Licensed under the terms of the Apache License, Version 2.0. See LICENSE file for terms.
__all__ = ['generate_reports', 'get_account_instance_summary', 'get_account_names', 'get_ec2_pricing', 'get_locations',
'get_reserved_instances', 'get_unlimited_summary', 'get_unused_box_summary', 'utils', 'LOGGER']
__version__='2.0.2'
__version__='2.0.3'

import logging
LOG_LEVEL = logging.INFO
Expand Down
9 changes: 9 additions & 0 deletions ariel/get_unlimited_summary.py
Expand Up @@ -59,6 +59,14 @@ def load(config):
starttime = endtime - datetime.timedelta(days=days)

# Download Instance and RI usage
# meckstmd: 07/30/2019 - Something must have changed with the way AWS is exposing CPU Credits.
# There is a line_item_line_item_type column of Tax for each account which has CPU Credits which
# does not have a product_region or product_instance. Because these fields are empty, Ariel
# fails when trying to insert this report data into the unlimited_usage DB table because it does
# not allow nulls. The line_item_line_item_type column of Usage in this report has the per-instance
# CPU credits for unlimited and does have product_region and product_instance. I am guessing the
# Tax one was just added to this report and that is what broke Ariel.
# See https://github.com/yahoo/ariel/issues/5
query = ' '.join((""
+ "SELECT line_item_usage_account_id AS accountid ,"
" product_region AS region, "
Expand All @@ -69,6 +77,7 @@ def load(config):
+ " WHERE line_item_usage_type like '%CPUCredits:%' "
+ " AND line_item_usage_start_date >= cast('{}' as timestamp) ".format(starttime.isoformat(' '))
+ " AND line_item_usage_start_date < cast('{}' as timestamp) ".format(endtime.isoformat(' '))
+ " AND product_region <> '' AND product_instance <> ''"
+ " GROUP BY line_item_usage_account_id, product_region, lower(product_instance) "
+ " ORDER BY line_item_usage_account_id, product_region, lower(product_instance) "
).split())
Expand Down

0 comments on commit 8328068

Please sign in to comment.