Skip to content

Commit

Permalink
Fixed minor changes (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma authored Sep 26, 2023
1 parent 54b0a22 commit cd23b81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ def update_cluster_cost(self):
pyathena_operations = PyAthenaOperations(aws_access_key_id=self.__athena_account_access_key,
aws_secret_access_key=self.__athena_account_secret_key)
response = pyathena_operations.execute_query(query_string=query)
cluster_cost = {item.get('ClusterName'): item.get('UnblendedCost') for item in response}
self.__es_operations.update_elasticsearch_index(index=self.es_cro_index, id=ticket_id,
metadata={
'cluster_cost': cluster_cost,
'timestamp': datetime.utcnow()
})
if response:
cluster_cost = {item.get('ClusterName'): item.get('UnblendedCost') for item in response}
self.__es_operations.update_elasticsearch_index(index=self.es_cro_index, id=ticket_id,
metadata={
'cluster_cost': cluster_cost,
'timestamp': datetime.utcnow()
})

def __prepare_athena_query_for_cluster_cost(self, names: list):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,15 @@ def __upload_cro_report_to_es(self, monitor_data: dict):
"""
upload_data = {}
for ticket_id, instance_data in monitor_data.items():
if not self.__check_value_in_es(tag_key='ticket_id_state', tag_value='in-progress', ticket_id=ticket_id):
if self.__check_value_in_es(tag_key='ticket_id_state', tag_value='in-progress', ticket_id=ticket_id):
ticket_id = ticket_id.split('-')[-1]
user = instance_data[self.ZERO].get('user')
user_project = instance_data[self.ZERO].get('project')
issue_description = self.jira_operations.get_issue_description(ticket_id=ticket_id, state='ANY')
ticket_opened_date = issue_description.get('TicketOpenedDate')
group_by_tag_name = self.COST_EXPLORER_TAGS[self.TICKET_ID_KEY]
user_cost = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id,
requested_date=ticket_opened_date,
extra_filter_key_values={'Project': user_project})
requested_date=ticket_opened_date)
duration = int(instance_data[self.ZERO].get('duration', 0))
user_forecast = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id, requested_date=datetime.utcnow(), extra_filter_key_values={'Project': user_project}, forecast=True, duration=duration)
cost_estimation = float(instance_data[self.ZERO].get('estimated_cost', self.ZERO))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __monitor_instances(self):
cluster_tickets.setdefault(ticket_id, {}).setdefault(cluster_key, {}).setdefault('region_name', []).append(self.__region_name)
cluster_tickets.setdefault(ticket_id, {}).setdefault(cluster_key, {}). \
update({
'cluster_name': self.__ec2_operations.get_tag_value_from_tags(tag_name='api.openshift.com/name', tags=tags),
'ticket_id': ticket_id,
'user_cro': self.__ec2_operations.get_tag_value_from_tags(tag_name='UserCRO', tags=tags),
'user': self.__ec2_operations.get_tag_value_from_tags(tag_name='User', tags=tags),
Expand Down Expand Up @@ -77,7 +76,7 @@ def __monitor_instances(self):
for ticket_id, cluster_data in cluster_tickets.items():
for cluster_id, cluster_values in cluster_data.items():
cluster_values['cluster_name'] = cluster_id.split('/')[-1]
monitored_ticket_ids[ticket_id].append(cluster_values)
monitored_ticket_ids.setdefault(ticket_id, []).append(cluster_values)
return monitored_ticket_ids

@logger_time_stamp
Expand Down

0 comments on commit cd23b81

Please sign in to comment.