From e64fcbe05549b3feda85c687a7de15f4c4984ef6 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Tue, 30 Jan 2024 13:14:56 +0530 Subject: [PATCH 01/19] update runbook.yaml config --- .../runwhen-config/runbook.yaml | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/runwhen-config/runbook.yaml b/codebundles/rds-mysql-conn-count/runwhen-config/runbook.yaml index 27fdbc6..8d17ef1 100644 --- a/codebundles/rds-mysql-conn-count/runwhen-config/runbook.yaml +++ b/codebundles/rds-mysql-conn-count/runwhen-config/runbook.yaml @@ -1,26 +1,18 @@ location: location-01-us-west1 codeBundle: - repoUrl: https://github.com/infracloudio/infracloud-runwhen-codecollection.git - ref: codebundle-rds-mysql-conn + repoUrl: https://github.com/infracloudio/ifc-rw-codecollection + ref: main pathToRobot: codebundles/rds-mysql-conn-count/runbook.robot -configProvided: - - name: KUBERNETES_DISTRIBUTION_BINARY - value: kubectl - - name: NAMESPACE - value: default - - name: ERROR_PATTERN - value: (Error|Exception) - - name: CONTEXT - value: default - - name: SERVICE_ERROR_PATTERN - value: (Error:) - - name: SERVICE_EXCLUDE_PATTERN - value: (node_modules|opentelemetry) - - name: ANOMALY_THRESHOLD - value: '5.0' -secretsProvided: - - name: kubeconfig - workspaceKey: kubeconfig +secretsProvided: [] servicesProvided: - - name: kubectl - locationServiceName: kubectl-service.shared + - name: curl + locationServiceName: curl-service.shared +configProvided: + - name: MYSQL_USER + value: admin + - name: MYSQL_HOST + value: robotshopmysql.example.us-west-2.rds.amazonaws.com + - name: PROCESS_USER + value: shipping + - name: MYSQL_PASSWORD + value: example_pass From cd2f9b09e11d2439b08acd231aef481b8e1f7111 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Tue, 30 Jan 2024 18:35:10 +0530 Subject: [PATCH 02/19] update repoUrl and ref --- codebundles/rds-mysql-conn-count/runwhen-config/sli.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/runwhen-config/sli.yaml b/codebundles/rds-mysql-conn-count/runwhen-config/sli.yaml index aa52d79..0b5a38c 100644 --- a/codebundles/rds-mysql-conn-count/runwhen-config/sli.yaml +++ b/codebundles/rds-mysql-conn-count/runwhen-config/sli.yaml @@ -5,8 +5,8 @@ locations: description: >- Watch RDS MySql connection count codeBundle: - repoUrl: https://github.com/infracloudio/infracloud-runwhen-codecollection.git - ref: codebundle-rds-mysql-conn + repoUrl: https://github.com/infracloudio/ifc-rw-codecollection + ref: main pathToRobot: codebundles/rds-mysql-conn-count/sli.robot # read more about intervalStrategy here: https://docs.runwhen.com/public/runwhen-platform/feature-overview/points-on-the-map-slxs/service-level-indicators-slis/interval-strategies intervalStrategy: intermezzo From c3395acd1bade066928cf3a6a4f83512ab302e9c Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Thu, 1 Feb 2024 16:21:33 +0530 Subject: [PATCH 03/19] add secret__ for mysql password in runbook.robot --- codebundles/rds-mysql-conn-count/runbook.robot | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/runbook.robot b/codebundles/rds-mysql-conn-count/runbook.robot index 7619253..400899f 100644 --- a/codebundles/rds-mysql-conn-count/runbook.robot +++ b/codebundles/rds-mysql-conn-count/runbook.robot @@ -9,8 +9,6 @@ Library RW.CLI Suite Setup Suite Initialization -*** Variables *** -${MYSQL_PASSWORD_ENV} %{MYSQL_PASSWORD_ENV} *** Tasks *** Run Bash File @@ -20,6 +18,7 @@ Run Bash File ... bash_file=kill-mysql-sleep-processes.sh ... cmd_override=./kill-mysql-sleep-processes.sh ... env=${env} + ... secret__mysql_password=${MYSQL_PASSWORD} ... include_in_history=False RW.Core.Add Pre To Report Command Stdout:\n${rsp.stdout} RW.Core.Add Pre To Report Command Stderr:\n${rsp.stderr} @@ -41,7 +40,7 @@ Suite Initialization ... type=string ... description=MySQL host endpoint ... pattern=\w* - ... example=robotshopmysql.cn9m6m4s8zo0.us-west-2.rds.amazonaws.com + ... example=exampledb.example.us-west-2.rds.amazonaws.com ${PROCESS_USER}= RW.Core.Import User Variable PROCESS_USER ... type=string ... description=mysql user which created numbers of sleep connections @@ -49,4 +48,4 @@ Suite Initialization ... example=shipping Set Suite Variable - ... ${env} {"MYSQL_USER":"${MYSQL_USER}", "MYSQL_PASSWORD":"${MYSQL_PASSWORD_ENV}", "MYSQL_HOST":"${MYSQL_HOST}", "PROCESS_USER":"${PROCESS_USER}"} \ No newline at end of file + ... ${env} {"MYSQL_USER":"${MYSQL_USER}", "MYSQL_HOST":"${MYSQL_HOST}", "PROCESS_USER":"${PROCESS_USER}"} \ No newline at end of file From e6238f212e687feefa2dc882a7e4724f6798b407 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Wed, 31 Jan 2024 13:07:25 +0530 Subject: [PATCH 04/19] fix variables name in sli.robot --- codebundles/rds-mysql-conn-count/sli.robot | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/sli.robot b/codebundles/rds-mysql-conn-count/sli.robot index c6fef95..7c1441e 100644 --- a/codebundles/rds-mysql-conn-count/sli.robot +++ b/codebundles/rds-mysql-conn-count/sli.robot @@ -6,9 +6,6 @@ Suite Setup Suite Initialization Library RW.Core Library RW.Prometheus -*** Variables *** -${ENV_PROMETHEUS_HOST} %{ENV_PROMETHEUS_HOST} -${ENV_QUERY} %{ENV_QUERY} *** Keywords *** Suite Initialization @@ -74,8 +71,8 @@ Suite Initialization Querying Prometheus Instance And Pushing Aggregated Data Log ${ENV_QUERY} ${rsp}= RW.Prometheus.Query Instant - ... api_url=${ENV_PROMETHEUS_HOST} - ... query=${ENV_QUERY} + ... api_url=${PROMETHEUS_HOSTNAME} + ... query=${QUERY} ... step=${STEP} ... target_service=${CURL_SERVICE} ${data}= Set Variable ${rsp["data"]} From 9bfb86bdc192a9846b2f69c1e7efe39c6216f948 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Wed, 31 Jan 2024 13:58:17 +0530 Subject: [PATCH 05/19] remove OPTIONAL_HEADERS from sli.robot --- codebundles/rds-mysql-conn-count/sli.robot | 8 -------- 1 file changed, 8 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/sli.robot b/codebundles/rds-mysql-conn-count/sli.robot index 7c1441e..19cf0a1 100644 --- a/codebundles/rds-mysql-conn-count/sli.robot +++ b/codebundles/rds-mysql-conn-count/sli.robot @@ -15,12 +15,6 @@ Suite Initialization ... pattern=\w* ... example=curl-service.shared ... default=curl-service.shared - ${OPTIONAL_HEADERS}= RW.Core.Import Secret OPTIONAL_HEADERS - ... type=string - ... description=A json string of headers to include in the request against the Prometheus instance. This can include your token. - ... pattern=\w* - ... default="{"my-header":"my-value"}" - ... example='{"my-header":"my-value", "Authorization": "Bearer mytoken"}' RW.Core.Import User Variable PROMETHEUS_HOSTNAME ... type=string ... description=The prometheus endpoint to perform requests against. @@ -63,13 +57,11 @@ Suite Initialization ... default=0 ... example=0 Set Suite Variable ${CURL_SERVICE} ${CURL_SERVICE} - Set Suite Variable ${OPTIONAL_HEADERS} ${OPTIONAL_HEADERS} Set Suite Variable ${NO_RESULT_OVERWRITE} ${NO_RESULT_OVERWRITE} Set Suite Variable ${NO_RESULT_VALUE} ${NO_RESULT_VALUE} *** Tasks *** Querying Prometheus Instance And Pushing Aggregated Data - Log ${ENV_QUERY} ${rsp}= RW.Prometheus.Query Instant ... api_url=${PROMETHEUS_HOSTNAME} ... query=${QUERY} From dbd4e4f1ecef8f9d3c812744269a836b0390bca8 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Thu, 1 Feb 2024 14:08:15 +0530 Subject: [PATCH 06/19] update query example and default value in sli.robot --- codebundles/rds-mysql-conn-count/sli.robot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/sli.robot b/codebundles/rds-mysql-conn-count/sli.robot index 19cf0a1..47ae7f1 100644 --- a/codebundles/rds-mysql-conn-count/sli.robot +++ b/codebundles/rds-mysql-conn-count/sli.robot @@ -24,8 +24,8 @@ Suite Initialization ... type=string ... description=The PromQL statement used to query metrics. ... pattern=\w* - ... example=sysdig_container_cpu_quota_used_percent > 75 or sysdig_container_memory_limit_used_percent> 75 - ... default=sysdig_container_cpu_quota_used_percent > 75 or sysdig_container_memory_limit_used_percent> 75 + ... example=aws_rds_database_connections_average{dimension_DBInstanceIdentifier="dbname"} > 1 + ... default=aws_rds_database_connections_average{dimension_DBInstanceIdentifier="dbname"} > 1 RW.Core.Import User Variable TRANSFORM ... type=string ... enum=[Raw,Max,Average,Minimum,Sum,First,Last] From 60c86ff0ca95c5fb50445849c4f362cabc64874e Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Thu, 1 Feb 2024 16:27:01 +0530 Subject: [PATCH 07/19] clean kill-mysql-sleep-processes.sh --- .../kill-mysql-sleep-processes.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/kill-mysql-sleep-processes.sh b/codebundles/rds-mysql-conn-count/kill-mysql-sleep-processes.sh index b340981..de407d8 100755 --- a/codebundles/rds-mysql-conn-count/kill-mysql-sleep-processes.sh +++ b/codebundles/rds-mysql-conn-count/kill-mysql-sleep-processes.sh @@ -1,17 +1,7 @@ #!/bin/bash -# MySQL connection details -# MYSQL_USER="admin" -# MYSQL_PASSWORD="docdb3421z" -# MYSQL_HOST="robotshopmysql.cn9m6m4s8zo0.us-west-2.rds.amazonaws.com" -# PROCESS_USER="shipping" -echo "MYSQL_USER $MYSQL_USER" -echo "MYSQL_PASSWORD $MYSQL_PASSWORD" -echo "MYSQL_HOST $MYSQL_HOST" -echo "PROCESS_USER $PROCESS_USER" - # Get process list IDs -PROCESS_IDS=$(MYSQL_PWD="$MYSQL_PASSWORD" mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -N -s -e "SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='shipping'") +PROCESS_IDS=$(MYSQL_PWD="$MYSQL_PASSWORD" mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -N -s -e "SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='$PROCESS_USER'") if [ $? -ne 0 ]; then echo "Error connecting to MySQL" From 4e1e3a12ab30f4fae577450aac8423222728f959 Mon Sep 17 00:00:00 2001 From: Hashfyre Date: Thu, 1 Feb 2024 16:38:27 +0530 Subject: [PATCH 08/19] deleted sample codebundle - hello_world --- codebundles/hello_world/README.md | 11 ----------- codebundles/hello_world/sli.robot | 12 ------------ 2 files changed, 23 deletions(-) delete mode 100644 codebundles/hello_world/README.md delete mode 100644 codebundles/hello_world/sli.robot diff --git a/codebundles/hello_world/README.md b/codebundles/hello_world/README.md deleted file mode 100644 index 76d20b1..0000000 --- a/codebundles/hello_world/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Hello World -## SLI -A simple SLI that gets a hello world message and pushes a metric value of 1 - -## Use Cases -- demonstrates codecollection layout - -## Requirements - -## TODO -- [ ] Add additional documentation \ No newline at end of file diff --git a/codebundles/hello_world/sli.robot b/codebundles/hello_world/sli.robot deleted file mode 100644 index 6fcf347..0000000 --- a/codebundles/hello_world/sli.robot +++ /dev/null @@ -1,12 +0,0 @@ -*** Settings *** -Metadata Author My Name -Documentation This is a hello world codebundle! -Force Tags Message Hello World Test -Library RW.Core -Library MyKeywords.HelloWorld - -*** Tasks *** -Hello World - ${msg}= MyKeywords.HelloWorld.get_msg - Log ${msg} - RW.Core.Push Metric 1 \ No newline at end of file From eb90fb737a9c9e59f197700e3941964d8a12e636 Mon Sep 17 00:00:00 2001 From: Hashfyre Date: Thu, 1 Feb 2024 16:41:00 +0530 Subject: [PATCH 09/19] update dev-cluster git submodule path --- .gitmodules | 4 ++-- Makefile | 6 +++--- test/sre-stack | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) delete mode 160000 test/sre-stack diff --git a/.gitmodules b/.gitmodules index 7e25692..ce8893a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "test/sre-stack"] - path = test/sre-stack +[submodule "dev-cluster/sre-stack"] + path = dev-cluster/sre-stack url = https://github.com/infracloudio/sre-stack.git branch = main diff --git a/Makefile b/Makefile index 4a931c9..da10b8e 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ GIT_TLD=$(shell git rev-parse --show-toplevel) -include $(GIT_TLD)/test/sre-stack/.env +include $(GIT_TLD)/dev-cluster/sre-stack/.env include $(GIT_TLD)/.env -include $(GIT_TLD)/test/sre-stack/makefile -SRE_STACK_DIR := $(GIT_TLD)/test/sre-stack +include $(GIT_TLD)/dev-cluster/sre-stack/makefile +SRE_STACK_DIR := $(GIT_TLD)/dev-cluster/sre-stack RUNWHEN_SETUP_SCRIPT_PATH=setup/runwhen-local/setup.sh RUNWHEN_REQUIRED_VARS := RUNWHEN_PLATFORM_TOKEN diff --git a/test/sre-stack b/test/sre-stack deleted file mode 160000 index a14f401..0000000 --- a/test/sre-stack +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a14f40196c3865f255cc45269839158dc88bd89a From 317704f8652b6cf95fa6a07bd1bb8bd6831dbbf6 Mon Sep 17 00:00:00 2001 From: Hashfyre Date: Thu, 1 Feb 2024 16:41:47 +0530 Subject: [PATCH 10/19] Update test scaffolding --- codebundles/hello_world_taskset/README.md | 11 -------- codebundles/hello_world_taskset/runbook.robot | 23 --------------- codebundles/rds-mysql-conn-count/sli.robot | 4 +-- .../test/scripts/local-docker.sh | 22 --------------- .../create-msql-sleeping-connections.sh | 0 .../runbook/runbook-deployment.yaml} | 12 +++----- .../tests/sli/dev-cluster/sli-deployment.yaml | 28 +++++++++++++++++++ .../tests/sli/dev-cluster/test.sh | 9 ++++++ .../sli/local-docker/docker-compose.yaml | 15 ++++++++++ .../tests/sli/local-docker/test.sh | 13 +++++++++ 10 files changed, 71 insertions(+), 66 deletions(-) delete mode 100644 codebundles/hello_world_taskset/README.md delete mode 100644 codebundles/hello_world_taskset/runbook.robot delete mode 100644 codebundles/rds-mysql-conn-count/test/scripts/local-docker.sh rename codebundles/rds-mysql-conn-count/{test/scripts => tests/runbook/dev-cluster}/create-msql-sleeping-connections.sh (100%) rename codebundles/rds-mysql-conn-count/{test/manifests/sli-deployment.yaml => tests/runbook/runbook-deployment.yaml} (66%) create mode 100644 codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml create mode 100644 codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh create mode 100644 codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml create mode 100644 codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh diff --git a/codebundles/hello_world_taskset/README.md b/codebundles/hello_world_taskset/README.md deleted file mode 100644 index 725a9ee..0000000 --- a/codebundles/hello_world_taskset/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Hello World Taskset -## Taskset -A simple taskset that imports a single variable and adds it to the report. - -## Use Cases -- demonstrates codecollection layout - -## Requirements - -## TODO -- [ ] Add additional documentation \ No newline at end of file diff --git a/codebundles/hello_world_taskset/runbook.robot b/codebundles/hello_world_taskset/runbook.robot deleted file mode 100644 index fadf1a0..0000000 --- a/codebundles/hello_world_taskset/runbook.robot +++ /dev/null @@ -1,23 +0,0 @@ -*** Settings *** -Metadata Author My Name -Documentation This is a hello world codebundle! -Force Tags Hello World Test -Library RW.Core -Suite Setup Suite Initialization - -*** Keywords *** -Suite Initialization - ${MY_INPUT}= RW.Core.Import User Variable MY_INPUT - ... type=string - ... description=A simple input variable - ... pattern=\w* - ... example=my special input - ... default=default input value - Set Suite Variable ${MY_INPUT} ${MY_INPUT} - -*** Tasks *** -Hello world - ${msg}= Set Variable The configured input is: ${MY_INPUT} - RW.Core.Add Pre To Report ${msg} - - diff --git a/codebundles/rds-mysql-conn-count/sli.robot b/codebundles/rds-mysql-conn-count/sli.robot index 47ae7f1..d05b2d4 100644 --- a/codebundles/rds-mysql-conn-count/sli.robot +++ b/codebundles/rds-mysql-conn-count/sli.robot @@ -15,7 +15,7 @@ Suite Initialization ... pattern=\w* ... example=curl-service.shared ... default=curl-service.shared - RW.Core.Import User Variable PROMETHEUS_HOSTNAME + RW.Core.Import User Variable PROMETHEUS_URL ... type=string ... description=The prometheus endpoint to perform requests against. ... pattern=\w* @@ -63,7 +63,7 @@ Suite Initialization *** Tasks *** Querying Prometheus Instance And Pushing Aggregated Data ${rsp}= RW.Prometheus.Query Instant - ... api_url=${PROMETHEUS_HOSTNAME} + ... api_url=${PROMETHEUS_URL} ... query=${QUERY} ... step=${STEP} ... target_service=${CURL_SERVICE} diff --git a/codebundles/rds-mysql-conn-count/test/scripts/local-docker.sh b/codebundles/rds-mysql-conn-count/test/scripts/local-docker.sh deleted file mode 100644 index 515cb39..0000000 --- a/codebundles/rds-mysql-conn-count/test/scripts/local-docker.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Build Image -docker build --tag runwhen . --no-cache - -# Run container -docker run --rm -d -p 3000:3000 --name rds-codecollection \ ---network="host" \ --e ENV_PROMETHEUS_HOST="http://${SRE_STACK_PROM_PUBLIC_HOST}/prometheus/api/v1" \ --e ENV_QUERY="aws_rds_database_connections_average{dimension_DBInstanceIdentifier=\"robotshopmysql\"} > 1" \ --e MYSQL_USER="admin" \ --e MYSQL_PASSWORD_ENV="" \ --e MYSQL_HOST="${SRE_STACK_RDS_MYSQL_PRIVATE_HOST}" \ --e PROCESS_USER="shipping" \ --e RW_PATH_TO_ROBOT="/app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot" \ -runwhen:latest - -# Run SLI -docker exec rds-codecollection bash -c "ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot && ls -R /robot_logs" - -# Run runbook -docker exec rds-codecollection bash -c "ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot && ls -R /robot_logs" \ No newline at end of file diff --git a/codebundles/rds-mysql-conn-count/test/scripts/create-msql-sleeping-connections.sh b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-msql-sleeping-connections.sh similarity index 100% rename from codebundles/rds-mysql-conn-count/test/scripts/create-msql-sleeping-connections.sh rename to codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-msql-sleeping-connections.sh diff --git a/codebundles/rds-mysql-conn-count/test/manifests/sli-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/runbook-deployment.yaml similarity index 66% rename from codebundles/rds-mysql-conn-count/test/manifests/sli-deployment.yaml rename to codebundles/rds-mysql-conn-count/tests/runbook/runbook-deployment.yaml index ae4aed4..cc9c16e 100644 --- a/codebundles/rds-mysql-conn-count/test/manifests/sli-deployment.yaml +++ b/codebundles/rds-mysql-conn-count/tests/runbook/runbook-deployment.yaml @@ -1,19 +1,19 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: rds-mysql-connection-count + name: rds-mysql-connection-count-runbook spec: replicas: 1 selector: matchLabels: - app: rds-mysql-connection-count + app: rds-mysql-connection-count-runbook template: metadata: labels: - app: rds-mysql-connection-count + app: rds-mysql-connection-count-runbook spec: containers: - - name: rds-mysql-connection-count + - name: rds-mysql-connection-count-runbook image: 590183940259.dkr.ecr.us-west-2.amazonaws.com/runwhen:latest command: - "bash" @@ -22,10 +22,6 @@ spec: ports: - containerPort: 3000 env: - - name: ENV_PROMETHEUS_HOST - value: "http://ab916f39fadce498ead455d91e808053-1900228415.us-west-2.elb.amazonaws.com/prometheus/api/v1" - - name: ENV_QUERY - value: "aws_rds_database_connections_average{dimension_DBInstanceIdentifier=\"robotshopmysql\"} > 1" - name: MYSQL_USER value: "admin" - name: MYSQL_PASSWORD_ENV diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml new file mode 100644 index 0000000..89da4a4 --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: rds-mysql-connection-count +spec: + replicas: 1 + selector: + matchLabels: + app: rds-mysql-connection-count-sli + template: + metadata: + labels: + app: rds-mysql-connection-count-sli + spec: + containers: + - name: rds-mysql-connection-count-sli + image: 590183940259.dkr.ecr.us-west-2.amazonaws.com/runwhen:latest + command: + - "bash" + - "-c" + - "ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot && while true; do sleep 5; done" + ports: + - containerPort: 3000 + env: + - name: ENV_PROMETHEUS_HOST + value: "http://ab916f39fadce498ead455d91e808053-1900228415.us-west-2.elb.amazonaws.com/prometheus/api/v1" + - name: ENV_QUERY + value: "aws_rds_database_connections_average{dimension_DBInstanceIdentifier=\"robotshopmysql\"} > 1" \ No newline at end of file diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh new file mode 100644 index 0000000..95d18e5 --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Deploy SLI test deployment +kubectl apply -f sli-deployment.yaml +# Exposes SLI test deployment + +## Show browser URLs +echo +echo \ No newline at end of file diff --git a/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml new file mode 100644 index 0000000..e74688b --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml @@ -0,0 +1,15 @@ +version: "3.8" +services: + rw-sli-test: + build: + context: ../../../../../ + dockerfile: Dockerfile + environment: + PROMETHEUS_URL: "http://localhost:9090/prometheus/api/v1" + QUERY: "aws_rds_database_connections_average{dimension_DBInstanceIdentifier=\"robotshopmysql\"} > 1" + ports: + - 3000:3000 +networks: + host: + name: host + external: true \ No newline at end of file diff --git a/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh new file mode 100644 index 0000000..b5377ec --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# expose promethes endpoint on your localhost from dev-cluster +kubectl port-forward service/prom-... 9090:9090 +# Run container +docker-compose up -d + +# Run SLI +docker exec local-docker-rw-sli-test bash -c "ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot && ls -R /robot_logs" + +## Show browser URLs +echo +echo From f6909273501262261fb210db625fca83bf9092f2 Mon Sep 17 00:00:00 2001 From: Hashfyre Date: Fri, 2 Feb 2024 12:04:51 +0530 Subject: [PATCH 11/19] fix sre-stack submodule --- .gitignore | 2 +- Makefile | 10 ++++++---- dev-cluster/sre-stack | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) create mode 160000 dev-cluster/sre-stack diff --git a/.gitignore b/.gitignore index df5da75..d4fe6ed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ __pycache__ output.xml log.html report.html -test/sre-stack/* \ No newline at end of file +dev-cluster/sre-stack/* \ No newline at end of file diff --git a/Makefile b/Makefile index da10b8e..e3225a3 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,16 @@ GIT_TLD=$(shell git rev-parse --show-toplevel) -include $(GIT_TLD)/dev-cluster/sre-stack/.env -include $(GIT_TLD)/.env -include $(GIT_TLD)/dev-cluster/sre-stack/makefile SRE_STACK_DIR := $(GIT_TLD)/dev-cluster/sre-stack -RUNWHEN_SETUP_SCRIPT_PATH=setup/runwhen-local/setup.sh +include $(DEV_CLUSTER_SUBMODULE_PATH)/.env +include $(GIT_TLD)/.env +include $(DEV_CLUSTER_SUBMODULE_PATH)/makefile +RUNWHEN_SETUP_SCRIPT_PATH=setup/runwhen-local/setup.sh RUNWHEN_REQUIRED_VARS := RUNWHEN_PLATFORM_TOKEN + $(foreach var,$(RUNWHEN_REQUIRED_VARS),$(if $(value $(var)),,$(error $(var) is not set))) setup-sre-stack: + git submodule update --recursive --remote $(MAKE) setup -C $(SRE_STACK_DIR) cleanup-sre-stack: diff --git a/dev-cluster/sre-stack b/dev-cluster/sre-stack new file mode 160000 index 0000000..2783be6 --- /dev/null +++ b/dev-cluster/sre-stack @@ -0,0 +1 @@ +Subproject commit 2783be6eb932b25f22d0f18eff2c27a015fead7b From 67079adf2d37f6e25e4f7ace3009f1c86f5903a8 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Fri, 2 Feb 2024 14:08:42 +0530 Subject: [PATCH 12/19] rds-mysql-conn-count sli test: update docker-compose.yaml and test.sh script --- .../sli/local-docker/docker-compose.yaml | 9 ++------- .../tests/sli/local-docker/test.sh | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) mode change 100644 => 100755 codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh diff --git a/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml index e74688b..a8782de 100644 --- a/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml +++ b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/docker-compose.yaml @@ -5,11 +5,6 @@ services: context: ../../../../../ dockerfile: Dockerfile environment: - PROMETHEUS_URL: "http://localhost:9090/prometheus/api/v1" + PROMETHEUS_URL: "http://${PROM_HOST}/api/v1" QUERY: "aws_rds_database_connections_average{dimension_DBInstanceIdentifier=\"robotshopmysql\"} > 1" - ports: - - 3000:3000 -networks: - host: - name: host - external: true \ No newline at end of file + network_mode: host \ No newline at end of file diff --git a/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh old mode 100644 new mode 100755 index b5377ec..a847749 --- a/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/sli/local-docker/test.sh @@ -1,13 +1,25 @@ #!/bin/bash +export PROM_HOST="$(kubectl get svc istio-ingressgateway -n istio-system -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')/prometheus" + +# Remove existing port-forward +kill -9 $(ps -ef | grep port-forward | awk 'NR==1 {print $2}') + # expose promethes endpoint on your localhost from dev-cluster -kubectl port-forward service/prom-... 9090:9090 +kubectl port-forward svc/prometheus-stack-kube-prom-prometheus 9090:9090 -n monitoring & + +# Remove old containers +docker-compose down + +# Build new containers +docker-compose build + # Run container docker-compose up -d # Run SLI -docker exec local-docker-rw-sli-test bash -c "ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot && ls -R /robot_logs" +docker exec local-docker_rw-sli-test_1 bash -c "ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot && ls -R /robot_logs" ## Show browser URLs -echo -echo +printf "\n Open Status page http://localhost:3000/" +printf "\n See logs http://localhost:3000/rds-mysql-conn-count/sli-log.html\n" From d7618d3ad5197133101cee26efef12e56383fdd3 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Fri, 2 Feb 2024 15:38:27 +0530 Subject: [PATCH 13/19] add rds-mysql-connection-count rubook test suite --- .../create-msql-sleeping-connections.sh | 14 -------- .../create-mysql-sleep-conn-deployment.yaml | 35 +++++++++++++++++++ .../{ => dev-cluster}/runbook-deployment.yaml | 4 +-- .../runbook/dev-cluster/runbook-svc.yaml | 12 +++++++ .../tests/runbook/dev-cluster/test.sh | 26 ++++++++++++++ 5 files changed, 75 insertions(+), 16 deletions(-) delete mode 100644 codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-msql-sleeping-connections.sh create mode 100644 codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml rename codebundles/rds-mysql-conn-count/tests/runbook/{ => dev-cluster}/runbook-deployment.yaml (90%) create mode 100644 codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml create mode 100755 codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-msql-sleeping-connections.sh b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-msql-sleeping-connections.sh deleted file mode 100644 index 6a55b52..0000000 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-msql-sleeping-connections.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# MySQL connection details -MYSQL_USER="shipping" -MYSQL_PASSWORD="secret" -MYSQL_HOST="robotshopmysql.c5eo4uy8mys1.us-west-2.rds.amazonaws.com" - -CONNECTIONS=30 -SLEEP_TIMEOUT=260 - -for ((i=1;i<=$CONNECTIONS;i++)) -do - MYSQL_PWD="$MYSQL_PASSWORD" mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -N -s -e "SELECT SLEEP(${SLEEP_TIMEOUT});" & -done diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml new file mode 100644 index 0000000..76356fc --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: create-mysql-sleep-connection +spec: + replicas: 1 + selector: + matchLabels: + app: create-mysql-sleep-connection + template: + metadata: + labels: + app: create-mysql-sleep-connection + spec: + containers: + - name: create-mysql-sleep-connection + image: mysql:8.0.36 + env: + - name: MYSQL_USER + value: "shipping" + - name: MYSQL_PASSWORD + value: "secret" + - name: MYSQL_HOST + value: "robotshopmysql.c5eo4uy8mys1.us-west-2.rds.amazonaws.com" + - name: CONNECTIONS + value: "1" + - name: SLEEP_TIMEOUT + value: "260" + command: ["/bin/bash", "-c"] + args: + - | + for ((i=1; i<=$CONNECTIONS; i++)); do + MYSQL_PWD="$MYSQL_PASSWORD" mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -N -s -e "SELECT SLEEP(${SLEEP_TIMEOUT});" & + done + while true; do sleep 5; done diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/runbook-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml similarity index 90% rename from codebundles/rds-mysql-conn-count/tests/runbook/runbook-deployment.yaml rename to codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml index cc9c16e..1c77673 100644 --- a/codebundles/rds-mysql-conn-count/tests/runbook/runbook-deployment.yaml +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml @@ -18,13 +18,13 @@ spec: command: - "bash" - "-c" - - "ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot && while true; do sleep 5; done" + - "ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot && ls -R /robot_logs && while true; do sleep 5; done" ports: - containerPort: 3000 env: - name: MYSQL_USER value: "admin" - - name: MYSQL_PASSWORD_ENV + - name: MYSQL_PASSWORD value: "docdb3421z" - name: MYSQL_HOST value: "robotshopmysql.c5eo4uy8mys1.us-west-2.rds.amazonaws.com" diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml new file mode 100644 index 0000000..d0766ac --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: rds-mysql-connection-count-runbook-svc +spec: + selector: + app: rds-mysql-connection-count-runbook + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 + type: ClusterIP diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh new file mode 100755 index 0000000..44bd5a4 --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Prerequisites +# 1) Please login to ecr using this command: aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin + +# Remove existing port-forward +kill -9 $(ps -ef | grep port-forward | awk 'NR==1 {print $2}') + +# Delete old resources +kubectl delete -f ./create-mysql-sleep-conn-deployment.yaml --ignore-not-found=true +kubectl delete -f ./runbook-svc.yaml --ignore-not-found=true +kubectl delete -f ./runbook-deployment.yaml --ignore-not-found=true + +# Create sleep connections +kubectl apply -f ./create-mysql-sleep-conn-deployment.yaml +kubectl wait --for=condition=Ready pod -l app=create-mysql-sleep-connection + +# Run runbook to kill the sleep connections +kubectl apply -f ./runbook-svc.yaml +kubectl apply -f ./runbook-deployment.yaml +kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-runbook + +# port-forward rds-mysql-connection-count-runbook-svc +# kubectl port-forward svc/rds-mysql-connection-count-runbook-svc 3000:3000 + + From 74d8bd16b96ebe03bbc9ce9f5fcc38a218c04021 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Fri, 2 Feb 2024 16:01:52 +0530 Subject: [PATCH 14/19] rds-mysql-connection-count sli dev-cluster test: add sli-svc and update test.sh --- .../tests/sli/dev-cluster/sli-svc.yaml | 12 ++++++++++++ .../tests/sli/dev-cluster/test.sh | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml mode change 100644 => 100755 codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml new file mode 100644 index 0000000..3b10598 --- /dev/null +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: rds-mysql-connection-count-sli-svc +spec: + selector: + app: rds-mysql-connection-count-sli + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 + type: ClusterIP diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh old mode 100644 new mode 100755 index 95d18e5..cbbb8ee --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh @@ -1,9 +1,19 @@ #!/bin/bash +# Remove existing port-forward +kill -9 $(ps -ef | grep port-forward | awk 'NR==1 {print $2}') + +# Remove old resources +kubectl delete -f sli-deployment.yaml +kubectl delete -f ./sli-svc.yaml + # Deploy SLI test deployment kubectl apply -f sli-deployment.yaml +kubectl apply -f ./sli-svc.yaml + # Exposes SLI test deployment +kubectl port-forward svc/rds-mysql-connection-count-sli-svc 3000:3000 & ## Show browser URLs -echo -echo \ No newline at end of file +printf "\n Open Status page http://localhost:3000/" +printf "\n See logs http://localhost:3000/rds-mysql-conn-count/sli-log.html\n" \ No newline at end of file From b69cf4685c692c771524441544ea32e0a717729c Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Mon, 5 Feb 2024 12:15:28 +0530 Subject: [PATCH 15/19] update deployment name and env var name in sli-deployment.yaml --- .../tests/sli/dev-cluster/sli-deployment.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml index 89da4a4..98647e7 100644 --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: rds-mysql-connection-count + name: rds-mysql-connection-count-sli spec: replicas: 1 selector: @@ -22,7 +22,7 @@ spec: ports: - containerPort: 3000 env: - - name: ENV_PROMETHEUS_HOST + - name: PROMETHEUS_URL value: "http://ab916f39fadce498ead455d91e808053-1900228415.us-west-2.elb.amazonaws.com/prometheus/api/v1" - - name: ENV_QUERY + - name: QUERY value: "aws_rds_database_connections_average{dimension_DBInstanceIdentifier=\"robotshopmysql\"} > 1" \ No newline at end of file From 8d6da1a75575ad990a88434ea1fb99de23570f95 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Mon, 5 Feb 2024 12:53:35 +0530 Subject: [PATCH 16/19] remove svc from sli and runbook and update test.sh script --- .../create-mysql-sleep-conn-deployment.yaml | 2 +- .../runbook/dev-cluster/runbook-svc.yaml | 12 ------- .../tests/runbook/dev-cluster/test.sh | 34 +++++++++++++------ .../tests/sli/dev-cluster/sli-svc.yaml | 12 ------- .../tests/sli/dev-cluster/test.sh | 22 ++++++++---- 5 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml delete mode 100644 codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml index 76356fc..edbeb0d 100644 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/create-mysql-sleep-conn-deployment.yaml @@ -23,7 +23,7 @@ spec: - name: MYSQL_HOST value: "robotshopmysql.c5eo4uy8mys1.us-west-2.rds.amazonaws.com" - name: CONNECTIONS - value: "1" + value: "30" - name: SLEEP_TIMEOUT value: "260" command: ["/bin/bash", "-c"] diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml deleted file mode 100644 index d0766ac..0000000 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-svc.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: rds-mysql-connection-count-runbook-svc -spec: - selector: - app: rds-mysql-connection-count-runbook - ports: - - protocol: TCP - port: 3000 - targetPort: 3000 - type: ClusterIP diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh index 44bd5a4..780990f 100755 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh @@ -2,25 +2,39 @@ # Prerequisites # 1) Please login to ecr using this command: aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin +# 2) Build and Push the image to ecr and update image in runbook-deployment.yaml + +NS=codebundles + +kubectl create ns ${NS} --dry-run=client -o yaml | kubectl apply -f - # Remove existing port-forward -kill -9 $(ps -ef | grep port-forward | awk 'NR==1 {print $2}') +process_id=$(ps -ef | grep '[p]ort-forward' | awk '{print $2}') + +if [ -z "$process_id" ]; then + echo "No process found with the name 'port-forward'." +else + echo "Killing process with PID: $process_id" + kill -9 $process_id +fi # Delete old resources -kubectl delete -f ./create-mysql-sleep-conn-deployment.yaml --ignore-not-found=true -kubectl delete -f ./runbook-svc.yaml --ignore-not-found=true -kubectl delete -f ./runbook-deployment.yaml --ignore-not-found=true +kubectl delete -f ./create-mysql-sleep-conn-deployment.yaml --ignore-not-found=true -n ${NS} +kubectl delete -f ./runbook-deployment.yaml --ignore-not-found=true -n ${NS} # Create sleep connections -kubectl apply -f ./create-mysql-sleep-conn-deployment.yaml -kubectl wait --for=condition=Ready pod -l app=create-mysql-sleep-connection +kubectl apply -f ./create-mysql-sleep-conn-deployment.yaml -n ${NS} +kubectl wait --for=condition=Ready pod -l app=create-mysql-sleep-connection -n ${NS} # Run runbook to kill the sleep connections -kubectl apply -f ./runbook-svc.yaml -kubectl apply -f ./runbook-deployment.yaml -kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-runbook +kubectl apply -f ./runbook-deployment.yaml -n ${NS} +kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-runbook --timeout 2m0s -n ${NS} # port-forward rds-mysql-connection-count-runbook-svc -# kubectl port-forward svc/rds-mysql-connection-count-runbook-svc 3000:3000 +kubectl port-forward deploy/rds-mysql-connection-count-runbook 3000:3000 -n ${NS} & + +## Show browser URLs +printf "\n Open Status page http://localhost:3000/" +printf "\n See logs http://localhost:3000/rds-mysql-conn-count/runbook-log.html" diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml deleted file mode 100644 index 3b10598..0000000 --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-svc.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: rds-mysql-connection-count-sli-svc -spec: - selector: - app: rds-mysql-connection-count-sli - ports: - - protocol: TCP - port: 3000 - targetPort: 3000 - type: ClusterIP diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh index cbbb8ee..6484985 100755 --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh @@ -1,18 +1,28 @@ #!/bin/bash +NS=codebundles + +kubectl create ns ${NS} --dry-run=client -o yaml | kubectl apply -f - + # Remove existing port-forward -kill -9 $(ps -ef | grep port-forward | awk 'NR==1 {print $2}') +process_id=$(ps -ef | grep '[p]ort-forward' | awk '{print $2}') + +if [ -z "$process_id" ]; then + echo "No process found with the name 'port-forward'." +else + echo "Killing process with PID: $process_id" + kill -9 $process_id +fi # Remove old resources -kubectl delete -f sli-deployment.yaml -kubectl delete -f ./sli-svc.yaml +kubectl delete -f sli-deployment.yaml --ignore-not-found=true -n ${NS} # Deploy SLI test deployment -kubectl apply -f sli-deployment.yaml -kubectl apply -f ./sli-svc.yaml +kubectl apply -f sli-deployment.yaml -n ${NS} +kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-sli --timeout 2m0s -n ${NS} # Exposes SLI test deployment -kubectl port-forward svc/rds-mysql-connection-count-sli-svc 3000:3000 & +kubectl port-forward deploy/rds-mysql-connection-count-sli 3000:3000 -n ${NS} & ## Show browser URLs printf "\n Open Status page http://localhost:3000/" From 4963cce00b89c5a7f915d59d410833ead9267211 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Mon, 5 Feb 2024 14:26:03 +0530 Subject: [PATCH 17/19] fix port-forward issue by removing command from sli and runbook deployment --- .../tests/runbook/dev-cluster/runbook-deployment.yaml | 4 ---- .../tests/runbook/dev-cluster/test.sh | 4 +++- .../tests/sli/dev-cluster/sli-deployment.yaml | 4 ---- .../rds-mysql-conn-count/tests/sli/dev-cluster/test.sh | 8 +++++++- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml index 1c77673..cfa4a7b 100644 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/runbook-deployment.yaml @@ -15,10 +15,6 @@ spec: containers: - name: rds-mysql-connection-count-runbook image: 590183940259.dkr.ecr.us-west-2.amazonaws.com/runwhen:latest - command: - - "bash" - - "-c" - - "ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot && ls -R /robot_logs && while true; do sleep 5; done" ports: - containerPort: 3000 env: diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh index 780990f..43f4590 100755 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh @@ -4,7 +4,7 @@ # 1) Please login to ecr using this command: aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin # 2) Build and Push the image to ecr and update image in runbook-deployment.yaml -NS=codebundles +NS=runwhen kubectl create ns ${NS} --dry-run=client -o yaml | kubectl apply -f - @@ -30,6 +30,8 @@ kubectl wait --for=condition=Ready pod -l app=create-mysql-sleep-connection -n $ kubectl apply -f ./runbook-deployment.yaml -n ${NS} kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-runbook --timeout 2m0s -n ${NS} +kubectl exec deploy/rds-mysql-connection-count-runbook -n ${NS} -- ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot + # port-forward rds-mysql-connection-count-runbook-svc kubectl port-forward deploy/rds-mysql-connection-count-runbook 3000:3000 -n ${NS} & diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml index 98647e7..c4c3987 100644 --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/sli-deployment.yaml @@ -15,10 +15,6 @@ spec: containers: - name: rds-mysql-connection-count-sli image: 590183940259.dkr.ecr.us-west-2.amazonaws.com/runwhen:latest - command: - - "bash" - - "-c" - - "ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot && while true; do sleep 5; done" ports: - containerPort: 3000 env: diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh index 6484985..e64c9c3 100755 --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh @@ -1,6 +1,10 @@ #!/bin/bash -NS=codebundles +# Prerequisites +# 1) Please login to ecr using this command: aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin +# 2) Build and Push the image to ecr and update image in sli-deployment.yaml + +NS=runwhen kubectl create ns ${NS} --dry-run=client -o yaml | kubectl apply -f - @@ -21,6 +25,8 @@ kubectl delete -f sli-deployment.yaml --ignore-not-found=true -n ${NS} kubectl apply -f sli-deployment.yaml -n ${NS} kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-sli --timeout 2m0s -n ${NS} +kubectl exec deploy/rds-mysql-connection-count-sli -n ${NS} -- ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot + # Exposes SLI test deployment kubectl port-forward deploy/rds-mysql-connection-count-sli 3000:3000 -n ${NS} & From f2a91850cb977c597925ffe9bad0c0153a99ab83 Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Mon, 5 Feb 2024 14:58:34 +0530 Subject: [PATCH 18/19] fix rds-mysql-connection-count-sli port-forward process kill --- .../tests/sli/dev-cluster/test.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh index e64c9c3..9c8628f 100755 --- a/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/sli/dev-cluster/test.sh @@ -5,16 +5,18 @@ # 2) Build and Push the image to ecr and update image in sli-deployment.yaml NS=runwhen +PF_PORT=3001 +SLI_NAME=rds-mysql-connection-count-sli kubectl create ns ${NS} --dry-run=client -o yaml | kubectl apply -f - # Remove existing port-forward -process_id=$(ps -ef | grep '[p]ort-forward' | awk '{print $2}') +process_id=$(ps -ef | grep 'port-forward' | grep "${SLI_NANE}" | grep "${PF_PORT}" | awk '{print $2}') if [ -z "$process_id" ]; then - echo "No process found with the name 'port-forward'." + echo "No ${SLI_NAME} port-forward process found." else - echo "Killing process with PID: $process_id" + echo "Killing ${SLI_NAME} port-forward with PID: $process_id" kill -9 $process_id fi @@ -23,13 +25,13 @@ kubectl delete -f sli-deployment.yaml --ignore-not-found=true -n ${NS} # Deploy SLI test deployment kubectl apply -f sli-deployment.yaml -n ${NS} -kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-sli --timeout 2m0s -n ${NS} +kubectl wait --for=condition=Ready pod -l app=${SLI_NAME} --timeout 2m0s -n ${NS} -kubectl exec deploy/rds-mysql-connection-count-sli -n ${NS} -- ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot +kubectl exec deploy/${SLI_NAME} -n ${NS} -- ro /app/codecollection/codebundles/rds-mysql-conn-count/sli.robot # Exposes SLI test deployment -kubectl port-forward deploy/rds-mysql-connection-count-sli 3000:3000 -n ${NS} & +kubectl port-forward deploy/${SLI_NAME} ${PF_PORT}:3000 -n ${NS} & ## Show browser URLs -printf "\n Open Status page http://localhost:3000/" -printf "\n See logs http://localhost:3000/rds-mysql-conn-count/sli-log.html\n" \ No newline at end of file +printf "\n Open Status page http://localhost:${PF_PORT}/" +printf "\n See logs http://localhost:${PF_PORT}/rds-mysql-conn-count/sli-log.html\n" \ No newline at end of file From b75afff1e6c6bf1ecb9961b0b5d40b506441e4ff Mon Sep 17 00:00:00 2001 From: saurabh3460 Date: Mon, 5 Feb 2024 15:07:57 +0530 Subject: [PATCH 19/19] fix rds-mysql-connection-count-runbook port-forward process kill --- .../tests/runbook/dev-cluster/test.sh | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh index 43f4590..cf29063 100755 --- a/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh +++ b/codebundles/rds-mysql-conn-count/tests/runbook/dev-cluster/test.sh @@ -5,16 +5,18 @@ # 2) Build and Push the image to ecr and update image in runbook-deployment.yaml NS=runwhen +PF_PORT=3002 +RUNBOOK_NAME=rds-mysql-connection-count-runbook kubectl create ns ${NS} --dry-run=client -o yaml | kubectl apply -f - # Remove existing port-forward -process_id=$(ps -ef | grep '[p]ort-forward' | awk '{print $2}') +process_id=$(ps -ef | grep 'port-forward' | grep "${RUNBOOK_NAME}" | grep "${PF_PORT}" | awk '{print $2}') if [ -z "$process_id" ]; then - echo "No process found with the name 'port-forward'." + echo "No ${RUNBOOK_NAME} port-forward process found." else - echo "Killing process with PID: $process_id" + echo "Killing ${RUNBOOK_NAME} port-forward with PID: $process_id" kill -9 $process_id fi @@ -28,15 +30,15 @@ kubectl wait --for=condition=Ready pod -l app=create-mysql-sleep-connection -n $ # Run runbook to kill the sleep connections kubectl apply -f ./runbook-deployment.yaml -n ${NS} -kubectl wait --for=condition=Ready pod -l app=rds-mysql-connection-count-runbook --timeout 2m0s -n ${NS} +kubectl wait --for=condition=Ready pod -l app=${RUNBOOK_NAME} --timeout 2m0s -n ${NS} -kubectl exec deploy/rds-mysql-connection-count-runbook -n ${NS} -- ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot +kubectl exec deploy/${RUNBOOK_NAME} -n ${NS} -- ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.robot -# port-forward rds-mysql-connection-count-runbook-svc -kubectl port-forward deploy/rds-mysql-connection-count-runbook 3000:3000 -n ${NS} & +# Exposes runbook test deployment +kubectl port-forward deploy/${RUNBOOK_NAME} ${PF_PORT}:3000 -n ${NS} & ## Show browser URLs -printf "\n Open Status page http://localhost:3000/" -printf "\n See logs http://localhost:3000/rds-mysql-conn-count/runbook-log.html" +printf "\n Open Status page http://localhost:${PF_PORT}/" +printf "\n See logs http://localhost:${PF_PORT}/rds-mysql-conn-count/runbook-log.html\n"