From 5c31be3e6ce66f8ffd2583438372cb5113a6af09 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Mon, 15 Sep 2025 21:47:22 +0200 Subject: [PATCH 1/6] Perf scale demo with shorter lifecycle Signed-off-by: Yury Tsarev --- apis/composition-intelligent.yaml | 4 +- apis/composition-rds-metrics.yaml | 2 +- examples/providerconfig-aws.yaml | 12 ++++ .../operation.yaml | 2 +- perf-scale-demo.sh | 66 +++++++++++++++++++ upbound.yaml | 2 +- 6 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 examples/providerconfig-aws.yaml create mode 100644 perf-scale-demo.sh diff --git a/apis/composition-intelligent.yaml b/apis/composition-intelligent.yaml index 800b6ad..78eb2a8 100644 --- a/apis/composition-intelligent.yaml +++ b/apis/composition-intelligent.yaml @@ -31,7 +31,7 @@ spec: - "FreeStorageSpace" - "ReadIOPS" - "WriteIOPS" - period: 300 + period: 60 target: "status.performanceMetrics" credentials: - name: aws-creds @@ -59,7 +59,7 @@ spec: 6. When scaling needed: ONLY modify the instanceClass or allocatedStorage fields in spec.forProvider 7. PRESERVE all other existing spec fields unchanged - do not recreate the entire spec 4. Make scaling decisions based on these thresholds: - - High CPU (>80%): Consider increasing instance class + - High CPU (>50%): Consider increasing instance class - High Memory usage (FreeableMemory <20% of total): Consider memory-optimized instance - High IOPS (>80% of provisioned): Consider increasing storage or instance class - High connections (>80% of max): Consider increasing instance class diff --git a/apis/composition-rds-metrics.yaml b/apis/composition-rds-metrics.yaml index 1eb064a..274d3b0 100644 --- a/apis/composition-rds-metrics.yaml +++ b/apis/composition-rds-metrics.yaml @@ -13,7 +13,7 @@ spec: pipeline: - step: xsqlinstance functionRef: - name: upbound-configuration-aws-databasexsqlinstance + name: upbound-configuration-aws-database-aixsqlinstance - step: fetch-metrics functionRef: name: upbound-function-rds-metrics diff --git a/examples/providerconfig-aws.yaml b/examples/providerconfig-aws.yaml new file mode 100644 index 0000000..63ebc2b --- /dev/null +++ b/examples/providerconfig-aws.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: aws.upbound.io/v1beta1 +kind: ProviderConfig +metadata: + name: default +spec: + credentials: + source: Secret + secretRef: + namespace: crossplane-system + name: aws-creds + key: credentials diff --git a/operations/rds-intelligent-scaling-cron/operation.yaml b/operations/rds-intelligent-scaling-cron/operation.yaml index d13907a..e446a5e 100644 --- a/operations/rds-intelligent-scaling-cron/operation.yaml +++ b/operations/rds-intelligent-scaling-cron/operation.yaml @@ -101,4 +101,4 @@ spec: namespace: crossplane-system name: claude retryLimit: 3 - schedule: '*/10 * * * *' # Run every 10 minute for testing + schedule: '*/2 * * * *' # Run every 2 minutes for demo diff --git a/perf-scale-demo.sh b/perf-scale-demo.sh new file mode 100644 index 0000000..9201487 --- /dev/null +++ b/perf-scale-demo.sh @@ -0,0 +1,66 @@ + #!/bin/bash + # Demo-optimized load test for fast autoscaling trigger + + DB_ENDPOINT="rds-metrics-database-ai-scale.cxal1lomznba.us-west-2.rds.amazonaws.com" + DB_USER="masteruser" + DB_PASS="YzZiCjT6vitMxClxBmE7OH8IScb" + XR_NAME="rds-metrics-database-ai-scale" + + echo "🚀 Starting DEMO load test (optimized for speed)..." + + # Maximum intensity load - 20 processes with high benchmark values + for i in {1..20}; do + mysql --host=$DB_ENDPOINT --user=$DB_USER --password=$DB_PASS \ + --default-auth=mysql_native_password \ + --execute="SELECT BENCHMARK(3000000000, MD5('demo_intensive_$i'));" & + done + + # Additional CPU-intensive operations + for i in {1..10}; do + mysql --host=$DB_ENDPOINT --user=$DB_USER --password=$DB_PASS \ + --execute=" + SELECT BENCHMARK(1000000000, SHA2(CONCAT('demo_', RAND()), 256)); + SELECT BENCHMARK(1000000000, MD5(CONCAT(CONNECTION_ID(), '_$i'))); + " & + done + + echo "⏱️ Load test running... Expected timeline:" + echo " - 30-60 seconds: CPU should hit 50%+" + echo " - 1-2 minutes: CloudWatch metrics update" + echo " - 2-3 minutes: Claude analysis and scaling decision" + echo " - 5-10 minutes: Instance scaling completion" + + # Real-time monitoring + for i in {1..15}; do + echo "" + echo "=== Demo Check $i ($(date +%H:%M:%S)) ===" + + # Current metrics + CPU=$(kubectl get xsqlinstance $XR_NAME -o jsonpath='{.status.performanceMetrics.metrics.CPUUtilization.value}' + 2>/dev/null || echo "collecting...") + echo "🔥 CPU: ${CPU}% (threshold: 50%)" + + # Instance class + CLASS=$(kubectl get instance.rds -l crossplane.io/composite=$XR_NAME -o + jsonpath='{.items[0].spec.forProvider.instanceClass}' 2>/dev/null || echo "unknown") + echo "💾 Instance: $CLASS" + + # Claude decision + REASONING=$(kubectl get xsqlinstance $XR_NAME -o jsonpath='{.status.claudeDecision.reasoning}' 2>/dev/null || echo "analyzing...") + echo "🤖 Claude: ${REASONING:0:80}..." + + # Check if scaling happened + if [[ "$CLASS" != "db.t3.micro" ]]; then + echo "🎉 SCALING SUCCESSFUL! Instance upgraded to $CLASS" + break + fi + + sleep 20 + done + + echo "" + echo "🛑 Stopping load test..." + pkill -f "mysql.*BENCHMARK" + pkill -f "mysql.*SHA2" + + echo "✅ Demo complete!" diff --git a/upbound.yaml b/upbound.yaml index 5be3b50..580788b 100644 --- a/upbound.yaml +++ b/upbound.yaml @@ -23,7 +23,7 @@ spec: - apiVersion: pkg.crossplane.io/v1beta1 kind: Function package: xpkg.upbound.io/upbound/function-rds-metrics - version: v0.0.3 + version: v0.0.6 description: This repository provides a foundational configuration to build and operate an AWS database, including handling its dependencies and configurations. The setup ensures a streamlined and repeatable deployment in a cloud environment. From 2312dfdb6d387954e55c6463ae5269da66f572a0 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Mon, 15 Sep 2025 23:46:43 +0200 Subject: [PATCH 2/6] Employ bidirectional scaling Signed-off-by: Yury Tsarev --- apis/composition-intelligent.yaml | 10 ++++++++-- .../rds-intelligent-scaling-cron/operation.yaml | 16 ++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apis/composition-intelligent.yaml b/apis/composition-intelligent.yaml index 78eb2a8..674244d 100644 --- a/apis/composition-intelligent.yaml +++ b/apis/composition-intelligent.yaml @@ -65,9 +65,15 @@ spec: - High connections (>80% of max): Consider increasing instance class SCALING LOGIC: - - For high CPU/Memory/IOPS: Upgrade instance class (e.g., db.t3.micro → db.t3.small → db.t3.medium) + - For high CPU/Memory/IOPS: Upgrade instance class (e.g., db.t3.micro → db.t3.small → db.t3.medium → db.t3.large) + - For low utilization: Downgrade instance class (e.g., db.t3.large → db.t3.medium → db.t3.small → db.t3.micro) - For storage issues: Increase allocatedStorage by 20GB increments - - Only scale up, never scale down automatically for safety + - Scale up when resources are constrained, scale down when consistently over-provisioned + - DOWNSCALING SAFETY: Only scale down if ALL metrics show low utilization for sustained period: + * CPU < 20% for extended time + * Memory usage < 40% + * Connections < 30% of capacity + * No recent scaling events (check annotations for last scaling time) CRITICAL UPDATE APPROACH: - PRESERVE the entire existing resource structure from section diff --git a/operations/rds-intelligent-scaling-cron/operation.yaml b/operations/rds-intelligent-scaling-cron/operation.yaml index e446a5e..236511b 100644 --- a/operations/rds-intelligent-scaling-cron/operation.yaml +++ b/operations/rds-intelligent-scaling-cron/operation.yaml @@ -44,12 +44,16 @@ spec: - Only proceed if no recent analysis or if metrics show significant changes SCALING TRIGGERS (conservative for cost control): - - CPU > 85%: scale up instance class - - FreeableMemory < 15%: scale up for memory pressure - - DatabaseConnections > 85% of max: scale up for connection pressure - - INSTANCE CLASS PROGRESSION: - db.t3.micro → db.t3.small → db.t3.medium → db.t3.large + - SCALE UP: CPU > 85%, Memory < 15%, Connections > 85% + - SCALE DOWN: CPU < 20% AND Memory > 60% AND Connections < 30% for sustained period + + INSTANCE CLASS PROGRESSION (bidirectional): + db.t3.micro ↔ db.t3.small ↔ db.t3.medium ↔ db.t3.large + + DOWNSCALING SAFETY: + - Only scale down if ALL conditions met for sustained period + - Check last-scaled annotation to prevent frequent changes + - Ensure minimum 15-minute cooldown between scaling events REQUIRED OUTPUT FORMAT: You must output the XSQLInstance resource in JSON format with ONLY the fields that need to be patched. From d1035f27cbfcdc5cd7de728302a065655aecf6c6 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 16 Sep 2025 17:11:39 +0200 Subject: [PATCH 3/6] Add demo scripts Signed-off-by: Yury Tsarev --- .../operation.yaml | 22 +++++++++---------- perf-scale-demo.sh | 0 simple-demo-scaling-monitor.sh | 16 ++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) mode change 100644 => 100755 perf-scale-demo.sh create mode 100755 simple-demo-scaling-monitor.sh diff --git a/operations/rds-intelligent-scaling-cron/operation.yaml b/operations/rds-intelligent-scaling-cron/operation.yaml index 236511b..74f49d2 100644 --- a/operations/rds-intelligent-scaling-cron/operation.yaml +++ b/operations/rds-intelligent-scaling-cron/operation.yaml @@ -10,7 +10,7 @@ spec: concurrencyPolicy: Forbid successfulHistoryLimit: 5 failedHistoryLimit: 1 - + operationTemplate: spec: mode: Pipeline @@ -33,16 +33,16 @@ spec: and makes scaling decisions based on CloudWatch performance metrics. userPrompt: | You are analyzing an XSQLInstance resource for potential RDS scaling needs. - + SCALING ANALYSIS CRITERIA: 1. Check performance metrics in status.performanceMetrics 2. Check current instanceClass in spec.parameters.instanceClass 3. Check if analysis was done recently (intelligent-scaling annotations) - + RATE LIMITING: - Skip analysis if "intelligent-scaling/last-analyzed" annotation exists and is < 5 minutes old - Only proceed if no recent analysis or if metrics show significant changes - + SCALING TRIGGERS (conservative for cost control): - SCALE UP: CPU > 85%, Memory < 15%, Connections > 85% - SCALE DOWN: CPU < 20% AND Memory > 60% AND Connections < 30% for sustained period @@ -54,14 +54,14 @@ spec: - Only scale down if ALL conditions met for sustained period - Check last-scaled annotation to prevent frequent changes - Ensure minimum 15-minute cooldown between scaling events - + REQUIRED OUTPUT FORMAT: You must output the XSQLInstance resource in JSON format with ONLY the fields that need to be patched. - + If scaling is needed: { "apiVersion": "aws.platform.upbound.io/v1alpha1", - "kind": "XSQLInstance", + "kind": "XSQLInstance", "metadata": { "name": "", "annotations": { @@ -75,10 +75,10 @@ spec: } } } - + If no scaling is needed: { - "apiVersion": "aws.platform.upbound.io/v1alpha1", + "apiVersion": "aws.platform.upbound.io/v1alpha1", "kind": "XSQLInstance", "metadata": { "name": "", @@ -88,10 +88,10 @@ spec: } } } - + Rules: - Use the exact resource name from the input - - Only include fields that need to be updated + - Only include fields that need to be updated - Use current timestamp in ISO8601 format - Provide brief, clear reasoning in annotations - Output only the JSON, no explanatory text diff --git a/perf-scale-demo.sh b/perf-scale-demo.sh old mode 100644 new mode 100755 diff --git a/simple-demo-scaling-monitor.sh b/simple-demo-scaling-monitor.sh new file mode 100755 index 0000000..b7cdff7 --- /dev/null +++ b/simple-demo-scaling-monitor.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# simple-demo-scaling-monitor.sh + +XR_NAME="rds-metrics-database-ai-scale" + +while true; do + echo "=== $(date '+%Y-%m-%d %H:%M:%S') ===" + echo "$ kubectl get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations | +del(.[\"kubectl.kubernetes.io/last-applied-configuration\"])'" + + kubectl get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations | +del(.["kubectl.kubernetes.io/last-applied-configuration"])' + + echo "" + sleep 15 +done From 95283fcf4f591d81075a9515bd2d878d73e7185c Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 16 Sep 2025 17:35:30 +0200 Subject: [PATCH 4/6] Bump default monitoring window Signed-off-by: Yury Tsarev --- simple-demo-scaling-monitor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-demo-scaling-monitor.sh b/simple-demo-scaling-monitor.sh index b7cdff7..96a8e8f 100755 --- a/simple-demo-scaling-monitor.sh +++ b/simple-demo-scaling-monitor.sh @@ -12,5 +12,5 @@ del(.[\"kubectl.kubernetes.io/last-applied-configuration\"])'" del(.["kubectl.kubernetes.io/last-applied-configuration"])' echo "" - sleep 15 + sleep 45 done From 534847d0a0c904a7eb2b59d223a754d6dc83aac8 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Thu, 18 Sep 2025 05:56:41 +0200 Subject: [PATCH 5/6] More frequent cron, context safe demo script Signed-off-by: Yury Tsarev --- operations/rds-intelligent-scaling-cron/operation.yaml | 2 +- simple-demo-scaling-monitor.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/operations/rds-intelligent-scaling-cron/operation.yaml b/operations/rds-intelligent-scaling-cron/operation.yaml index 74f49d2..25e55ef 100644 --- a/operations/rds-intelligent-scaling-cron/operation.yaml +++ b/operations/rds-intelligent-scaling-cron/operation.yaml @@ -105,4 +105,4 @@ spec: namespace: crossplane-system name: claude retryLimit: 3 - schedule: '*/2 * * * *' # Run every 2 minutes for demo + schedule: '*/1 * * * *' # Run every 2 minutes for demo diff --git a/simple-demo-scaling-monitor.sh b/simple-demo-scaling-monitor.sh index 96a8e8f..9066f1a 100755 --- a/simple-demo-scaling-monitor.sh +++ b/simple-demo-scaling-monitor.sh @@ -2,13 +2,14 @@ # simple-demo-scaling-monitor.sh XR_NAME="rds-metrics-database-ai-scale" +CONTEXT="kind-up-configuration-aws-database-ai" while true; do echo "=== $(date '+%Y-%m-%d %H:%M:%S') ===" echo "$ kubectl get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations | del(.[\"kubectl.kubernetes.io/last-applied-configuration\"])'" - kubectl get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations | + kubectl --context $CONTEXT get xsqlinstance $XR_NAME -o yaml | yq '.metadata.annotations | del(.["kubectl.kubernetes.io/last-applied-configuration"])' echo "" From 2e80a0f2a9e413a10a9ef6872ae11bb016879173 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Thu, 2 Oct 2025 16:03:20 +0200 Subject: [PATCH 6/6] Add 2 minutes back, tweak .yamllint Signed-off-by: Yury Tsarev --- .yamllint | 2 ++ operations/rds-intelligent-scaling-cron/operation.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.yamllint b/.yamllint index 669c864..1fd3784 100644 --- a/.yamllint +++ b/.yamllint @@ -3,3 +3,5 @@ extends: default rules: line-length: disable document-start: disable + indentation: + indent-sequences: consistent diff --git a/operations/rds-intelligent-scaling-cron/operation.yaml b/operations/rds-intelligent-scaling-cron/operation.yaml index 25e55ef..74f49d2 100644 --- a/operations/rds-intelligent-scaling-cron/operation.yaml +++ b/operations/rds-intelligent-scaling-cron/operation.yaml @@ -105,4 +105,4 @@ spec: namespace: crossplane-system name: claude retryLimit: 3 - schedule: '*/1 * * * *' # Run every 2 minutes for demo + schedule: '*/2 * * * *' # Run every 2 minutes for demo