Skip to content

Commit

Permalink
- Update deployment to hook grafana into rds
Browse files Browse the repository at this point in the history
  • Loading branch information
elipe17 committed Oct 9, 2024
1 parent 1cd19cb commit 0b98845
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tdrs-backend/plg/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ help() {
echo "a Deploy the entire PLG stack."
echo "p Deploy a postgres exporter. Requires -u and -d"
echo "u Requires -p. The database URI the exporter should connect with."
echo "d Requires -p. The Cloud Foundry service name of the RDS instance."
echo "d The Cloud Foundry service name of the RDS instance. Should be included with all deployments."
echo
}

Expand Down Expand Up @@ -39,9 +39,12 @@ deploy_grafana() {
APP_NAME="grafana"
DATASOURCES="datasources.yml"
cp datasources.template.yml $DATASOURCES
MANIFEST=manifest.tmp.yml
cp manifest.yml $MANIFEST

yq eval -i ".datasources[0].url = \"http://prometheus.apps.internal:8080\"" $DATASOURCES
yq eval -i ".datasources[1].url = \"http://loki.apps.internal:8080\"" $DATASOURCES
yq eval -i ".applications[0].services[0] = \"$1\"" $MANIFEST

cf push --no-route -f manifest.yml -t 180 --strategy rolling
# cf map-route $APP_NAME apps.internal --hostname $APP_NAME
Expand All @@ -52,6 +55,7 @@ deploy_grafana() {
cf add-network-policy $APP_NAME prometheus --protocol tcp --port 8080
cf add-network-policy $APP_NAME loki --protocol tcp --port 8080
rm $DATASOURCES
rm $MANIFEST
popd
}

Expand All @@ -69,6 +73,14 @@ deploy_loki() {
popd
}

err_help_exit() {
echo $1
echo
help
popd
exit
}

while getopts ":hap:u:d:" option; do
case $option in
h) # display Help
Expand All @@ -81,7 +93,7 @@ while getopts ":hap:u:d:" option; do
DEPLOY="pg-exporter";;
u) # Bind a Postgres exporter to $DB_URI
DB_URI=$OPTARG;;
d) # Bind a Postgres exporter to $DB_SERVICE_NAME
d) # Bind a Postgres exporter or Grafana to $DB_SERVICE_NAME
DB_SERVICE_NAME=$OPTARG;;
\?) # Invalid option
echo "Error: Invalid option"
Expand All @@ -95,18 +107,17 @@ if [ "$#" -eq 0 ]; then
fi

pushd "$(dirname "$0")"
if [ "$DB_URI" == "" ] || [ "$DB_SERVICE_NAME" == "" ]; then
err_help_exit "Error: you must include a database service name."
fi
if [ "$DEPLOY" == "plg" ]; then
deploy_prometheus
deploy_loki
deploy_grafana
fi
if [ "$DEPLOY" == "pg-exporter" ]; then
if [ "$DB_URI" == "" ] || [ "$DB_SERVICE_NAME" == "" ]; then
echo "Error: you must also pass -u and -d when deploying a postgres exporter."
echo
help
popd
exit
if [ "$DB_URI" == "" ]; then
err_help_exit "Error: you must provide a database uri when deploying a postgres exporter."
fi
deploy_pg_exporter $ENV $DB_URI $DB_SERVICE_NAME
fi
Expand Down
2 changes: 2 additions & 0 deletions tdrs-backend/plg/grafana/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ applications:
cfg:default.paths.provisioning="$GF_PATHS_PROVISIONING"
buildpacks:
- https://github.com/cloudfoundry/binary-buildpack
services:
- {{ rds_service }}

0 comments on commit 0b98845

Please sign in to comment.