Skip to content

Commit 8373d8c

Browse files
authored
Update repo to KCD Sofia demo (#4)
* Perf scale demo with shorter lifecycle Signed-off-by: Yury Tsarev <[email protected]> * Employ bidirectional scaling Signed-off-by: Yury Tsarev <[email protected]> * Add demo scripts Signed-off-by: Yury Tsarev <[email protected]> * Bump default monitoring window Signed-off-by: Yury Tsarev <[email protected]> * More frequent cron, context safe demo script Signed-off-by: Yury Tsarev <[email protected]> * Add 2 minutes back, tweak .yamllint Signed-off-by: Yury Tsarev <[email protected]> --------- Signed-off-by: Yury Tsarev <[email protected]>
1 parent e0c65d3 commit 8373d8c

File tree

8 files changed

+131
-24
lines changed

8 files changed

+131
-24
lines changed

.yamllint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ extends: default
33
rules:
44
line-length: disable
55
document-start: disable
6+
indentation:
7+
indent-sequences: consistent

apis/composition-intelligent.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
- "FreeStorageSpace"
3232
- "ReadIOPS"
3333
- "WriteIOPS"
34-
period: 300
34+
period: 60
3535
target: "status.performanceMetrics"
3636
credentials:
3737
- name: aws-creds
@@ -59,15 +59,21 @@ spec:
5959
6. When scaling needed: ONLY modify the instanceClass or allocatedStorage fields in spec.forProvider
6060
7. PRESERVE all other existing spec fields unchanged - do not recreate the entire spec
6161
4. Make scaling decisions based on these thresholds:
62-
- High CPU (>80%): Consider increasing instance class
62+
- High CPU (>50%): Consider increasing instance class
6363
- High Memory usage (FreeableMemory <20% of total): Consider memory-optimized instance
6464
- High IOPS (>80% of provisioned): Consider increasing storage or instance class
6565
- High connections (>80% of max): Consider increasing instance class
6666
6767
SCALING LOGIC:
68-
- For high CPU/Memory/IOPS: Upgrade instance class (e.g., db.t3.micro → db.t3.small → db.t3.medium)
68+
- For high CPU/Memory/IOPS: Upgrade instance class (e.g., db.t3.micro → db.t3.small → db.t3.medium → db.t3.large)
69+
- For low utilization: Downgrade instance class (e.g., db.t3.large → db.t3.medium → db.t3.small → db.t3.micro)
6970
- For storage issues: Increase allocatedStorage by 20GB increments
70-
- Only scale up, never scale down automatically for safety
71+
- Scale up when resources are constrained, scale down when consistently over-provisioned
72+
- DOWNSCALING SAFETY: Only scale down if ALL metrics show low utilization for sustained period:
73+
* CPU < 20% for extended time
74+
* Memory usage < 40%
75+
* Connections < 30% of capacity
76+
* No recent scaling events (check annotations for last scaling time)
7177
7278
CRITICAL UPDATE APPROACH:
7379
- PRESERVE the entire existing resource structure from <composed> section

apis/composition-rds-metrics.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313
pipeline:
1414
- step: xsqlinstance
1515
functionRef:
16-
name: upbound-configuration-aws-databasexsqlinstance
16+
name: upbound-configuration-aws-database-aixsqlinstance
1717
- step: fetch-metrics
1818
functionRef:
1919
name: upbound-function-rds-metrics

examples/providerconfig-aws.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
apiVersion: aws.upbound.io/v1beta1
3+
kind: ProviderConfig
4+
metadata:
5+
name: default
6+
spec:
7+
credentials:
8+
source: Secret
9+
secretRef:
10+
namespace: crossplane-system
11+
name: aws-creds
12+
key: credentials

operations/rds-intelligent-scaling-cron/operation.yaml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
concurrencyPolicy: Forbid
1111
successfulHistoryLimit: 5
1212
failedHistoryLimit: 1
13-
13+
1414
operationTemplate:
1515
spec:
1616
mode: Pipeline
@@ -33,31 +33,35 @@ spec:
3333
and makes scaling decisions based on CloudWatch performance metrics.
3434
userPrompt: |
3535
You are analyzing an XSQLInstance resource for potential RDS scaling needs.
36-
36+
3737
SCALING ANALYSIS CRITERIA:
3838
1. Check performance metrics in status.performanceMetrics
3939
2. Check current instanceClass in spec.parameters.instanceClass
4040
3. Check if analysis was done recently (intelligent-scaling annotations)
41-
41+
4242
RATE LIMITING:
4343
- Skip analysis if "intelligent-scaling/last-analyzed" annotation exists and is < 5 minutes old
4444
- Only proceed if no recent analysis or if metrics show significant changes
45-
45+
4646
SCALING TRIGGERS (conservative for cost control):
47-
- CPU > 85%: scale up instance class
48-
- FreeableMemory < 15%: scale up for memory pressure
49-
- DatabaseConnections > 85% of max: scale up for connection pressure
50-
51-
INSTANCE CLASS PROGRESSION:
52-
db.t3.micro → db.t3.small → db.t3.medium → db.t3.large
53-
47+
- SCALE UP: CPU > 85%, Memory < 15%, Connections > 85%
48+
- SCALE DOWN: CPU < 20% AND Memory > 60% AND Connections < 30% for sustained period
49+
50+
INSTANCE CLASS PROGRESSION (bidirectional):
51+
db.t3.micro ↔ db.t3.small ↔ db.t3.medium ↔ db.t3.large
52+
53+
DOWNSCALING SAFETY:
54+
- Only scale down if ALL conditions met for sustained period
55+
- Check last-scaled annotation to prevent frequent changes
56+
- Ensure minimum 15-minute cooldown between scaling events
57+
5458
REQUIRED OUTPUT FORMAT:
5559
You must output the XSQLInstance resource in JSON format with ONLY the fields that need to be patched.
56-
60+
5761
If scaling is needed:
5862
{
5963
"apiVersion": "aws.platform.upbound.io/v1alpha1",
60-
"kind": "XSQLInstance",
64+
"kind": "XSQLInstance",
6165
"metadata": {
6266
"name": "<exact-resource-name>",
6367
"annotations": {
@@ -71,10 +75,10 @@ spec:
7175
}
7276
}
7377
}
74-
78+
7579
If no scaling is needed:
7680
{
77-
"apiVersion": "aws.platform.upbound.io/v1alpha1",
81+
"apiVersion": "aws.platform.upbound.io/v1alpha1",
7882
"kind": "XSQLInstance",
7983
"metadata": {
8084
"name": "<exact-resource-name>",
@@ -84,10 +88,10 @@ spec:
8488
}
8589
}
8690
}
87-
91+
8892
Rules:
8993
- Use the exact resource name from the input
90-
- Only include fields that need to be updated
94+
- Only include fields that need to be updated
9195
- Use current timestamp in ISO8601 format
9296
- Provide brief, clear reasoning in annotations
9397
- Output only the JSON, no explanatory text
@@ -101,4 +105,4 @@ spec:
101105
namespace: crossplane-system
102106
name: claude
103107
retryLimit: 3
104-
schedule: '*/10 * * * *' # Run every 10 minute for testing
108+
schedule: '*/2 * * * *' # Run every 2 minutes for demo

perf-scale-demo.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Demo-optimized load test for fast autoscaling trigger
3+
4+
DB_ENDPOINT="rds-metrics-database-ai-scale.cxal1lomznba.us-west-2.rds.amazonaws.com"
5+
DB_USER="masteruser"
6+
DB_PASS="YzZiCjT6vitMxClxBmE7OH8IScb"
7+
XR_NAME="rds-metrics-database-ai-scale"
8+
9+
echo "🚀 Starting DEMO load test (optimized for speed)..."
10+
11+
# Maximum intensity load - 20 processes with high benchmark values
12+
for i in {1..20}; do
13+
mysql --host=$DB_ENDPOINT --user=$DB_USER --password=$DB_PASS \
14+
--default-auth=mysql_native_password \
15+
--execute="SELECT BENCHMARK(3000000000, MD5('demo_intensive_$i'));" &
16+
done
17+
18+
# Additional CPU-intensive operations
19+
for i in {1..10}; do
20+
mysql --host=$DB_ENDPOINT --user=$DB_USER --password=$DB_PASS \
21+
--execute="
22+
SELECT BENCHMARK(1000000000, SHA2(CONCAT('demo_', RAND()), 256));
23+
SELECT BENCHMARK(1000000000, MD5(CONCAT(CONNECTION_ID(), '_$i')));
24+
" &
25+
done
26+
27+
echo "⏱️ Load test running... Expected timeline:"
28+
echo " - 30-60 seconds: CPU should hit 50%+"
29+
echo " - 1-2 minutes: CloudWatch metrics update"
30+
echo " - 2-3 minutes: Claude analysis and scaling decision"
31+
echo " - 5-10 minutes: Instance scaling completion"
32+
33+
# Real-time monitoring
34+
for i in {1..15}; do
35+
echo ""
36+
echo "=== Demo Check $i ($(date +%H:%M:%S)) ==="
37+
38+
# Current metrics
39+
CPU=$(kubectl get xsqlinstance $XR_NAME -o jsonpath='{.status.performanceMetrics.metrics.CPUUtilization.value}'
40+
2>/dev/null || echo "collecting...")
41+
echo "🔥 CPU: ${CPU}% (threshold: 50%)"
42+
43+
# Instance class
44+
CLASS=$(kubectl get instance.rds -l crossplane.io/composite=$XR_NAME -o
45+
jsonpath='{.items[0].spec.forProvider.instanceClass}' 2>/dev/null || echo "unknown")
46+
echo "💾 Instance: $CLASS"
47+
48+
# Claude decision
49+
REASONING=$(kubectl get xsqlinstance $XR_NAME -o jsonpath='{.status.claudeDecision.reasoning}' 2>/dev/null || echo "analyzing...")
50+
echo "🤖 Claude: ${REASONING:0:80}..."
51+
52+
# Check if scaling happened
53+
if [[ "$CLASS" != "db.t3.micro" ]]; then
54+
echo "🎉 SCALING SUCCESSFUL! Instance upgraded to $CLASS"
55+
break
56+
fi
57+
58+
sleep 20
59+
done
60+
61+
echo ""
62+
echo "🛑 Stopping load test..."
63+
pkill -f "mysql.*BENCHMARK"
64+
pkill -f "mysql.*SHA2"
65+
66+
echo "✅ Demo complete!"

simple-demo-scaling-monitor.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# simple-demo-scaling-monitor.sh
3+
4+
XR_NAME="rds-metrics-database-ai-scale"
5+
CONTEXT="kind-up-configuration-aws-database-ai"
6+
7+
while true; do
8+
echo "=== $(date '+%Y-%m-%d %H:%M:%S') ==="
9+
echo "$ kubectl get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations |
10+
del(.[\"kubectl.kubernetes.io/last-applied-configuration\"])'"
11+
12+
kubectl --context $CONTEXT get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations |
13+
del(.["kubectl.kubernetes.io/last-applied-configuration"])'
14+
15+
echo ""
16+
sleep 45
17+
done

upbound.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
- apiVersion: pkg.crossplane.io/v1beta1
2424
kind: Function
2525
package: xpkg.upbound.io/upbound/function-rds-metrics
26-
version: v0.0.3
26+
version: v0.0.6
2727
description: This repository provides a foundational configuration to build and
2828
operate an AWS database, including handling its dependencies and configurations.
2929
The setup ensures a streamlined and repeatable deployment in a cloud environment.

0 commit comments

Comments
 (0)