Skip to content

Commit

Permalink
add config log
Browse files Browse the repository at this point in the history
Signed-off-by: bvolovat <[email protected]>
  • Loading branch information
bvolovat committed Feb 27, 2025
1 parent 575d8d9 commit 0edd4a3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/performance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
echo "PRIVATE_NODE_AGENT: ${{ github.event.inputs.PRIVATE_NODE_AGENT }}"
echo "HELM_GIT_BRANCH: ${{ github.event.inputs.HELM_GIT_BRANCH }}"
- name: Run Performance Test & Deploy Kubescape
- name: Run Performance Test
env:
QUAYIO_REGISTRY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
QUAYIO_REGISTRY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
Expand Down
13 changes: 12 additions & 1 deletion collect-metrics-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ data:
python threshold_check.py
python check_logs.py
if [ -f "/workspace/config.log" ]; then
echo "Copying config.log to OUTPUT_DIR..."
cp /workspace/config.log "${OUTPUT_DIR}/config.log"
else
echo "WARNING: config.log not found in /workspace/!"
fi
# Debug: Verify config.log is in the correct directory
echo "Checking OUTPUT_DIR contents after copying config.log:"
ls -l "${OUTPUT_DIR}"
# Change to Logs repo directory to commit and push
cd /workspace/Logs
echo "Pushing results to Logs repository..."
git add "performance-inCluster/${TIMESTAMP}_helm_${CLEAN_HELM_VERSION}"
git commit -m "Add performance test results - Duration: ${DURATION_TIME}m, Helm: ${HELM_VERSION}"
Expand Down
45 changes: 36 additions & 9 deletions performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import argparse
import subprocess
from concurrent.futures import ThreadPoolExecutor, as_completed
import logging



NODE_SIZES = {
Expand All @@ -15,7 +17,28 @@
}

DEFAULT_NODE_SIZE = "s-4vcpu-16gb"
DEFAULT_NODE_COUNT = 4
DEFAULT_NODE_COUNT = 4

def setup_logging(output_dir):
os.makedirs(output_dir, exist_ok=True)
log_file = os.path.join(output_dir, "config.log")

# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_file),
logging.StreamHandler() # Keep console output too
]
)
return logging.getLogger()

logger = setup_logging(os.getenv('OUTPUT_DIR', 'config'))

def log_and_print(message):
print(message) # Console
logger.info(message) # Log file

def run_command(command, cwd=None):
try:
Expand Down Expand Up @@ -217,9 +240,10 @@ def deploy_kubescape(
if not helm_git_branch.startswith("http"):
repo_url = "https://github.com/kubescape/helm-charts.git"
branch_name = helm_git_branch
print(f"Using default repo {repo_url} with branch {branch_name}")
log_and_print(f"Using default repo {repo_url} with branch {branch_name}")
else:
repo_url = helm_git_branch
log_and_print(f"Using custom Git repository: {repo_url}")
branch_name = None

repo_name = repo_url.split('/')[-1].replace('.git', '')
Expand All @@ -232,7 +256,7 @@ def deploy_kubescape(
run_command(clone_command)

git_commit_hash = run_command(f"git -C {helm_chart_path} rev-parse HEAD")
print(f"Using Git commit hash: {git_commit_hash}")
log_and_print(f"Using Git commit hash: {git_commit_hash}")

# Detect the correct path
default_chart_path = os.path.join(helm_chart_path, "kubescape-operator")
Expand Down Expand Up @@ -305,6 +329,8 @@ def deploy_kubescape(
helm_command += ' ' + additional_params

run_command(helm_command)
log_and_print(helm_command)

time.sleep(30) # Wait for the operator to deploy
print("waiting for operator to deploy - 30 sec")
print("Kubescape Operator deployed successfully.")
Expand Down Expand Up @@ -352,6 +378,7 @@ def calculate_resources(node_size, node_count, enable_kdr=False):

node_size = node_size or DEFAULT_NODE_SIZE
node_count = node_count or DEFAULT_NODE_COUNT
log_and_print(f"{node_count} nodes of size '{node_size}'")

if node_size not in NODE_SIZES:
print(f"Warning: Unknown NODE_SIZE '{node_size}'. Using default '{DEFAULT_NODE_SIZE}'.")
Expand Down Expand Up @@ -424,16 +451,16 @@ def calculate_resources(node_size, node_count, enable_kdr=False):
}

# **Print Calculated Resource Allocations**
print("\nComputed Resource Allocations:")
print(f"Node Agent Requests: CPU: {config['nodeAgent']['resources']['requests']['cpu']}, "
log_and_print("\nComputed Resource Allocations:")
log_and_print(f"Node Agent Requests: CPU: {config['nodeAgent']['resources']['requests']['cpu']}, "
f"Memory: {config['nodeAgent']['resources']['requests']['memory']}")
print(f"Node Agent Limits: CPU: {config['nodeAgent']['resources']['limits']['cpu']}, "
log_and_print(f"Node Agent Limits: CPU: {config['nodeAgent']['resources']['limits']['cpu']}, "
f"Memory: {config['nodeAgent']['resources']['limits']['memory']}")

print(f"Storage Requests: Memory: {config['storage']['resources']['requests']['memory']}")
print(f"Storage Limits: Memory: {config['storage']['resources']['limits']['memory']}")
log_and_print(f"Storage Requests: Memory: {config['storage']['resources']['requests']['memory']}")
log_and_print(f"Storage Limits: Memory: {config['storage']['resources']['limits']['memory']}")

print(f"KubeVuln Limits: Memory: {config['kubevuln']['resources']['limits']['memory']}")
log_and_print(f"KubeVuln Limits: Memory: {config['kubevuln']['resources']['limits']['memory']}")

return config

Expand Down

0 comments on commit 0edd4a3

Please sign in to comment.