Skip to content

Commit

Permalink
maybe tier issue fixed :)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosalmi committed Jan 31, 2025
1 parent 591bf8b commit 2c7de96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
42 changes: 27 additions & 15 deletions lxc_autoscale/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import sys
from socket import gethostname
Expand All @@ -20,22 +21,33 @@ def load_tier_configurations() -> Dict[str, Dict[str, Any]]:
"""Load and validate tier configurations."""
tier_configs: Dict[str, Dict[str, Any]] = {}

# Initialize logging
logging.basicConfig(level=logging.INFO)

for section, values in config.items():
if section.startswith('TIER_') and isinstance(values, dict):
for ctid in values.get('lxc_containers', []):
tier_configs[str(ctid)] = {
'cpu_upper_threshold': values.get('cpu_upper_threshold', DEFAULTS.get('cpu_upper_threshold')),
'cpu_lower_threshold': values.get('cpu_lower_threshold', DEFAULTS.get('cpu_lower_threshold')),
'memory_upper_threshold': values.get('memory_upper_threshold', DEFAULTS.get('memory_upper_threshold')),
'memory_lower_threshold': values.get('memory_lower_threshold', DEFAULTS.get('memory_lower_threshold')),
'min_cores': values.get('min_cores', DEFAULTS.get('min_cores')),
'max_cores': values.get('max_cores', DEFAULTS.get('max_cores')),
'min_memory': values.get('min_memory', DEFAULTS.get('min_memory')),
'core_min_increment': values.get('core_min_increment', DEFAULTS.get('core_min_increment')),
'core_max_increment': values.get('core_max_increment', DEFAULTS.get('core_max_increment')),
'memory_min_increment': values.get('memory_min_increment', DEFAULTS.get('memory_min_increment')),
'min_decrease_chunk': values.get('min_decrease_chunk', DEFAULTS.get('min_decrease_chunk'))
}
if section.startswith('TIER_'):
# Extract tier name from section
tier_name = section[5:] # Remove 'TIER_' prefix
if isinstance(values, dict):
if 'lxc_containers' in values:
# Apply tier settings to each container in the tier
for ctid in values['lxc_containers']:
tier_configs[str(ctid)] = {
'cpu_upper_threshold': values.get('cpu_upper_threshold', DEFAULTS['cpu_upper_threshold']),
'cpu_lower_threshold': values.get('cpu_lower_threshold', DEFAULTS['cpu_lower_threshold']),
'memory_upper_threshold': values.get('memory_upper_threshold', DEFAULTS['memory_upper_threshold']),
'memory_lower_threshold': values.get('memory_lower_threshold', DEFAULTS['memory_lower_threshold']),
'min_cores': values.get('min_cores', DEFAULTS['min_cores']),
'max_cores': values.get('max_cores', DEFAULTS['max_cores']),
'min_memory': values.get('min_memory', DEFAULTS['min_memory']),
'core_min_increment': values.get('core_min_increment', DEFAULTS.get('core_min_increment', 1)),
'core_max_increment': values.get('core_max_increment', DEFAULTS.get('core_max_increment', 2)),
'memory_min_increment': values.get('memory_min_increment', DEFAULTS.get('memory_min_increment', 256)),
'min_decrease_chunk': values.get('min_decrease_chunk', DEFAULTS.get('min_decrease_chunk', 128)),
'tier_name': tier_name
}
logging.info(f"Loaded tier configuration for container {ctid} from tier {tier_name}")

return tier_configs

def get_config_value(section: str, key: str, default: Any) -> Any:
Expand Down
14 changes: 7 additions & 7 deletions lxc_autoscale/lxc_autoscale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ DEFAULTS:
# Tier configurations
TIER_webservers:
lxc_containers:
- 102 # Container 102 shows higher memory usage
- 102
cpu_upper_threshold: 70
cpu_lower_threshold: 20 # Adjusted to match logs
cpu_lower_threshold: 20
memory_upper_threshold: 80
memory_lower_threshold: 20
min_cores: 1
max_cores: 4 # Increased based on usage patterns
min_memory: 4096 # Adjusted based on current allocation
max_cores: 4
min_memory: 4096
core_min_increment: 1
core_max_increment: 2
memory_min_increment: 1024
min_decrease_chunk: 1024

TIER_other:
lxc_containers:
- 103 # Removed 104 as it should be ignored
- 103
cpu_upper_threshold: 60
cpu_lower_threshold: 20 # Adjusted to match logs
cpu_lower_threshold: 20
memory_upper_threshold: 50
memory_lower_threshold: 20
min_cores: 1
max_cores: 2
min_memory: 256 # Matches current allocation
min_memory: 256
core_min_increment: 1
core_max_increment: 1
memory_min_increment: 128
Expand Down
17 changes: 11 additions & 6 deletions lxc_autoscale/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

import lxc_utils
import scaling_manager
from config import config
from config import (
config,
DEFAULTS,
LXC_TIER_ASSOCIATIONS,
IGNORE_LXC
)
from notification import send_notification


Expand Down Expand Up @@ -85,18 +90,18 @@ def collect_container_data() -> Dict[str, Dict[str, Any]]:
result = future.result()
if result:
containers.update(result)
# Apply tier settings with validation
tier_config = config.get("tiers", {}).get(ctid)
# Apply tier settings
tier_config = LXC_TIER_ASSOCIATIONS.get(ctid)
if tier_config:
if validate_tier_config(ctid, tier_config):
containers[ctid].update(tier_config)
logging.info(f"Applied validated tier settings for container {ctid}: {tier_config}")
logging.info(f"Applied tier settings for container {ctid} from tier {tier_config.get('tier_name', 'unknown')}")
else:
logging.warning(f"Using default settings for container {ctid} due to invalid tier configuration")
containers[ctid].update(config.get("DEFAULTS", {}))
containers[ctid].update(DEFAULTS)
else:
logging.info(f"No tier settings found for container {ctid}, using defaults")
containers[ctid].update(config.get("DEFAULTS", {}))
containers[ctid].update(DEFAULTS)
except Exception as e:
logging.error(f"Error collecting data for container {ctid}: {e}")

Expand Down

0 comments on commit 2c7de96

Please sign in to comment.