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

Enable delfin installer to run multiple instances of delfin components #625

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
# 4. When finished using delfin project, bring down containers using following command
#
# $ docker-compose down
#
# 5. To bring up delfin project with multiple service instances
#
# $ docker-compose up -d --scale <<service-name>>=<<number of instances>>
#
# example: Deploy delfin with 3 delfin-task and 2 delfin-alert instances
AmitRoushan marked this conversation as resolved.
Show resolved Hide resolved
# $ docker-compose up -d --scale delfin-task=3 --scale delfin-alert=2
# Note: Multiple instances of delfin-api are not allowed

version: '3.3'

Expand Down
16 changes: 16 additions & 0 deletions installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ installer/install
root@root1:~/delfin-demo/delfin$ installer/install
```

#### Configure multiple instances of delfin components
Respective environment variable required to set for running multiple instances
of delfin component before executing install command

```sh
$ export DELFIN_<<delfin component name>>_INSTANCES=<<number of instances>>
$ installer/install

# Example: Deploy delfin with 3 task and 2 alert instances
$ export DELFIN_TASK_INSTANCES=3
$ export DELFIN_ALERT_INSTANCES=2
$ installer/install
```

Note: Multiple instances of exporter and api is not allowed currently.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Somewhere we can mention about the scope of this step is for single node, multi instances of processes

# Uninstall
Running the uninstall script will stop all delfin processes and do cleanup
```sh
Expand Down
60 changes: 32 additions & 28 deletions installer/install_delfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import os
import subprocess
from subprocess import CalledProcessError
import traceback as tb
from subprocess import CalledProcessError

from installer.helper import copy_files, create_dir, \
logger, logfile, delfin_log_dir, create_file

Expand Down Expand Up @@ -53,42 +54,45 @@ def create_delfin_db():


def start_processes():
# start api process
proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd', 'api.py')
command = 'python3 ' + proc_path + ' --config-file ' +\
conf_file + ' >' + DEVNULL + ' 2>&1 &'
# >/dev/null 2>&1
logger.info("Executing command [%s]", command)
os.system(command)
logger.info("API process_started")

# Start task process
proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd', 'task.py')
command = 'python3 ' + proc_path + ' --config-file ' +\
conf_file + ' >' + DEVNULL + ' 2>&1 &'
logger.info("Executing command [%s]", command)
os.system(command)

logger.info("TASK process_started")

# Start alert process
proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd', 'alert.py')
command = 'python3 ' + proc_path + ' --config-file ' +\
conf_file + ' >' + DEVNULL + ' 2>&1 &'
logger.info("Executing command [%s]", command)
os.system(command)
logger.info("ALERT process_started")
processes = ['api', 'task', 'alert']
# Start cmd processes
for process in processes:
env_var = 'DELFIN_' + process.upper() + '_INSTANCES'
try:
instances = os.environ.get(env_var)
# Ignore multiple instance of api
if not instances or process == 'api':
instances = '1'
start_process(process, int(instances))
except CalledProcessError as cpe:
logger.error("Got CPE error [%s]:[%s]" % (cpe, tb.print_exc()))
return
except ValueError as e:
logger.error(
"Got invalid [%s] environment variable:[%s]" % (env_var, e))
return

# Start exporter server process
proc_path = os.path.join(delfin_source_path, 'delfin', 'exporter',
'prometheus', 'exporter_server.py')
command = 'python3 ' + proc_path + ' --config-file ' +\
command = 'python3 ' + proc_path + ' --config-file ' + \
conf_file + ' >' + DEVNULL + ' 2>&1 &'
logger.info("Executing command [%s]", command)
os.system(command)
logger.info("Exporter process_started")


def start_process(process, instances=1):
for instance in range(0, instances):
proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd',
process + '.py')
command = 'python3 ' + proc_path + ' --config-file ' + \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Its always good to put the absolute path of the command (viz. /usr/bin/python3) and it should be constant driven

Copy link
Author

Choose a reason for hiding this comment

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

issue created #635

conf_file + ' >' + DEVNULL + ' 2>&1 &'
logger.info("Executing command [%s]", command)
os.system(command)
logger.info("[%s] process_started", process)


def install_delfin():
python_setup_comm = ['build', 'install']
req_logs = os.path.join(delfin_log_dir, 'requirements.log')
Expand All @@ -99,7 +103,7 @@ def install_delfin():
setup_file = os.path.join(delfin_source_path, 'setup.py')
for command in python_setup_comm:
try:
command = 'python3 ' + setup_file + ' ' +\
command = 'python3 ' + setup_file + ' ' + \
command + ' >>' + logfile
logger.info("Executing [%s]", command)
os.system(command)
Expand Down