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

Serve metrics under a dedicated port #48

Merged
merged 5 commits into from
Mar 7, 2018
Merged
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
23 changes: 20 additions & 3 deletions etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EtcdMember:
API_VERSION = '/v2/'
DEFAULT_CLIENT_PORT = 2379
DEFAULT_PEER_PORT = 2380
DEFAULT_METRICS_PORT = 2381
AG_TAG = 'aws:autoscaling:groupName'
CF_TAG = 'aws:cloudformation:stack-name'

Expand All @@ -56,6 +57,7 @@ def __init__(self, arg, region=None):

self.client_port = self.DEFAULT_CLIENT_PORT
self.peer_port = self.DEFAULT_PEER_PORT
self.metrics_port = self.DEFAULT_METRICS_PORT

self.client_urls = [] # these values could be assigned only from the running etcd
self.peer_urls = [] # cluster by performing http://addr:client_port/v2/members api call
Expand Down Expand Up @@ -241,8 +243,9 @@ def delete_member(self, member):
self.adjust_security_groups('revoke_ingress', member)
return result

def etcd_arguments(self, data_dir, initial_cluster, cluster_state):
return [
def etcd_arguments(self, data_dir, initial_cluster, cluster_state, run_old):
# common flags that always have to be set
arguments = [
'-name',
self.instance_id,
'--data-dir',
Expand All @@ -263,6 +266,20 @@ def etcd_arguments(self, data_dir, initial_cluster, cluster_state):
cluster_state
]

# this section handles etcd version specific flags
etcdversion = os.environ.get('ETCDVERSION_PREV' if run_old else 'ETCDVERSION')
if etcdversion:
etcdversion = tuple(int(x) for x in etcdversion.split('.'))
# etcd >= v3.3: serve metrics on an additonal port
if etcdversion >= (3, 3):
arguments += [
'-listen-metrics-urls',
'http://0.0.0.0:{}'.format(self.metrics_port),
]

# return final list of arguments
return arguments


class EtcdCluster:
REGIONS = [] # more then one (1) Region if this a Multi-Region-Cluster
Expand Down Expand Up @@ -454,7 +471,7 @@ def register_me(self, cluster):
peers = ','.join(['{}={}'.format(m.instance_id or m.name, m.peer_url) for m in cluster.members
if (include_ec2_instances and m.instance_id) or m.peer_urls])

return self.me.etcd_arguments(self.DATA_DIR, peers, cluster_state)
return self.me.etcd_arguments(self.DATA_DIR, peers, cluster_state, self.run_old)

def run(self):
cluster = EtcdCluster(self)
Expand Down