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

Define rosa cluster and graviton type #851

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 9 additions & 1 deletion cloud_governance/policy/aws/monitor/cluster_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def run_policy_operations(self):
else:
running_instances = 1
creation_date = ''
rosa_cluster = True if self.get_tag_name_from_tags(tags=tags, tag_name='red-hat-managed') else False
using_graviton = True if '.g' in instance.get('InstanceType') else False
Copy link
Collaborator

@ebattat ebattat Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graviton_families = ["a1", "t4g", "c6g", "m6g", "r6g", "g5g"]
do u think we need to handle it like this ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer this

if 'master' in name_tag.lower():
creation_date = self.__get_creation_date(instance.get('BlockDeviceMappings', []))
instance_data = f"{instance.get('InstanceId')}, {self.get_tag_name_from_tags(tags=tags, tag_name='Name')}, {instance.get('InstanceType')}, {instance_state}, {running_days}, {launch_time}"
Expand All @@ -63,6 +65,7 @@ def run_policy_operations(self):
cluster_data[cluster_tag]['ClusterState'] = instance_state
cluster_data[cluster_tag]['StoppedDate'] = stopped_date_time
cluster_data[cluster_tag]['Instances'].append(instance_data)
cluster_data[cluster_tag]['InstanceTypes'].append(instance.get('InstanceType'))
cluster_data[cluster_tag]['InstanceCount'] = len(cluster_data[cluster_tag]['Instances'])
cluster_data[cluster_tag]['Stopped'] = int(cluster_data[cluster_tag]['Stopped']) + stopped_instances
cluster_data[cluster_tag]['Running'] = int(cluster_data[cluster_tag]['Running']) + running_instances
Expand All @@ -72,6 +75,7 @@ def run_policy_operations(self):
'ClusterName2': cluster_tag.split('/')[-1].lower(),
'ResourceId': cluster_tag,
'ClusterTag': cluster_tag,
'InstanceTypes': [instance.get('InstanceType')],
'User': self.get_tag_name_from_tags(tags=tags, tag_name='User'),
'RunningDays': running_days,
'RegionName': self._region,
Expand All @@ -80,11 +84,15 @@ def run_policy_operations(self):
'InstanceCount': 1,
'Stopped': stopped_instances,
'Running': running_instances,
'Graviton': using_graviton,
'RosaCluster': rosa_cluster,
'index-id': f'{datetime.datetime.now(datetime.timezone.utc).date()}-{self._cloud_name.lower()}-{self.account.lower()}-{self._region.lower()}-{cluster_tag}',
}
if creation_date:
cluster_data[cluster_tag]['creation_date'] = creation_date
cluster_data[cluster_tag]['ClusterState'] = instance_state
cluster_data[cluster_tag]['StoppedDate'] = stopped_date_time

for cluster in cluster_data.values():
instance_types = cluster['InstanceTypes']
cluster['InstanceTypes'] = [f"{x}: {instance_types.count(x)}" for x in set(instance_types)]
return list(cluster_data.values())