-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the GitHub Actions file for prombench.
This commit adds the GitHub Actions file to trigger the benchmarking process for GMP Collector (using the prombench tool). Signed-off-by: saketjajoo <saketjajoo77@gmail.com> Updating the default permissions for GITHUB_TOKEN and setting the COMMENTER as an env variable. Signed-off-by: saketjajoo <saketjajoo77@gmail.com>
- Loading branch information
1 parent
10d972f
commit e5294b1
Showing
1 changed file
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
name: "Run Prombench" | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*-gmp.*' | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
env: | ||
CANCEL_BENCHMARK: "false" | ||
CLUSTER_NAME: "prombench" | ||
COLLECTOR_IMAGE_REPOSITORY: "gke.gcr.io/prometheus-engine/prometheus" | ||
CREATE_CLUSTER: "true" | ||
DASHBOARD_ID: 33755240-08f9-4db9-a86f-839481fd5002 | ||
DISABLE_LOADGEN_QUERIER: "true" | ||
DOMAIN_NAME: "" | ||
GITHUB_ORG: ${{ github.repository_owner }} # GoogleCloudPlatform | ||
GITHUB_REPO: ${{ github.event.repository.name }} # prometheus | ||
GITHUB_STATUS_TARGET_URL: "" | ||
GKE_PROJECT_ID: ${{ secrets.GKE_PROJECT_ID }} | ||
GRAFANA_ADMIN_PASSWORD: admin | ||
LAST_COMMIT_SHA: ${{ github.event.client_payload.LAST_COMMIT_SHA }} | ||
OAUTH_TOKEN: "" | ||
PR_NUMBER: ${{github.event.issue.number}} | ||
PROMBENCH_DOCKER_IMAGE_REPOSITORY: "docker://saketjajoo/prombench:latest" | ||
PROVIDER: gke | ||
RELEASE: ${{ github.event.repository.default_branch }} # e.g. main / release-X.Y.Z-gmp / etc. | ||
SERVICEACCOUNT_CLIENT_EMAIL: ${{ secrets.SERVICEACCOUNT_CLIENT_EMAIL }} | ||
WH_SECRET: "" | ||
ZONE: us-east4-a | ||
|
||
jobs: | ||
benchmark: | ||
if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/prombench') | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
|
||
- name: verify_user | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMMENTER: ${{ github.event.comment.user.login }} | ||
run: | | ||
COMMENTER_PERMISSION=$(curl --silent -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/collaborators/${COMMENTER}/permission | jq --raw-output .permission) | ||
if ! ([ "${COMMENTER_PERMISSION}" == "admin" ] || [ "${COMMENTER_PERMISSION}" == "write" ]) | ||
then | ||
echo "${COMMENTER} does not have admin or write privileges. Therefore cannot execute the benchmark command." | ||
curl --silent -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/issues/${PR_NUMBER}/comments \ | ||
--data '{ "body": "'${COMMENTER}' does not have admin or write privileges. Therefore cannot execute the benchmark command." }' | ||
exit 1 | ||
fi | ||
- uses: 'actions/checkout@v3' | ||
|
||
- id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
uses: 'google-github-actions/auth@v1' | ||
with: | ||
credentials_json: '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}' | ||
|
||
- name: 'Set up Google Cloud SDK' | ||
uses: 'google-github-actions/setup-gcloud@v1' | ||
|
||
|
||
- name: check_benchmark_trigger_action | ||
run: | | ||
GMP_COLLECTOR_TAG=$(echo ${{ github.event.comment.body }} | head -n 1 | awk '{ print $2 }') | ||
if [ "$2" == "cancel" ] | ||
then | ||
echo "Cancelling the benchmark run for PR #${PR_NUMBER}." | ||
CANCEL_BENCHMARK="true" | ||
echo "CANCEL_BENCHMARK=${CANCEL_BENCHMARK}" >> $GITHUB_ENV | ||
else | ||
echo "GMP Collector Tag: ${GMP_COLLECTOR_TAG}" | ||
function get_default_collector_tag() { | ||
DEFAULT_COLLECTOR_TAG=$(gcloud container images list-tags ${COLLECTOR_IMAGE_REPOSITORY} --sort-by=UPDATE_TIME,TAGS | tail -1 | awk '{ print $2 }') | ||
} | ||
if [[ $GMP_COLLECTOR_TAG == '' ]] | ||
then | ||
echo "Since the collector version is missing, the latest one would be used." | ||
get_default_collector_tag | ||
echo "COLLECTOR_RELEASE_VERSION=${DEFAULT_COLLECTOR_TAG}" >> $GITHUB_ENV | ||
export COLLECTOR_RELEASE_VERSION="${DEFAULT_COLLECTOR_TAG}" | ||
else | ||
GCLOUD_TAG=$(gcloud container images list-tags --filter="tags:${GMP_COLLECTOR_TAG}" --format=json ${COLLECTOR_IMAGE_REPOSITORY}) | ||
if [[ "$GCLOUD_TAG" == "[]" ]] | ||
then | ||
echo "The ${COLLECTOR_IMAGE_REPOSITORY} image does not have the ${GMP_COLLECTOR_TAG} tag. Hence, this run will use the default latest tag." | ||
DEFAULT_COLLECTOR_TAG=$(get_default_collector_tag) | ||
echo "COLLECTOR_RELEASE_VERSION=${DEFAULT_COLLECTOR_TAG}" >> $GITHUB_ENV | ||
export COLLECTOR_RELEASE_VERSION="${DEFAULT_COLLECTOR_TAG}" | ||
else | ||
echo "COLLECTOR_RELEASE_VERSION=${GMP_COLLECTOR_TAG}" >> $GITHUB_ENV | ||
export COLLECTOR_RELEASE_VERSION="${GMP_COLLECTOR_TAG}" | ||
fi | ||
fi | ||
echo "The release/base GMP Collector's tag is set to: ${COLLECTOR_RELEASE_VERSION}." | ||
fi | ||
- name: check_cluster_existance | ||
run: | | ||
if RETURN=$(gcloud container clusters describe "${CLUSTER_NAME}" --project="${GKE_PROJECT_ID}" --location="${ZONE}" >/dev/null 2>&1) | ||
then | ||
CREATE_CLUSTER="false" | ||
echo "CREATE_CLUSTER=${CREATE_CLUSTER}" >> $GITHUB_ENV | ||
echo "The cluster (name: ${CLUSTER_NAME}) already exists. Therefore, skipping cluster creation." | ||
else | ||
CREATE_CLUSTER="true" | ||
echo "CREATE_CLUSTER=${CREATE_CLUSTER}" >> $GITHUB_ENV | ||
echo "The cluster (name: ${CLUSTER_NAME}) does not exist, the cluster will get created before creating the nodes and triggering the benchmark process." | ||
fi | ||
- name: cluster_create | ||
if: env.CREATE_CLUSTER == 'true' | ||
uses: ${PROMBENCH_DOCKER_IMAGE_REPOSITORY} | ||
with: | ||
args: make cluster_create; | ||
|
||
- name: cluster_resource_apply | ||
if: env.CREATE_CLUSTER == 'true' | ||
uses: ${PROMBENCH_DOCKER_IMAGE_REPOSITORY} | ||
with: | ||
args: make cluster_resource_apply; | ||
|
||
- name: node_create | ||
if: env.CANCEL_BENCHMARK == 'false' | ||
uses: ${PROMBENCH_DOCKER_IMAGE_REPOSITORY} | ||
with: | ||
args: >- | ||
make clean; | ||
until make all_nodes_deleted; do echo "Waiting for nodepools to be deleted"; sleep 10; done; | ||
make node_create; | ||
- name: node_resource_apply | ||
if: env.CANCEL_BENCHMARK == 'false' | ||
uses: ${PROMBENCH_DOCKER_IMAGE_REPOSITORY} | ||
with: | ||
args: make resource_apply; | ||
|
||
|
||
- name: post_benchmark_dashboard_url_to_pr | ||
if: env.CANCEL_BENCHMARK == 'false' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
MONITORING_DASHBOARD_URL="https://console.cloud.google.com/monitoring/dashboards/builder/${DASHBOARD_ID};duration=PT15M?f.rlabel.cluster_name=${CLUSTER_NAME}&f.rlabel.namespace=prombench-${PR_NUMBER}&f.umlabel.goog-k8s-cluster-name=${CLUSTER_NAME}" | ||
COMMENT_MSG="The benchmark results can be viewed at: ${MONITORING_DASHBOARD_URL}.\n\nTo cancel the benchmark, comment \`/prombench cancel\` on this PR." | ||
curl --silent -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/issues/${PR_NUMBER}/comments \ | ||
--data '{ "body": "'"${COMMENT_MSG}"'" }' | ||
- name: node_delete | ||
if: env.CANCEL_BENCHMARK == 'true' | ||
uses: ${PROMBENCH_DOCKER_IMAGE_REPOSITORY} | ||
with: | ||
args: make clean; |