Skip to content

Commit

Permalink
Merge pull request #11 from infracloudio/fix/rds
Browse files Browse the repository at this point in the history
Fixes secrets and environment variables
  • Loading branch information
Hashfyre authored Feb 5, 2024
2 parents b55b5f2 + b75afff commit e9c2f37
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ __pycache__
output.xml
log.html
report.html
test/sre-stack/*
dev-cluster/sre-stack/*
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
GIT_TLD=$(shell git rev-parse --show-toplevel)
include $(GIT_TLD)/test/sre-stack/.env
SRE_STACK_DIR := $(GIT_TLD)/dev-cluster/sre-stack
include $(DEV_CLUSTER_SUBMODULE_PATH)/.env
include $(GIT_TLD)/.env
include $(GIT_TLD)/test/sre-stack/makefile
SRE_STACK_DIR := $(GIT_TLD)/test/sre-stack
RUNWHEN_SETUP_SCRIPT_PATH=setup/runwhen-local/setup.sh
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:
Expand Down
11 changes: 0 additions & 11 deletions codebundles/hello_world/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions codebundles/hello_world/sli.robot

This file was deleted.

11 changes: 0 additions & 11 deletions codebundles/hello_world_taskset/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions codebundles/hello_world_taskset/runbook.robot

This file was deleted.

12 changes: 1 addition & 11 deletions codebundles/rds-mysql-conn-count/kill-mysql-sleep-processes.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 3 additions & 4 deletions codebundles/rds-mysql-conn-count/runbook.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Library RW.CLI

Suite Setup Suite Initialization

*** Variables ***
${MYSQL_PASSWORD_ENV} %{MYSQL_PASSWORD_ENV}

*** Tasks ***
Run Bash File
Expand All @@ -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}
Expand All @@ -41,12 +40,12 @@ 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
... pattern=\w*
... example=shipping

Set Suite Variable
... ${env} {"MYSQL_USER":"${MYSQL_USER}", "MYSQL_PASSWORD":"${MYSQL_PASSWORD_ENV}", "MYSQL_HOST":"${MYSQL_HOST}", "PROCESS_USER":"${PROCESS_USER}"}
... ${env} {"MYSQL_USER":"${MYSQL_USER}", "MYSQL_HOST":"${MYSQL_HOST}", "PROCESS_USER":"${PROCESS_USER}"}
36 changes: 14 additions & 22 deletions codebundles/rds-mysql-conn-count/runwhen-config/runbook.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions codebundles/rds-mysql-conn-count/runwhen-config/sli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 5 additions & 16 deletions codebundles/rds-mysql-conn-count/sli.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,13 +15,7 @@ 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
RW.Core.Import User Variable PROMETHEUS_URL
... type=string
... description=The prometheus endpoint to perform requests against.
... pattern=\w*
Expand All @@ -33,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]
Expand Down Expand Up @@ -66,16 +57,14 @@ 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=${ENV_PROMETHEUS_HOST}
... query=${ENV_QUERY}
... api_url=${PROMETHEUS_URL}
... query=${QUERY}
... step=${STEP}
... target_service=${CURL_SERVICE}
${data}= Set Variable ${rsp["data"]}
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions codebundles/rds-mysql-conn-count/test/scripts/local-docker.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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: "30"
- 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
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
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"
- "-c"
- "ro /app/codecollection/codebundles/rds-mysql-conn-count/runbook.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"
- 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"
Expand Down
Loading

0 comments on commit e9c2f37

Please sign in to comment.