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

Redesign returned results by the API #16

Closed
ifraixedes opened this issue Jan 26, 2018 · 1 comment · Fixed by #26
Closed

Redesign returned results by the API #16

ifraixedes opened this issue Jan 26, 2018 · 1 comment · Fixed by #26
Assignees

Comments

@ifraixedes
Copy link
Contributor

Although the goal of the library is

It currently provides simplicity - one package vs multitude in AWS - as well as multi-region management - all calls are done for each selected region(s). Region's parameter also supports globbing, thus allowing to fetch data from all eu with: 'eu-' or all eu-west with 'eu-west-'

I would like to make a proposal based on the results (on successful calls) written below, which has been got using only one of the methods of the AWSReader implementation, specifically the GetInstances

Using one only wildcard for specifying the regions "eu-*" which resolves 4 regions for now if the AWS return 0 results on all the regions, the list of instances received ([]*ec2.DescribeInstancesOutput) is

[{

} {

} {

} {

}]

which is 4 elements on such array, which are the number of regions which has been requested and on another call which return results, you get something like this (some data has been removed by placeholders)

[{

} {

} {
  Reservations: [
    {
      Instances: [{
          AmiLaunchIndex: 0,
          Architecture: "x86_64",
          BlockDeviceMappings: [{
              DeviceName: "/dev/xvda",
              Ebs: {
                AttachTime: YYY-MM-DD 15:08:43 +0000 UTC,
                DeleteOnTermination: false,
                Status: "attached",
                VolumeId: "vol-XXXXXX"
              }
            }],
          ClientToken: "",
          EbsOptimized: false,
          Hypervisor: "xen",
          IamInstanceProfile: {
            Arn: "arn:aws:iam::XXXXXXXXXX:some/some",
            Id: "XXXXXXXXXXXXXXXXXXX"
          },
          ImageId: "ami-XXXXXXXX",
          InstanceId: "i-XXXXXXXX",
          InstanceType: "t2.micro",
          KeyName: "some-name",
          LaunchTime: YYY-MM-DD 15:08:43 +0000 UTC,
          Monitoring: {
            State: "disabled"
          },
          NetworkInterfaces: [{
              Association: {
                IpOwnerId: "XXXXXXXX",
                PublicDnsName: "xxxxxxxxxxxxx.eu-west-1.compute.amazonaws.com",
                PublicIp: "xx.xx.xx.xxx"
              },
              Attachment: {
                AttachTime: YYY-MM-DD 14:16:40 +0000 UTC,
                AttachmentId: "eni-attach-xxxxxx",
                DeleteOnTermination: true,
                DeviceIndex: 0,
                Status: "attached"
              },
              Description: "",
              Groups: [{
                  GroupId: "sg-xxxxxx",
                  GroupName: "some-group"
                },{
                  GroupId: "sg-xxxxx",
                  GroupName: "other-group"
                }],
              MacAddress: "xx:xx:xx:xx:xx:xx",
              NetworkInterfaceId: "eni-xxxxxx",
              OwnerId: "000000000000",
              PrivateDnsName: "ip-xx-xx-xx-xx.eu-west-1.compute.internal",
              PrivateIpAddress: "xx.xx.x.xx",
              PrivateIpAddresses: [{
                  Association: {
                    IpOwnerId: "00000000000",
                    PublicDnsName: "ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com",
                    PublicIp: "xx.xx.xx.xx"
                  },
                  Primary: true,
                  PrivateDnsName: "ip-xx-xx-x-xx.eu-west-1.compute.internal",
                  PrivateIpAddress: "xx.xx.x.xx"
                }],
              SourceDestCheck: true,
              Status: "in-use",
              SubnetId: "subnet-xxxxxx",
              VpcId: "vpc-xxxxx"
            }],
          Placement: {
            AvailabilityZone: "eu-west-1a",
            GroupName: "",
            Tenancy: "default"
          },
          PrivateDnsName: "ip-xx-xx-x-xx.eu-west-1.compute.internal",
          PrivateIpAddress: "xx.xx.x.xx",
          PublicDnsName: "ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com",
          PublicIpAddress: "xx.xx.xx.xx",
          RootDeviceName: "/dev/xvda",
          RootDeviceType: "ebs",
          SecurityGroups: [{
              GroupId: "sg-xxxx",
              GroupName: "some-group"
            },{
              GroupId: "sg-xxxx",
              GroupName: "another-group"
            }],
          SourceDestCheck: true,
          State: {
            Code: 16,
            Name: "running"
          },
          StateTransitionReason: "",
          SubnetId: "subnet-xxx",
          Tags: [
            {
              Key: "client",
              Value: "xxxxxx"
            },
            {
              Key: "Name",
              Value: "some-name"
            },
            {
              Key: "env",
              Value: "some-env"
            },
            {
              Key: "project",
              Value: "some-project"
            },
            {
              Key: "role",
              Value: "some-role"
            }
          ],
          VirtualizationType: "hvm",
          VpcId: "vpc-xxxxx"
        }],
      OwnerId: "0000000000",
      ReservationId: "r-xxxxxx"
    },
    {
}]

My proposal will be to return a map of such types rather than a slice, where each key of the slice is the region, other possibility would be to have a custom type which allow to retrieve the results for each type, although we may reduce the map allocations, I don't think that we could improve a lot the performance and probably we won't improve it at the first instance, so a map, looks the simplest and easiest approach.

Having this replacement, it will be possible to know to which region the resources information pertains, otherwise, it isn't possible to figure out to which region the pertains.

A further improvement, but I would need to do a deeper analysis on each returned type, if if we could simplify some results, for example in the shown function call, the Reservations filed which contains values of the Reservation type, looks that only the Instances filed will be filled, so we could move them one level up and remove the Reservation type.

What do you think?

@xlr-8
Copy link
Contributor

xlr-8 commented Jan 29, 2018

Good idea, that would indeed clarify a bit things when using many regions or varied regions (US, EU, etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants