Skip to content

Commit 7585972

Browse files
authored
Merge pull request #1 from MicrosoftCloudEssentials-LearningHub/terraform-scenario1
Terraform scenario1
2 parents a08727e + 6485a5c commit 7585972

12 files changed

Lines changed: 976 additions & 47 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Update Last Modified Date
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update-date:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
ref: ${{ github.event.pull_request.head.ref }}
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.x'
27+
28+
- name: Install dependencies
29+
run: pip install python-dateutil
30+
31+
- name: Configure Git
32+
run: |
33+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
34+
git config --global user.name "github-actions[bot]"
35+
36+
- name: Update last modified date in Markdown files
37+
run: python .github/workflows/update_date.py
38+
39+
- name: Pull (merge) remote changes, commit, and push if needed
40+
env:
41+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
BRANCH="${{ github.event.pull_request.head.ref }}"
44+
git pull origin "$BRANCH" || echo "No merge needed"
45+
git add -A
46+
git commit -m "Update last modified date in Markdown files" || echo "No changes to commit"
47+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
48+
git push origin HEAD:"$BRANCH"

.github/workflows/update_date.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import subprocess
3+
from datetime import datetime, timezone
4+
5+
# Get the list of modified files
6+
result = subprocess.run(['git', 'diff', '--name-only', 'HEAD~1'], stdout=subprocess.PIPE)
7+
modified_files = result.stdout.decode('utf-8').split()
8+
9+
# Debugging: Print the list of modified files
10+
print("Modified files:", modified_files)
11+
12+
# Filter for Markdown files
13+
modified_md_files = [f for f in modified_files if f.endswith('.md')]
14+
15+
# Debugging: Print the list of modified Markdown files
16+
print("Modified Markdown files:", modified_md_files)
17+
18+
# Current date
19+
current_date = datetime.now(timezone.utc).strftime('%Y-%m-%d')
20+
21+
# Function to update the last modified date in a file
22+
def update_date_in_file(file_path):
23+
with open(file_path, 'r') as file:
24+
lines = file.readlines()
25+
26+
updated = False
27+
with open(file_path, 'w') as file:
28+
for line in lines:
29+
if line.startswith('Last updated:'):
30+
file.write(f'Last updated: {current_date}\n')
31+
updated = True
32+
else:
33+
file.write(line)
34+
if not updated:
35+
file.write(f'\nLast updated: {current_date}\n')
36+
37+
# Check if there are any modified Markdown files
38+
if not modified_md_files:
39+
print("No modified Markdown files found.")
40+
exit(0)
41+
42+
# Update the date in each modified Markdown file
43+
for file_path in modified_md_files:
44+
print(f"Updating file: {file_path}") # Debugging: Print the file being updated
45+
update_date_in_file(file_path)
46+
47+
# Add and commit changes
48+
subprocess.run(['git', 'add', '-A'])
49+
subprocess.run(['git', 'commit', '-m', 'Update last modified date in Markdown files'])
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Use Visitor Counter Logic
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
schedule:
8+
- cron: '0 0 * * *' # Runs daily at midnight
9+
workflow_dispatch: # Allows manual triggering
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
update-visitor-count:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout current repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Shallow clone visitor counter logic
26+
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '20'
32+
33+
- name: Install dependencies for github-visitor-counter
34+
run: |
35+
cd github-visitor-counter
36+
npm ci
37+
38+
- name: Run visitor counter logic (updates markdown badges and metrics.json)
39+
run: node github-visitor-counter/update_repo_views_counter.js
40+
env:
41+
TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}
42+
REPO: ${{ github.repository }}
43+
44+
- name: Move generated metrics.json to root
45+
run: mv github-visitor-counter/metrics.json .
46+
47+
- name: List files for debugging
48+
run: |
49+
ls -l
50+
ls -l github-visitor-counter
51+
52+
- name: Clean up visitor counter logic
53+
run: rm -rf github-visitor-counter
54+
55+
- name: Configure Git author
56+
run: |
57+
git config --global user.name "github-actions[bot]"
58+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
59+
60+
# Commit and push logic for PR events (merge, not rebase)
61+
- name: Commit and push changes (PR)
62+
if: github.event_name == 'pull_request'
63+
env:
64+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
run: |
66+
git fetch origin
67+
git checkout ${{ github.head_ref }}
68+
git pull origin ${{ github.head_ref }} || echo "No merge needed"
69+
git add -A
70+
git commit -m "Update visitor count" || echo "No changes to commit"
71+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
72+
git push origin HEAD:${{ github.head_ref }}
73+
74+
# Commit and push logic for non-PR events (merge, not rebase)
75+
- name: Commit and push changes (non-PR)
76+
if: github.event_name != 'pull_request'
77+
env:
78+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
run: |
80+
git fetch origin
81+
git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
82+
git pull origin ${{ github.ref_name }} || echo "No merge needed"
83+
git add -A
84+
git commit -m "Update visitor count" || echo "No changes to commit"
85+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
86+
git push origin HEAD:${{ github.ref_name }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Last updated: 2025-08-27
2323

2424
<!-- START BADGE -->
2525
<div align="center">
26-
<img src="https://img.shields.io/badge/Total%20views-1342-limegreen" alt="Total views">
27-
<p>Refresh Date: 2025-08-29</p>
26+
<img src="https://img.shields.io/badge/Total%20views-42-limegreen" alt="Total views">
27+
<p>Refresh Date: 2025-09-05</p>
2828
</div>
2929
<!-- END BADGE -->

metrics.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"date": "2025-07-07",
4+
"count": 330,
5+
"uniques": 20
6+
},
7+
{
8+
"date": "2025-07-08",
9+
"count": 159,
10+
"uniques": 6
11+
},
12+
{
13+
"date": "2025-07-10",
14+
"count": 482,
15+
"uniques": 1
16+
},
17+
{
18+
"date": "2025-07-11",
19+
"count": 170,
20+
"uniques": 4
21+
},
22+
{
23+
"date": "2025-07-12",
24+
"count": 7,
25+
"uniques": 1
26+
},
27+
{
28+
"date": "2025-07-14",
29+
"count": 130,
30+
"uniques": 2
31+
},
32+
{
33+
"date": "2025-07-15",
34+
"count": 2,
35+
"uniques": 1
36+
}
37+
]

scenario1-high-decay/README.md

Lines changed: 77 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,100 @@ Last updated: 2025-08-27
1212

1313
> This scenario is intended to demonstrate rapid temporary file accumulation and disk degradation in Azure Functions.
1414
15+
<details>
16+
<summary><b>List of References</b> (Click to expand)</summary>
17+
18+
- [Kudu service overview](https://learn.microsoft.com/en-us/azure/app-service/resources-kudu)
19+
- [log levels types](https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2#configure-log-levels)
20+
- [How to configure monitoring for Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2)
21+
- [host.json reference for Azure Functions 2.x and later](https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#override-hostjson-values)
22+
- [Sampling overrides %](https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling-overrides)
23+
- [Sampling in Azure Monitor Application Insights with OpenTelemetry](https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-sampling)
24+
25+
</details>
26+
27+
> [!NOTE]
28+
> Expected Results: <br/>
29+
> - Rapid temp file accumulation in `C:\local\Temp` <br/>
30+
> - Disk decay within 1-2 days <br/>
31+
> - Restart clears only partial space due to locked files
1532
1633
## Infrastructure Setup
1734

1835
- **App Service Plan (Windows)** - P1v3 tier for high-load testing
19-
- See: [./terraform-infrastructure/variables.tf](./terraform-infrastructure/variables.tf) (lines 12-21)
20-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (lines 35-45)
21-
- **Deployment Method**: Standard deployment (extracted .zip)
22-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (line 115)
36+
37+
```terraform
38+
# Service Plan
39+
sku_name = "P1v3"
40+
```
41+
42+
<img width="1908" height="842" alt="image" src="https://github.com/user-attachments/assets/fd5b96e4-be63-4319-b533-5c0fe18ec862" />
43+
44+
- **Deployment Method (Function App Environment Variables)**: Standard deployment (extracted .zip)
45+
2346
```terraform
2447
# Force standard deployment instead of mounted package
2548
"WEBSITE_RUN_FROM_PACKAGE" = "0"
2649
```
27-
- **Application Insights**: Full logging (no sampling)
28-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (lines 47-56)
50+
51+
<img width="1903" height="842" alt="image" src="https://github.com/user-attachments/assets/412aeee4-3c7d-43b6-82ea-87050e30f4fe" />
52+
53+
- **Diagnostics Settings (Function App Environment Variables)**: Detailed diagnostics enabled
54+
2955
```terraform
30-
# No sampling configured - full logging
31-
sampling_percentage = 100
56+
# Enable full diagnostics for troubleshooting
57+
"WEBSITE_ENABLE_DETAILED_DIAGNOSTICS" = "true"
3258
```
33-
- **Verbose Diagnostics**: Enabled
34-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (line 118)
59+
60+
<img width="1917" height="796" alt="image" src="https://github.com/user-attachments/assets/bf8e1b7f-bc4a-4c1d-aced-e06f92df5185" />
61+
62+
- **Logging Configuration (Function App Environment Variables)**: Verbose logging enabled. Click here to understand more about [log levels types](https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2#configure-log-levels)
63+
3564
```terraform
36-
# Enable full diagnostics
37-
"WEBSITE_ENABLE_DETAILED_DIAGNOSTICS" = "true"
65+
# Set verbose logging level for better diagnostics but higher disk usage
66+
"AzureFunctionsJobHost__logging__LogLevel__Default" = "Information"
67+
```
68+
69+
<img width="1898" height="828" alt="image" src="https://github.com/user-attachments/assets/6a10498c-fa5d-4e01-a392-0da31ae89cfb" />
70+
71+
- **SCM Separation (Function App Environment Variables)**: Enabled to ensure Kudu and function app run as separate processes
72+
73+
```terraform
74+
# Enable SCM separation for diagnostics
75+
"WEBSITE_DISABLE_SCM_SEPARATION" = "false"
3876
```
39-
- **Storage Logging**: Enabled
40-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (line 124)
77+
78+
<img width="1907" height="842" alt="image" src="https://github.com/user-attachments/assets/d2128b76-38e1-4e3a-af3f-835db68b428f" />
79+
80+
- **Temp Access (Function App Environment Variables)**: Explicitly enabled for diagnostics and reporting
81+
4182
```terraform
42-
# Log to storage account (increases I/O operations)
43-
"AzureWebJobsDashboard" = azurerm_storage_account.storage.primary_connection_string
83+
# Enable temp file access for diagnostics
84+
"WEBSITE_ENABLE_TEMP_ACCESS" = "true"
4485
```
45-
- **WEBSITE_RUN_FROM_PACKAGE**: Disabled (set to "0")
46-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (line 115)
47-
- **Key Vault Integration**: Secrets stored in Azure Key Vault
48-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (lines 147-193)
49-
- **Managed Identity**: System-assigned identity for Key Vault access
50-
- See: [./terraform-infrastructure/main.tf](./terraform-infrastructure/main.tf) (lines 96-98)
5186

52-
## Expected Results
87+
<img width="1907" height="841" alt="image" src="https://github.com/user-attachments/assets/9fbb1211-5d5c-4356-b18f-deef61963150" />
5388

54-
- Rapid temp file accumulation in `C:\local\Temp`
55-
- Disk decay within 1-2 days
56-
- Restart clears only partial space due to locked files
89+
> Overall:
5790
58-
## Deployment Instructions
91+
<img width="973" height="825" alt="image" src="https://github.com/user-attachments/assets/4563a3f1-7168-4b86-b629-6210e99b8f90" />
5992

60-
> For detailed deployment instructions including VS Code deployment and Azure DevOps pipeline samples, see the [DEPLOYMENT.md](./DEPLOYMENT.md) guide.
93+
- **Application Insights**: Full logging (no sampling). Click here to understand more about [Sampling overrides %](https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling-overrides)
6194

62-
1. Go to the terraform-infrastructure directory:
63-
```
64-
cd scenario-1-high-decay/terraform-infrastructure
65-
```
95+
```terraform
96+
# No sampling configured - full logging
97+
sampling_percentage = 100
98+
```
6699

67-
2. Update the `terraform.tfvars` file with your Azure subscription ID and preferred configuration values.
100+
<img width="1903" height="837" alt="image" src="https://github.com/user-attachments/assets/24197ef8-b302-480e-825b-4ddb34e18598" />
68101

69-
3. Initialize Terraform:
70-
```
71-
terraform init
72-
```
102+
- **Key Vault Integration**: Secrets stored in Azure Key Vault
103+
- **Managed Identity**: System-assigned identity for Key Vault access
73104

74-
4. Apply the Terraform configuration:
75-
```
76-
terraform apply
77-
```
105+
## Deployment Instructions
78106

79-
5. After infrastructure deployment, follow the deployment approaches in [DEPLOYMENT.md](./DEPLOYMENT.md) to publish the function app.
107+
1. Please follow the [Terraform Deployment guide](./terraform-infrastructure/README.md) to deploy the necessary Azure resources for the workshop.
108+
2. After infrastructure deployment, follow the deployment approaches in [Deployment Guide](./DEPLOYMENT.md) to publish the function app.
80109

81110
## Testing
82111

@@ -86,13 +115,16 @@ Last updated: 2025-08-27
86115

87116
> Monitor the function app using:
88117
89-
- Azure Portal > Function App > Platform features > Advanced tools (Kudu)
118+
- Azure Portal > Function App > Development Tools > Advanced tools ([Kudu](https://learn.microsoft.com/en-us/azure/app-service/resources-kudu))
119+
120+
https://github.com/user-attachments/assets/0e529115-13ae-4a2f-83ad-35c33be8bb67
121+
90122
- Application Insights
91123
- Azure Monitor metrics
92124

93125
<!-- START BADGE -->
94126
<div align="center">
95-
<img src="https://img.shields.io/badge/Total%20views-1342-limegreen" alt="Total views">
96-
<p>Refresh Date: 2025-08-29</p>
127+
<img src="https://img.shields.io/badge/Total%20views-42-limegreen" alt="Total views">
128+
<p>Refresh Date: 2025-09-05</p>
97129
</div>
98130
<!-- END BADGE -->

0 commit comments

Comments
 (0)