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

#584 Added Support for SSM based Instance #1159

Merged
merged 18 commits into from
Jan 24, 2024
Merged

Conversation

Horiodino
Copy link
Contributor

@Horiodino Horiodino commented Nov 3, 2023

Problem

Support AWS Systems Manager managed-instane #584

Changes Made

Notes

this hasn't been tested yet , i opened this pull request to view the code for the reviewers to know what i did
and if theirs any problem please correct me .

Checklist

  • Code follows the contributing guidelines
  • Changes have been thoroughly tested
  • Documentation has been updated, if necessary
  • Any dependencies have been added to the project, if necessary

Reviewers

@[username of the reviewer]

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.
I've a few comments regarding the changes

  • The changes belong to a new file in systemsmanager folder
  • Take inspiration from how otherFetchDataFunctions are written
  • don't use "." imports

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

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

Drop the cost calculation as we'll be going with AWS cost explorer API integration for AWS provider

@Horiodino
Copy link
Contributor Author

Drop the cost calculation as we'll be going with AWS cost explorer API integration for AWS provider

yep i removed the cost monitoring and will be doing test on it . any suggestion where i should i call the function from

@Horiodino
Copy link
Contributor Author

almost done with testing and going to do some changes 👍

@Horiodino
Copy link
Contributor Author

Horiodino commented Nov 24, 2023

@Azanul ```
[
{
"id": ,
"resourceId": "i-0b360c042863610a2",
"provider": "AWS",
"account": "my-account",
"accountId": "my-account-id",
"service": "EC2",
"region": "ap-south-1",
"name": "t2.micro",
"createdAt": "2023-11-24T02:22:33Z",
"fetchedAt": "2023-11-24T09:45:21.242287061+05:30",
"cost": 0,
"metadata": null,
"relations": null,
"tags": [
{
"key": "Name",
"value": "test"
}
],
"link": "https://ap-south-1.console.aws.amazon.com/ec2/home?region=ap-south-1#InstanceDetails:instanceId=i-0b360c042863610a2",
"Value": ""
}
]

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

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

failing CLI

Region: client.AWSClient.Region,
ResourceId: *ec2instance.InstanceId,
Name: *ec2instance.Name,
Cost: 0.0, // No cost calculation in this version
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Cost: 0.0, // No cost calculation in this version

Name: *ec2instance.Name,
Cost: 0.0, // No cost calculation in this version
CreatedAt: *ec2instance.RegistrationDate,
Tags: nil, // No tags in this version
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Tags: nil, // No tags in this version

@Horiodino
Copy link
Contributor Author

failing CLI

its because i didn't committed latest changes , i am asking what should be in the

"id": 

once the id is populated i will push the commits

@Azanul
Copy link
Collaborator

Azanul commented Nov 24, 2023

failing CLI

its because i didn't committed latest changes , i am asking what should be in the

"id": 

once the id is populated i will push the commits

I think that's auto. It'll be filled by the respective DB.

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

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

  • I see too many API requests being sent. Could you move client creation to the main function and create helper functions to fetch respective data for all instances at once instead of making an API call for each instance.
  • refer to other implementations for error handling

@Horiodino
Copy link
Contributor Author

  • I see too many API requests being sent. Could you move client creation to the main function and create helper functions to fetch respective data for all instances at once instead of making an API call for each instance.
  • refer to other implementations for error handling

Ok

@Horiodino Horiodino requested a review from jakepage91 as a code owner December 8, 2023 17:47
@Horiodino
Copy link
Contributor Author

hey @Azanul now i am fetching the all instance info at once which reduce the API calls , and now just few API calls , i have also tested it

[
  {
    "id": 0,
    "resourceId": "i-037adb5a71eb0be30",
    "provider": "AWS",
    "account": "my-account :) ",
    "accountId": "my-id :) ",
    "service": "EC2",
    "region": "ap-south-1",
    "name": "t2.micro",
    "createdAt": "2023-12-08T17:32:49Z",
    "fetchedAt": "2023-12-08T23:15:30.813538473+05:30",
    "cost": 0,
    "metadata": null,
    "relations": null,
    "tags": [
      {
        "key": "Name",
        "value": "komi"
      }
    ],
    "link": "https://ap-south-1.console.aws.amazon.com/ec2/home?region=ap-south-1#InstanceDetails:instanceId=i-037adb5a71eb0be30",
    "Value": ""
  }
]

@Horiodino Horiodino requested a review from Azanul December 19, 2023 04:56
ec2Client := ec2.NewFromConfig(*client.AWSClient)

ssmOutput, err := ssmClient.DescribeInstanceInformation(ctx, &ssm.DescribeInstanceInformationInput{
MaxResults: aws.Int32(50),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason we are keeping this parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it tells what instances are managed ec2 instances, and later we are using describe because it provides more info regarding the instance, and the parameter is set to MaxResults: aws.Int32(50) is maximum value we can use (Defined by aws). another reason is making as less as possible call, thats why the MaxResults: aws.Int32(50)

Copy link
Collaborator

Choose a reason for hiding this comment

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

In case of SSM managing more instances > 50 we would still need those too as we want users to know what resources in what quantity are active

Copy link
Contributor Author

@Horiodino Horiodino Jan 7, 2024

Choose a reason for hiding this comment

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

I didn't know that we have pagination token, let me add it so it will fetch all ssm intance even its >50 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AvineshTripathi thanks for pointing it out , i removed the MaxResults because if the ssm-instance is less than 5 it will through error now just using pagination token 👍 .

MaxResults: aws.Int32(50),
})
if err != nil {
log.Fatal(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
log.Fatal(err)
return resources, err

InstanceIds: instanceIds,
})
if err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, err
return resources, err

some nits for readability


account, accountID, err := fetchID(ctx, client)
if err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, err
return resources, err

Provider: "AWS",
Account: account,
AccountId: accountID,
Service: "EC2",
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we call this SSM Instance ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, thanks for noticing it out 😃

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please donot add - and use space that is how we have done for other resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Collaborator

@AvineshTripathi AvineshTripathi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@Azanul Azanul left a comment

Choose a reason for hiding this comment

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

Please fix the failing CI. You need to call getManagedEc2. Check out other implementations.

@Horiodino Horiodino requested a review from Azanul January 24, 2024 04:40
@Azanul
Copy link
Collaborator

Azanul commented Jan 24, 2024

@Horiodino Still failing

@Horiodino
Copy link
Contributor Author

@Horiodino Still failing

in aws.go on line 103 i have added

@Horiodino
Copy link
Contributor Author

o i added it but i forgot to commit it , sorry

@Azanul Azanul merged commit 2a23700 into tailwarden:develop Jan 24, 2024
3 checks passed
Azanul added a commit that referenced this pull request Jan 31, 2024
* enhancement: added ssm based instance

* enhancement: added cost-monitoring on smm based instances

* Refactor: Removed dot imports and organized changes into the systemsmanager folder.

* enhancement: Removed the cost calculation logic and related code

* implemented suggested changes

* Reduced API Requests & bulk data fetching for instances.

* added suggested changes

* added  pagination token for fetching ssm-instance-info

* fixed the failing CI

* Update providers/aws/systemsmanager/managedinstances.go

Co-authored-by: Azanul Haque <[email protected]>

---------

Co-authored-by: Azanul Haque <[email protected]>
Co-authored-by: LABOUARDY Mohamed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants