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 3 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
19 changes: 18 additions & 1 deletion 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 @@ -242,7 +244,8 @@ def delete_member(self, member):
return result

def etcd_arguments(self, data_dir, initial_cluster, cluster_state):
return [
# 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')
Copy link
Contributor

Choose a reason for hiding this comment

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

There is still one corner case left, it breaks upgrade from 3.2 to 3.3 :(
During the upgrade first it starts the old binary in order to get data, than it stops it and starts the new binary.
Current change will try to apply -listen-metrics-urls to the old binary and fail if the old version is 3.2

In order to solve it, let's introduce one more argument to this method, run_old and pass its value from https://github.com/linki/stups-etcd-cluster/blob/0a914150be28b93ff77b56747b0cf09a010138dc/etcd.py#L474:

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

And the line 270 has to be changed to:

    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