Commit c036985f authored by Waqas Riaz's avatar Waqas Riaz

resolved merge conflicts

parents 99228fa2 29deaced
Pipeline #4178 passed with stages
in 12 seconds
stages:
- build
- deploy
build_job:
stage: build
- build_dashboards
- deploy_dashboards
- build_alerts
- deploy_alerts
build_dashboards_job:
stage: build_dashboards
before_script:
- curl --version
- jsonnet --version
- tar --version
script:
- echo "Starting script for deploying to Jfrog"
- existing_files=$(find . -type f -name "*.jsonnet" ! -path "./grafonnet-lib/*" | xargs -I{} basename {} )
- last_commit_files=$(git diff --name-only HEAD^ HEAD)
- files_list=$(comm -12 <(echo "${last_commit_files[@]}" | tr ' ' '\n' | sort) <(echo "${existing_files[@]}" | tr ' ' '\n' | sort))
- echo "Creating directory"
- mkdir grafonnet
- ls
- |
for json_file in ${files_list[@]};
do
echo $json_file
filename=$(basename -- "$json_file")
filename="${filename%.*}"
echo $filename
JSONNET_PATH=grafonnet-lib \
jsonnet $json_file > grafonnet/$filename.json
done
- tar -cvzf grafonnet.tar.gz grafonnet/
- echo "Uploading to $ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/grafonnet.tar.gz"
- curl -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS -T grafonnet.tar.gz "$ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/grafonnet.tar.gz"
# brew install jsonnet
# jsonnet -v
script:
- echo "Building updated dashboards"
- scripts/build_dashboards.sh
- echo "Promoting json artifacts to artifactory"
- scripts/promote_dashboard_artifacts.sh
tags:
- ci
- ci
only:
- master
deploy_job:
stage: deploy
refs:
- master
changes:
- dashboards/*
build_alerts_job:
stage: build_alerts
before_script:
- curl --version
- jsonnet --version
- tar --version
script:
- echo "Building updated alerts"
- scripts/build_alerts.sh
- echo "Promoting json artifacts to artifactory"
- scripts/promote_alerts_artifacts.sh
only:
refs:
- master
changes:
- alerts/*
- alerts-config/*
tags:
- ci
deploy_dashboards_job:
stage: deploy_dashboards
before_script:
- curl --version
- jq --version
- tar --version
script:
- mkdir -p build/$CI_BUILD_ID
- cd build/$CI_BUILD_ID
- echo "Downloading artifact from $ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/grafonnet.tar.gz"
- curl -O -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS "$ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/grafonnet.tar.gz"
- ls -larth
- pwd
- tar -xzvf grafonnet.tar.gz
- cd grafonnet
- ls -larth
- |
for FILE in *;
do
echo "$FILE \n";
DASHBOARD="{\"dashboard\": $(jq . $FILE), \"overwrite\": true}"
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$DASHBOARD" \
$GRAFANA_URL/api/dashboards/db
echo "\n"
done
#grafonnet.tar.gz
- echo "Deploying dasbhoards"
- scripts/deploy_dashboards.sh
only:
refs:
- master
changes:
- dashboards/*
tags:
- cd
only:
- master
\ No newline at end of file
deploy_alerts_job:
stage: deploy_alerts
before_script:
- curl --version
- jq --version
- tar --version
script:
- echo "Deploying alerts"
- scripts/deploy_alerts.sh
only:
refs:
- master
changes:
- alerts/*
- alerts-config/*
tags:
- cd
\ No newline at end of file
local alert_contact = import '../alerts-config/alert_contact.libsonnet';
alert_contact.new(uid="17126128",
name="test_rizwan_con-2",
type='email',
address='rizwanshakoor50@gmail.com',
singleEmail=false,
disableResolveMessage=false
)
local alert_test = import '../alerts-config/alert_rule.libsonnet';
local alert_data = import '../alerts-config/alert_model.libsonnet';
local alert_model_data = import '../alerts-config/alert_condition.libsonnet';
local my_alert_condition_A = alert_model_data.new(
evaluatorParams=null,
evaluatorType='gt',
operatorType='and',
queryRefId='B',
reducerParams=[],
reducerType='last',
);
local my_alert_condition_B = alert_model_data.new(
evaluatorParams=10,
evaluatorType='lt',
operatorType='and',
queryRefId='C',
queryTimeStart=null,
queryTimeEnd=null,
reducerParams=[],
reducerType='last',
);
alert_test.new(id=331,
uid='test_uid12344',
orgID=1,
folderUID='6G7_MULVz',
ruleGroup='my_alert-dashboards',
title='alert-rule_331',
condition='B',
updated="2023-04-09T15:52:13+05:00",
noDataState="NoData",
panelId="2",
execErrState="Error",
isPaused=false,
dashboardUid="ABC12345",
interval='2m',
annotationDesc="Alert is Triggering .. Huhhhh!!!!!",
annotationSummary="This is Test Rule"
).addAlertCondition(alert_data.new(
refId="A",
from=600,
to=0,
datasourceUid="oQQKKPY4z",
editorMode="code",
expr="prometheus_http_request_duration_seconds_count",
hide="false",
intervalMs=2000,
legendFormat="__auto",
maxDataPoints=43200,
range=true
)
).addAlertCondition(alert_data.new(
refId="B",
from=600,
to=0,
datasourceUid="__expr__",
expression="A",
hide=false,
intervalMs=1000,
maxDataPoints=43200,
reducer='max',
type="reduce",
modelCondition=my_alert_condition_A
)
).addAlertCondition(alert_data.new(
refId="C",
from=600,
to=0,
datasourceUid="__expr__",
expression="B",
hide=false,
intervalMs=1000,
maxDataPoints=43200,
type="threshold",
modelCondition=my_alert_condition_B
)
) + {
"for":'5m'
}
\ No newline at end of file
local grafana = import 'grafonnet/grafana.libsonnet';
grafana.dashboard.new(
title='My dashboard',
editable=true,
......
local grafana = import 'grafonnet-lib/grafonnet/grafana.libsonnet';
local grafana = import 'grafonnet/grafana.libsonnet';
local barGaugePanel = grafana.barGaugePanel;
local dashboard = grafana.dashboard;
local row = grafana.row;
......
#!/bin/bash
# Extract the version number from VERSION.txt
VERSION=$(cat version.txt)
echo "Current version is ${VERSION}"
# Use a regular expression to extract the major, minor, and patch numbers
if [[ ${VERSION} =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
else
echo "Could not extract version number from VERSION.txt"
exit 1
fi
# Increment the patch number by 1
PATCH=$((${PATCH}+1))
# Construct the new version string
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "New version is ${NEW_VERSION}"
# Write the new version string back to VERSION.txt
echo "${NEW_VERSION}" > version.txt
{
"version": 1,
"dependencies": [],
"legacyImports": true
}
# JSONNET_PATH=grafonnet-lib \
# jsonnet mssql.jsonnet > mssql.json
echo "Starting script for deploying to Jfrog"
files_list=$(find . -path ./grafonnet-lib -prune -o -name '*.jsonnet')
echo "Creating directory"
mkdir grafonnet
while IFS= read -r jsonnet_file;
do
echo $jsonnet_file
filename=$(basename -- "$jsonnet_file")
filename="${filename%.*}"
echo $filename
JSONNET_PATH=grafonnet-lib \
jsonnet $jsonnet_file > grafonnet/$filename.json
done <<< "$files_list"
tar -cvzf grafonnet.tar.gz grafonnet/
version=$(cat version.txt)
echo $version + 0.1 | bc > version.txt
version=$(cat version.txt)
#curl -u ${{ secrets.JFROG_USER }} -T grafonnet.tar.gz "https://grafanaascode.jfrog.io/artifactory/temp123-generic/grafonnet/$version/grafonnet.tar.gz"
#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
# payload="{\"dashboard\": $(jq . elk.json), \"overwrite\": true}"
# curl -X POST $BASIC_AUTH \
# -H 'Content-Type: application/json' \
# -d "${payload}" \
# "http://admin:admin@localhost:3000/api/dashboards/db"
# https://grafanaascode.jfrog.io/artifactory/temp123-generic/grafonnet/0.1.0/elk.json
\ No newline at end of file
#!/bin/bash
ALERTS_JSONNET_PATH=alerts
ALERTS_BUILD_PATH=build/alerts
ALERTS_TAR_NAME=alerts
CURRENT_DIR=$PWD
mkdir -p ${ALERTS_BUILD_PATH}
echo "Cleaning up previous builds"
rm -rf ${ALERTS_BUILD_PATH}/*.json
LAST_COMMIT_FILES=$(git diff --name-only HEAD^ HEAD ${ALERTS_JSONNET_PATH} | xargs -I{} basename {} )
echo "last commit files $LAST_COMMIT_FILES"
for json_file in ${LAST_COMMIT_FILES[@]};
do
echo "$json_file"
filename=$(basename -- "${json_file}")
filename="${filename%.*}"
JSONNET_PATH=../grafonnet-lib \
jsonnet ${ALERTS_JSONNET_PATH}/${json_file} > ${ALERTS_BUILD_PATH}/${filename}.json
echo "Created new json at ${ALERTS_BUILD_PATH}/${filename}.json"
done
ls -larth ${ALERTS_BUILD_PATH}
cd ${CURRENT_DIR}
\ No newline at end of file
#!/bin/bash
set -e
CURRENT_DIR=$PWD
Green='\033[1;32m'
NC='\033[0m'
function build_alerts {
ALERTS_JSONNET_PATH=alerts
ALERTS_BUILD_PATH=build/alerts
ALERTS_TAR_NAME=alerts
mkdir -p ${ALERTS_BUILD_PATH}
echo "Cleaning up previous builds"
rm -rf ${ALERTS_BUILD_PATH}/*.json
ALERTS_JSONNETS=$(find ALERTS_JSONNET_PATH -type f -name "*.jsonnet" | xargs -I{} basename {} )
for json_file in ${ALERTS_JSONNETS[@]};
do
echo "$json_file"
filename=$(basename -- "${json_file}")
filename="${filename%.*}"
JSONNET_PATH=../grafonnet-lib \
jsonnet ${ALERTS_JSONNET_PATH}/${json_file} > ${ALERTS_BUILD_PATH}/${filename}.json
echo -e "${Green}Created new json at ${ALERTS_BUILD_PATH}/${filename}.json${NC}"
done
#ls -larth ${ALERTS_BUILD_PATH}
cd ${CURRENT_DIR}
echo -e "\n${Green}Alerts build Successfully${NC}"
echo "JSON files in ${ALERTS_BUILD_PATH}"
}
function build_dashboards {
DASHBOARDS_JSONNET_PATH=dashboards
DASHBOARDS_BUILD_PATH=build/dashboards
DASHBOARDS_TAR_NAME=dashboards
mkdir -p ${DASHBOARDS_BUILD_PATH}
echo "Cleaning up previous builds"
rm -rf ${DASHBOARDS_BUILD_PATH}/*.json
DASHBOARDS_JSONNETS=$(find ${DASHBOARDS_JSONNET_PATH} -type f -name "*.jsonnet" | xargs -I{} basename {} )
for json_file in ${DASHBOARDS_JSONNETS[@]};
do
echo "$json_file"
filename=$(basename -- "${json_file}")
filename="${filename%.*}"
JSONNET_PATH=grafonnet-lib \
jsonnet ${DASHBOARDS_JSONNET_PATH}/${json_file} > ${DASHBOARDS_BUILD_PATH}/${filename}.json
echo -e "${Green}Created new json at ${DASHBOARDS_BUILD_PATH}/${filename}.json${NC}"
done
#ls -larth ${DASHBOARDS_BUILD_PATH}
cd ${CURRENT_DIR}
echo -e "\n${Green}Dashboards build Successfully${NC}"
echo "JSON files in ${DASHBOARDS_BUILD_PATH}"
}
if [ $1 == "alerts" ]; then
echo "Building only alerts"
build_alerts
elif [ $1 == "dashboards" ]; then
echo "Building only dashboards"
build_dashboards
else
echo "Building All"
build_alerts
build_dashboards
fi
echo -e "\n \t \t ${Green}Build Successful${NC} \n \n JSON files are available in build folder"
#!/bin/bash
DASHBOARDS_JSONNET_PATH=dashboards
DASHBOARDS_BUILD_PATH=build/dashboards
DASHBOARDS_TAR_NAME=dashboards
CURRENT_DIR=$PWD
mkdir -p ${DASHBOARDS_BUILD_PATH}
echo "Cleaning up previous builds"
rm -rf ${DASHBOARDS_BUILD_PATH}/*.json
LAST_COMMIT_FILES=$(git diff --name-only HEAD^ HEAD ${DASHBOARDS_JSONNET_PATH} | xargs -I{} basename {} )
echo "last commit files $LAST_COMMIT_FILES"
for json_file in ${LAST_COMMIT_FILES[@]};
do
echo "$json_file"
filename=$(basename -- "${json_file}")
filename="${filename%.*}"
JSONNET_PATH=grafonnet-lib \
jsonnet ${DASHBOARDS_JSONNET_PATH}/${json_file} > ${DASHBOARDS_BUILD_PATH}/${filename}.json
echo "Created new json at ${DASHBOARDS_BUILD_PATH}/${filename}.json"
done
ls -larth ${DASHBOARDS_BUILD_PATH}
cd ${CURRENT_DIR}
\ No newline at end of file
#!/bin/bash
ALERTS_DEPLOY_DIR=build/$CI_PIPELINE_ID/alerts
ALERTS_TAR_NAME=alerts
CURRENT_DIR=$PWD
mkdir -p ${CURRENT_DIR}/${ALERTS_DEPLOY_DIR}
cd ${CURRENT_DIR}/${ALERTS_DEPLOY_DIR}
echo "Cleaning up previous archives"
rm -rf ${CURRENT_DIR}/${ALERTS_TAR_NAME}.tar.gz
echo "Downloading artifact from $ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${ALERTS_TAR_NAME}.tar.gz"
curl -O -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS "$ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${ALERTS_TAR_NAME}.tar.gz"
ls -larth
pwd
mkdir -p ${CURRENT_DIR}/${ALERTS_TAR_NAME}
tar -xzvf ${ALERTS_TAR_NAME}.tar.gz -C ${CURRENT_DIR}/${DASHBOARD_DEPLOY_DIR}/${ALERTS_TAR_NAME}
cd ${ALERTS_TAR_NAME}
ls -larth
for FILE in *;
do
echo "$FILE \n";
PAYLOAD="$(jq . $FILE)"
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
$GRAFANA_URL/api/v1/provisioning/alert-rules
echo "\n"
done
cd ${CURRENT_DIR}
\ No newline at end of file
#!/bin/bash
DASHBOARD_DEPLOY_DIR=build/$CI_PIPELINE_ID/dashboards
DASHBOARD_TAR_NAME=dashboards
CURRENT_DIR=$PWD
mkdir -p ${CURRENT_DIR}/${DASHBOARD_DEPLOY_DIR}
cd ${CURRENT_DIR}/${DASHBOARD_DEPLOY_DIR}
echo "Cleaning up previous archives"
rm -rf ${CURRENT_DIR}/${DASHBOARD_DEPLOY_DIR}/*
echo "Downloading artifact from $ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${DASHBOARD_TAR_NAME}.tar.gz"
curl -O -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS "$ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${DASHBOARD_TAR_NAME}.tar.gz"
ls -larth
pwd
mkdir -p ${DASHBOARD_TAR_NAME}
tar -xzvf ${DASHBOARD_TAR_NAME}.tar.gz -C ${CURRENT_DIR}/${DASHBOARD_DEPLOY_DIR}/${DASHBOARD_TAR_NAME}
cd ${DASHBOARD_TAR_NAME}
ls -larth
for FILE in *;
do
echo "$FILE \n";
DASHBOARD="{\"dashboard\": $(jq . $FILE), \"overwrite\": true}"
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$DASHBOARD" \
$GRAFANA_URL/api/dashboards/db
echo "\n"
done
cd ${CURRENT_DIR}
\ No newline at end of file
#!/bin/bash
ALERTS_BUILD_PATH=build/alerts
ALERTS_TAR_NAME=alerts
ARCHIVE_PATH=build/archive
CURRENT_DIR=$PWD
mkdir -p ${CURRENT_DIR}/${ARCHIVE_PATH}
echo "Cleaning up previous archives"
rm -rf ${CURRENT_DIR}/${ARCHIVE_PATH}/${ALERTS_TAR_NAME}.tar.gz
cd ${ALERTS_BUILD_PATH}
count_file=`ls -1 *.json 2>/dev/null | wc -l`
echo "${count_file} json files found at `pwd`"
if [ $count_file != 0 ]
then
tar -cvzf ${CURRENT_DIR}/${ARCHIVE_PATH}/${ALERTS_TAR_NAME}.tar.gz *.json
ls -larth ${CURRENT_DIR}/${ARCHIVE_PATH}
echo "Uploading to $ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${ALERTS_TAR_NAME}.tar.gz"
curl -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS -T ${CURRENT_DIR}/${ARCHIVE_PATH}/${ALERTS_TAR_NAME}.tar.gz "$ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${ALERTS_TAR_NAME}.tar.gz"
echo "Artifact Uploaded Successfully"
else
echo "ERROR: No json files found at ${ALERTS_BUILD_PATH}. Build process Failed"
ls -larth ${ALERTS_BUILD_PATH}
exit 1
fi
cd ${CURRENT_DIR}
\ No newline at end of file
#!/bin/bash
DASHBOARDS_BUILD_PATH=build/dashboards
DASHBOARDS_TAR_NAME=dashboards
ARCHIVE_PATH=build/archive
CURRENT_DIR=$PWD
mkdir -p ${CURRENT_DIR}/${ARCHIVE_PATH}
echo "Cleaning up previous archives"
rm -rf ${CURRENT_DIR}/${ARCHIVE_PATH}/${DASHBOARDS_TAR_NAME}.tar.gz
cd ${DASHBOARDS_BUILD_PATH}
ls -larth
count_file=`ls -1 *.json 2>/dev/null | wc -l`
echo "${count_file} json files found at `pwd`"
if [ $count_file != 0 ]
then
tar -cvzf ${CURRENT_DIR}/${ARCHIVE_PATH}/${DASHBOARDS_TAR_NAME}.tar.gz *.json
ls -larth ${CURRENT_DIR}/${ARCHIVE_PATH}
echo "Uploading to $ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${DASHBOARDS_TAR_NAME}.tar.gz"
curl -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS -T ${CURRENT_DIR}/${ARCHIVE_PATH}/${DASHBOARDS_TAR_NAME}.tar.gz "$ARTIFACTORY_URL/grafonet/$CI_PIPELINE_ID/${DASHBOARDS_TAR_NAME}.tar.gz"
echo "Artifact Uploaded Successfully"
else
echo "ERROR: No json files found at ${DASHBOARDS_BUILD_PATH}. Build process Failed"
ls -larth ${DASHBOARDS_BUILD_PATH}
exit 1
fi
cd ${CURRENT_DIR}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment