zalando-zmon / zmon-aws-agent

AWS API crawler to auto discover running services in your account
Apache License 2.0
11 stars 11 forks source link

PG cluster discovery #119

Closed avaczi closed 6 years ago

avaczi commented 7 years ago

Looks for Spilo clusters by investigating ASGs, instances and EIPs. Complete with tests.

codecov[bot] commented 7 years ago

Codecov Report

Merging #119 into master will increase coverage by 0.87%. The diff coverage is 84.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #119      +/-   ##
==========================================
+ Coverage   76.34%   77.22%   +0.87%     
==========================================
  Files           6        6              
  Lines         651      720      +69     
==========================================
+ Hits          497      556      +59     
- Misses        154      164      +10
Impacted Files Coverage Δ
zmon_aws_agent/main.py 34.01% <62.5%> (-0.47%) :arrow_down:
zmon_aws_agent/postgresql.py 79.78% <86.95%> (+20.52%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3c4e9af...9dedbf6. Read the comment docs.

CyberDem0n commented 7 years ago

I am afraid such approach of finding elastic ip associated with the cfn/asg will not work reliable enough. It doesn't protect us from the case when eip is allocated, but have never been assigned to any of the instances?

We should use UserData from Launch Configuration instead:

import base64
import yaml

lc_paginator = asg.get_paginator('describe_launch_configurations')
all_configurations = lc_paginator.paginate().build_full_result()['LaunchConfigurations']
launch_configuration = all_configurations[11]  # find the matching one
user_data = base64.decodebytes(launch_configuration['UserData'].encode('utf-8')).decode('utf-8')
user_data = yaml.safe_load(user_data)
eip_allocation = user_data['environment']['EIP_ALLOCATION']

it will give you something like eipalloc-12345678

avaczi commented 7 years ago

I think the way we match the returned EIPs using the instance IDs should be safe. I noticed there are EIPs without InstanceId, but those are excluded by the logic.

CyberDem0n commented 7 years ago

I noticed there are EIPs without InstanceId, but those are excluded by the logic.

This is exactly a problem. In this case you can't figure out which cluster EIP belongs to, because it is not associated with the instance. There is no other way to get this information rather than get it from UserData of LaunchConfiguration used by AutoScalingGroup.

codecov-io commented 7 years ago

Codecov Report

Merging #119 into master will increase coverage by 2.27%. The diff coverage is 93.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #119      +/-   ##
==========================================
+ Coverage   76.34%   78.62%   +2.27%     
==========================================
  Files           6        6              
  Lines         651      725      +74     
==========================================
+ Hits          497      570      +73     
- Misses        154      155       +1
Impacted Files Coverage Δ
zmon_aws_agent/aws.py 90.66% <ø> (+0.64%) :arrow_up:
zmon_aws_agent/main.py 34.01% <0%> (-0.47%) :arrow_down:
zmon_aws_agent/postgresql.py 87% <96%> (+27.74%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3c4e9af...85eaf26. Read the comment docs.

avaczi commented 7 years ago

:+1:

avaczi commented 7 years ago

:+1:

avaczi commented 7 years ago
avaczi commented 6 years ago

:+1:

mohabusama commented 6 years ago

👍