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

Add option to disable metrics collection #407

Merged
merged 5 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
40 changes: 24 additions & 16 deletions awsf3/aws_run_workflow_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export ACCESS_KEY=
export SECRET_KEY=
export REGION=
export SINGULARITY_OPTION_TO_PASS=
export DISABLE_METRICS_COLLECTION=false
export S3_ENCRYPT_KEY_ID=

printHelpAndExit() {
echo "Usage: ${0##*/} -i JOBID -l LOGBUCKET -V VERSION -A AWSF_IMAGE [-m SHUTDOWN_MIN] [-p PASSWORD] [-a ACCESS_KEY] [-s SECRET_KEY] [-r REGION] [-g] [-k S3_ENCRYPT_KEY_ID]"
echo "Usage: ${0##*/} -i JOBID -l LOGBUCKET -V VERSION -A AWSF_IMAGE [-m SHUTDOWN_MIN] [-p PASSWORD] [-a ACCESS_KEY] [-s SECRET_KEY] [-r REGION] [-g] [-c] [-k S3_ENCRYPT_KEY_ID]"
echo "-i JOBID : awsem job id (required)"
echo "-l LOGBUCKET : bucket for sending log file (required)"
echo "-V TIBANNA_VERSION : tibanna version (used in the run_task lambda that launched this instance)"
Expand All @@ -22,10 +23,11 @@ printHelpAndExit() {
echo "-s SECRET_KEY : secret key for certian s3 bucket access (if not set, use IAM permission only)"
echo "-r REGION : region for the profile set for certain s3 bucket access (if not set, use IAM permission only)"
echo "-g : use singularity"
echo "-c : Metrics collection is disabled if flag is set"
echo "-k S3_ENCRYPT_KEY_ID : KMS key to encrypt s3 files with"
exit "$1"
}
while getopts "i:m:l:p:a:s:r:gV:A:k:" opt; do
while getopts "i:m:l:p:a:s:r:gcV:A:k:" opt; do
case $opt in
i) export JOBID=$OPTARG;;
l) export LOGBUCKET=$OPTARG;; # bucket for sending log file
Expand All @@ -37,6 +39,7 @@ while getopts "i:m:l:p:a:s:r:gV:A:k:" opt; do
s) export SECRET_KEY=$OPTARG;; # secret key for certian s3 bucket access
r) export REGION=$OPTARG;; # region for the profile set for certian s3 bucket access
g) export SINGULARITY_OPTION_TO_PASS=-g;; # use singularity
c) export DISABLE_METRICS_COLLECTION=true;; # disable metrics collection
k) export S3_ENCRYPT_KEY_ID=$OPTARG;; # KMS key ID to encrypt s3 files with
h) printHelpAndExit 0;;
[?]) printHelpAndExit 1;;
Expand Down Expand Up @@ -176,24 +179,29 @@ exl mkdir -p $LOCAL_OUTDIR
mv $LOGFILE1 $LOGFILE2
export LOGFILE=$LOGFILE2


exl echo
exl echo "## Installing and activating Cloudwatch agent to collect metrics"
cwd0=$(pwd)
cd ~

ARCHITECTURE="$(dpkg --print-architecture)"
CW_AGENT_LINK="https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/${ARCHITECTURE}/latest/amazon-cloudwatch-agent.deb"
apt install -y wget
exl echo "Loading Cloudwatch Agent from ${CW_AGENT_LINK}"
wget "${CW_AGENT_LINK}"
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
# If we want to collect new metrics, the following file has to be modified
exl echo "## Using CW Agent config: https://raw.githubusercontent.com/4dn-dcic/tibanna/master/awsf3/cloudwatch_agent_config.json"
wget https://raw.githubusercontent.com/4dn-dcic/tibanna/master/awsf3/cloudwatch_agent_config.json
mv ./cloudwatch_agent_config.json /opt/aws/amazon-cloudwatch-agent/bin/config.json
# This starts the agent with the downloaded configuration file
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
if [ "$DISABLE_METRICS_COLLECTION" = false ] ; then
exl echo "## Installing and activating Cloudwatch agent to collect metrics"
ARCHITECTURE="$(dpkg --print-architecture)"
CW_AGENT_LINK="https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/${ARCHITECTURE}/latest/amazon-cloudwatch-agent.deb"
apt install -y wget
exl echo "Loading Cloudwatch Agent from ${CW_AGENT_LINK}"
wget "${CW_AGENT_LINK}"
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
# If we want to collect new metrics, the following file has to be modified
exl echo "## Using CW Agent config: https://raw.githubusercontent.com/4dn-dcic/tibanna/master/awsf3/cloudwatch_agent_config.json"
wget https://raw.githubusercontent.com/4dn-dcic/tibanna/master/awsf3/cloudwatch_agent_config.json
mv ./cloudwatch_agent_config.json /opt/aws/amazon-cloudwatch-agent/bin/config.json
# This starts the agent with the downloaded configuration file
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
else
exl echo "## Metrics collection is disabled"
fi



# Set up cronjob to monitor AWS spot instance termination notice.
# Works only in deployed Tibanna version >=1.6.0 since the ec2 needed more permissions to call `aws ec2 describe-spot-instance-requests`
Expand Down
4 changes: 4 additions & 0 deletions docs/execution_json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ The ``config`` field describes execution configuration.
- type of EBS (e.g. ``gp3``, ``gp2``, ``io1``, ``io2``)
- optional (default: gp3 (version >= ``1.0.0``) or gp2 (version < ``1.0.0``))

:disable_metrics_collection:
- <true|false>, default: false
- If true, the cloudwatch agent is not installed on the EC2 and CPU/memory/storage won't be collected and send to AWS CloudWatch. Disabling metrics collection can reduce CloudWatch associated costs.

:cloudwatch_dashboard:
- **This option is now depricated.**
- if true, Memory Used, Disk Used, CPU Utilization Cloudwatch metrics are collected into a single Cloudwatch Dashboard page. (default ``false``)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tibanna"
version = "5.2.2"
version = "5.3.0"
description = "Tibanna runs portable pipelines (in CWL/WDL) on the AWS Cloud."
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions tibanna/ec2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ def fill_default(self):
self.mem_as_is = False
if not hasattr(self, 'ebs_size_as_is'): # if false, add 5GB overhead
self.ebs_size_as_is = False
if not hasattr(self, 'disable_metrics_collection'):
self.disable_metrics_collection = False
if not hasattr(self, 'ami_id'):
self.ami_id = "" # will be assigned instance architecture specific later
if not hasattr(self, 'ami_per_region'):
Expand Down Expand Up @@ -741,6 +743,8 @@ def create_userdata(self, profile=None):
str += " -l $LOGBUCKET"
str += " -V {version}".format(version=__version__)
str += " -A {awsf_image}".format(awsf_image=cfg.awsf_image)
if cfg.disable_metrics_collection:
str += " -c"
if cfg.kms_key_id:
str += " -k %s" % cfg.kms_key_id
if cfg.password:
Expand Down
2 changes: 1 addition & 1 deletion tibanna/lambdas/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Benchmark-4dn>=0.5.24
boto3>=1.9.0
botocore>=1.12.1
tomlkit>=0.11.0
tomlkit>=0.11.0,<1.0.0
Loading