-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: implement quota check in CI Pipeline to ensure resource availability in supported region for RA #376
Merged
Roopan-Microsoft
merged 3 commits into
main
from
task/ci-pipeline-quota-check-research-assistant
Feb 25, 2025
Merged
ci: implement quota check in CI Pipeline to ensure resource availability in supported region for RA #376
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,97 @@ | ||
#!/bin/bash | ||
|
||
# List of Azure regions to check for quota (update as needed) | ||
REGIONS=("eastus2" "westus" "northcentralus" "uksouth" "francecentral") | ||
|
||
SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}" | ||
GPT_MIN_CAPACITY="${GPT_MIN_CAPACITY}" | ||
TEXT_EMBEDDING_MIN_CAPACITY="${TEXT_EMBEDDING_MIN_CAPACITY}" | ||
AZURE_CLIENT_ID="${AZURE_CLIENT_ID}" | ||
AZURE_TENANT_ID="${AZURE_TENANT_ID}" | ||
AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}" | ||
|
||
# Authenticate using Managed Identity | ||
echo "Authentication using Managed Identity..." | ||
if ! az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"; then | ||
echo "❌ Error: Failed to login using Managed Identity." | ||
exit 1 | ||
fi | ||
|
||
echo "🔄 Validating required environment variables..." | ||
if [[ -z "$SUBSCRIPTION_ID" || -z "$GPT_MIN_CAPACITY" || -z "$TEXT_EMBEDDING_MIN_CAPACITY" ]]; then | ||
echo "❌ ERROR: Missing required environment variables." | ||
exit 1 | ||
fi | ||
|
||
echo "🔄 Setting Azure subscription..." | ||
if ! az account set --subscription "$SUBSCRIPTION_ID"; then | ||
echo "❌ ERROR: Invalid subscription ID or insufficient permissions." | ||
exit 1 | ||
fi | ||
echo "✅ Azure subscription set successfully." | ||
|
||
# Define models and their minimum required capacities | ||
declare -A MIN_CAPACITY=( | ||
["OpenAI.Standard.gpt-35-turbo-16k"]=$GPT_MIN_CAPACITY | ||
["OpenAI.Standard.text-embedding-ada-002"]=$TEXT_EMBEDDING_MIN_CAPACITY | ||
) | ||
|
||
VALID_REGION="" | ||
for REGION in "${REGIONS[@]}"; do | ||
echo "----------------------------------------" | ||
echo "🔍 Checking region: $REGION" | ||
|
||
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json) | ||
if [ -z "$QUOTA_INFO" ]; then | ||
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping." | ||
continue | ||
fi | ||
|
||
INSUFFICIENT_QUOTA=false | ||
for MODEL in "${!MIN_CAPACITY[@]}"; do | ||
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL\"" ' | ||
BEGIN { RS="},"; FS="," } | ||
$0 ~ model { print $0 } | ||
') | ||
|
||
if [ -z "$MODEL_INFO" ]; then | ||
echo "⚠️ WARNING: No quota information found for model: $MODEL in $REGION. Skipping." | ||
continue | ||
fi | ||
|
||
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ') | ||
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ') | ||
|
||
CURRENT_VALUE=${CURRENT_VALUE:-0} | ||
LIMIT=${LIMIT:-0} | ||
|
||
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1) | ||
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1) | ||
|
||
AVAILABLE=$((LIMIT - CURRENT_VALUE)) | ||
|
||
echo "✅ Model: $MODEL | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE" | ||
|
||
if [ "$AVAILABLE" -lt "${MIN_CAPACITY[$MODEL]}" ]; then | ||
echo "❌ ERROR: $MODEL in $REGION has insufficient quota." | ||
INSUFFICIENT_QUOTA=true | ||
break | ||
fi | ||
done | ||
|
||
if [ "$INSUFFICIENT_QUOTA" = false ]; then | ||
VALID_REGION="$REGION" | ||
break | ||
fi | ||
|
||
done | ||
|
||
if [ -z "$VALID_REGION" ]; then | ||
echo "❌ No region with sufficient quota found. Blocking deployment." | ||
echo "QUOTA_FAILED=true" >> "$GITHUB_ENV" | ||
exit 0 | ||
else | ||
echo "✅ Suggested Region: $VALID_REGION" | ||
echo "VALID_REGION=$VALID_REGION" >> "$GITHUB_ENV" | ||
exit 0 | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'grep' on the script file to detect a quota check failure may not work as intended. Consider capturing and checking the output of the script execution instead.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.