From 43dbe26dd8cc284970e692927795936c9c1364c3 Mon Sep 17 00:00:00 2001 From: damon Date: Tue, 6 Oct 2020 11:04:09 -0700 Subject: [PATCH] add prometheus option --- deploy/ansible/worker/include/run_ursula.yml | 4 ++-- nucypher/cli/commands/cloudworkers.py | 10 ++++++---- nucypher/utilities/clouddeploy.py | 16 +++++++++++++++- .../templates/cloud_deploy_ansible_inventory.j2 | 1 + 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/deploy/ansible/worker/include/run_ursula.yml b/deploy/ansible/worker/include/run_ursula.yml index de1dc69b1..3d796f434 100644 --- a/deploy/ansible/worker/include/run_ursula.yml +++ b/deploy/ansible/worker/include/run_ursula.yml @@ -70,7 +70,7 @@ max-file: "5" image: "{{ nucypher_image | default('nucypher/nucypher:latest') }}" restart_policy: "unless-stopped" - command: "nucypher ursula run {{nucypher_ursula_run_options | default('')}} {{signer_options}} --lonely --prometheus --metrics-port 9101" + command: "nucypher ursula run {{nucypher_ursula_run_options | default('')}} {{signer_options}} --lonely {{prometheus | default('')}}" volumes: - /home/nucypher:/root/.local/share/ ports: @@ -102,7 +102,7 @@ max-file: "5" image: "{{ nucypher_image | default('nucypher/nucypher:latest') }}" restart_policy: "unless-stopped" - command: "nucypher ursula run {{nucypher_ursula_run_options | default('')}} {{signer_options}} --disable-availability-check --teacher {{SEED_NODE_URI}} --prometheus --metrics-port 9101" + command: "nucypher ursula run {{nucypher_ursula_run_options | default('')}} {{signer_options}} --disable-availability-check --teacher {{SEED_NODE_URI}} {{prometheus | default('')}}" volumes: - /home/nucypher:/root/.local/share/ ports: diff --git a/nucypher/cli/commands/cloudworkers.py b/nucypher/cli/commands/cloudworkers.py index 100d65c73..b9385face 100644 --- a/nucypher/cli/commands/cloudworkers.py +++ b/nucypher/cli/commands/cloudworkers.py @@ -54,8 +54,9 @@ def cloudworkers(): @click.option('--sentry-dsn', help="a sentry dsn for these workers (https://sentry.io/)", default=None) @click.option('--include-stakeholder', 'stakes', help="limit worker to specified stakeholder addresses", multiple=True) @click.option('--wipe', help="Clear nucypher configs on existing nodes and start a fresh node with new keys.", default=False, is_flag=True) +@click.option('--prometheus', help="Run Prometheus on workers.", default=False, is_flag=True) @group_general_config -def up(general_config, staker_options, config_file, cloudprovider, aws_profile, remote_provider, nucypher_image, seed_network, sentry_dsn, stakes, wipe): +def up(general_config, staker_options, config_file, cloudprovider, aws_profile, remote_provider, nucypher_image, seed_network, sentry_dsn, stakes, wipe, prometheus): """Creates workers for all stakes owned by the user for the given network.""" emitter = setup_emitter(general_config) @@ -74,7 +75,7 @@ def up(general_config, staker_options, config_file, cloudprovider, aws_profile, config_file = config_file or StakeHolderConfiguration.default_filepath() - deployer = CloudDeployers.get_deployer(cloudprovider)(emitter, STAKEHOLDER, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, aws_profile) + deployer = CloudDeployers.get_deployer(cloudprovider)(emitter, STAKEHOLDER, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, aws_profile, prometheus) config = deployer.create_nodes_for_stakers(staker_addresses) if config.get('instances') and len(config.get('instances')) >= len(staker_addresses): @@ -124,8 +125,9 @@ def add(general_config, staker_options, config_file, staker_address, host_addres @click.option('--sentry-dsn', help="a sentry dsn for these workers (https://sentry.io/)", default=None) @click.option('--include-stakeholder', 'stakes', help="limit worker to specified stakeholder addresses", multiple=True) @click.option('--wipe', help="Clear your nucypher config and start a fresh node with new kets", default=False, is_flag=True) +@click.option('--prometheus', help="Run Prometheus on workers.", default=False, is_flag=True) @group_general_config -def deploy(general_config, staker_options, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, stakes, wipe): +def deploy(general_config, staker_options, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, stakes, wipe, prometheus): """Deploys NuCypher on existing hardware.""" emitter = setup_emitter(general_config) @@ -144,7 +146,7 @@ def deploy(general_config, staker_options, config_file, remote_provider, nucyphe config_file = config_file or StakeHolderConfiguration.default_filepath() - deployer = CloudDeployers.get_deployer('generic')(emitter, STAKEHOLDER, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn) + deployer = CloudDeployers.get_deployer('generic')(emitter, STAKEHOLDER, config_file, remote_provider, nucypher_image, seed_network, sentry_dsn, prometheus=prometheus) emitter.echo("found nodes for the following stakers:") for staker_address in staker_addresses: diff --git a/nucypher/utilities/clouddeploy.py b/nucypher/utilities/clouddeploy.py index 699ceac29..bdd881929 100644 --- a/nucypher/utilities/clouddeploy.py +++ b/nucypher/utilities/clouddeploy.py @@ -133,7 +133,19 @@ class AnsiblePlayBookResultsCollector(CallbackBase): class BaseCloudNodeConfigurator: - def __init__(self, emitter, stakeholder, stakeholder_config_path, blockchain_provider=None, nucypher_image=None, seed_network=False, sentry_dsn=None, profile=None): + PROMETHEUS_PORT = PROMETHEUS_PORTS[0] + + def __init__(self, + emitter, + stakeholder, + stakeholder_config_path, + blockchain_provider=None, + nucypher_image=None, + seed_network=False, + sentry_dsn=None, + profile=None, + prometheus=False, + ): self.emitter = emitter self.stakeholder = stakeholder @@ -183,6 +195,8 @@ class BaseCloudNodeConfigurator: self.config.pop('seed_node', None) self.nodes_are_decentralized = 'geth.ipc' in self.config['blockchain_provider'] self.config['stakeholder_config_file'] = stakeholder_config_path + self.config['use-prometheus'] = prometheus + self._write_config() def _write_config(self): diff --git a/nucypher/utilities/templates/cloud_deploy_ansible_inventory.j2 b/nucypher/utilities/templates/cloud_deploy_ansible_inventory.j2 index 810faf90b..55e36481e 100644 --- a/nucypher/utilities/templates/cloud_deploy_ansible_inventory.j2 +++ b/nucypher/utilities/templates/cloud_deploy_ansible_inventory.j2 @@ -19,6 +19,7 @@ all: nucypher_image: {{deployer.config['nucypher_image']}} blockchain_provider: {{deployer.config['blockchain_provider']}} node_is_decentralized: {{deployer.nodes_are_decentralized}} + prometheus: {% if deployer.config.get('use-prometheus') %}--prometheus --metrics-port {{deployer.PROMETHEUS_PORT}}{% endif %} SEED_NODE_URI:{% if deployer.config.get('seed_node') %} {{deployer.config['seed_node']}}{% endif %} {% if deployer.config.get('sentry_dsn')%}SENTRY_DSN: {{deployer.config['sentry_dsn']}}{% endif %} wipe_nucypher_config: {{wipe_nucypher}}