feat: add version column to node tables

- Shows PVE/PBS version in node summary tables
- Helps quickly identify nodes needing updates
- Extracts just version number from PVE (e.g. 9.0.5)
- Also improved mock mode system for local development
This commit is contained in:
Pulse Monitor
2025-08-29 10:58:23 +00:00
parent c2917947ec
commit e6c15f620a
5 changed files with 119 additions and 61 deletions
+3
View File
@@ -94,5 +94,8 @@ scripts/TEST_*.md
mock.env
internal/mock/
internal/monitoring/mock_integration.go
internal/monitoring/mock_stub.go
scripts/mock-dev.sh
scripts/toggle-mock.sh
scripts/toggle-mock-pure.sh
MOCK_MODE_GUIDE.md
@@ -75,6 +75,9 @@ export const PBSNodeTable: Component<PBSNodeTableProps> = (props) => {
<th class="px-2 py-1.5 text-left text-[11px] sm:text-xs font-medium uppercase tracking-wider whitespace-nowrap" style="min-width: 80px;">
Status
</th>
<th class="px-2 py-1.5 text-left text-[11px] sm:text-xs font-medium uppercase tracking-wider whitespace-nowrap">
Version
</th>
<th class="px-2 py-1.5 text-center text-[11px] sm:text-xs font-medium uppercase tracking-wider whitespace-nowrap" style="min-width: 100px;">
Datastores
</th>
@@ -180,6 +183,13 @@ export const PBSNodeTable: Component<PBSNodeTableProps> = (props) => {
{pbs.status}
</span>
</td>
<td class="p-1 px-2">
<span class="text-xs text-gray-600 dark:text-gray-400 whitespace-nowrap">
<Show when={pbs.version} fallback="-">
{pbs.version}
</Show>
</span>
</td>
<td class="p-1 px-2 text-center">
<span class="text-xs font-medium text-gray-700 dark:text-gray-300">
{pbs.datastores?.length || 0}
@@ -235,7 +245,7 @@ export const PBSNodeTable: Component<PBSNodeTableProps> = (props) => {
<>
{/* Datastore row */}
<tr class="bg-gray-50 dark:bg-gray-800/50 border-b border-gray-100 dark:border-gray-700/30">
<td colspan="8" class="px-8 py-1">
<td colspan="9" class="px-8 py-1">
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<svg class="w-4 h-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -286,7 +296,7 @@ export const PBSNodeTable: Component<PBSNodeTableProps> = (props) => {
}
}}
>
<td colspan="8" class="px-12 py-0.5">
<td colspan="9" class="px-12 py-0.5">
<div class="flex items-center gap-2">
<svg
class={`w-3 h-3 ${isSelected() ? 'text-blue-600 dark:text-blue-400' : 'text-gray-400'}`}
@@ -124,6 +124,9 @@ export const PVENodeTable: Component<PVENodeTableProps> = (props) => {
<th class="px-2 py-1.5 text-left text-[11px] sm:text-xs font-medium uppercase tracking-wider whitespace-nowrap" style="min-width: 100px;">
Cluster
</th>
<th class="px-2 py-1.5 text-left text-[11px] sm:text-xs font-medium uppercase tracking-wider whitespace-nowrap">
Version
</th>
<For each={getCountHeaders()}>
{(header) => (
<th class="px-2 py-1.5 text-center text-[11px] sm:text-xs font-medium uppercase tracking-wider whitespace-nowrap" style="min-width: 80px;">
@@ -195,6 +198,13 @@ export const PVENodeTable: Component<PVENodeTableProps> = (props) => {
{node.clusterName || '-'}
</span>
</td>
<td class="p-1 px-2">
<span class="text-xs text-gray-600 dark:text-gray-400 whitespace-nowrap" title={node.pveVersion || ''}>
<Show when={node.pveVersion} fallback="-">
{node.pveVersion.split('/')[1] || node.pveVersion}
</Show>
</span>
</td>
<For each={counts}>
{(count) => (
<td class="p-1 px-2 text-center">
+2 -8
View File
@@ -2116,18 +2116,12 @@ func (m *Monitor) pollPBSInstance(ctx context.Context, instanceName string, clie
}
}
// getMockState returns mock data when mock mode is enabled
func getMockState() *models.StateSnapshot {
// Mock support removed from production builds
return nil
}
// GetState returns the current state
func (m *Monitor) GetState() models.StateSnapshot {
// Check if mock mode is enabled
if os.Getenv("PULSE_MOCK_MODE") == "true" {
// Import mock package and return mock data
if mockData := getMockState(); mockData != nil {
// Try to get mock data if compiled with mock support
if mockData := tryGetMockState(); mockData != nil {
return *mockData
}
}
+92 -51
View File
@@ -1,64 +1,105 @@
#!/bin/bash
# Pure mock mode toggle - disables real nodes completely
# This is a workaround until we properly integrate mock mode to skip node initialization
# Pure mock mode toggle - completely disables real nodes when mock is enabled
# This ensures no mixing of real and mock data
RED='\033[0;31m'
GREEN='\033[0;32m'
MODE="${1:-status}"
MOCK_ENV="/opt/pulse/mock.env"
SERVICE_DIR="/etc/systemd/system/pulse-backend.service.d"
MOCK_CONF="$SERVICE_DIR/mock.conf"
# Colors for output
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
RESET='\033[0m'
NODES_FILE="/etc/pulse/nodes.enc"
NODES_BACKUP="/etc/pulse/nodes.enc.real"
enable_pure_mock() {
echo -e "${YELLOW}Enabling PURE mock mode (no real nodes)...${NC}"
# Backup real nodes if they exist
if [ -f "$NODES_FILE" ]; then
sudo mv "$NODES_FILE" "$NODES_BACKUP"
echo -e "${GREEN}Real nodes config backed up${NC}"
fi
# Enable mock mode
/opt/pulse/scripts/toggle-mock.sh on
echo -e "${GREEN}✓ Pure mock mode enabled!${NC}"
echo -e "${YELLOW}Real nodes are completely disabled${NC}"
}
disable_pure_mock() {
echo -e "${YELLOW}Restoring real nodes...${NC}"
# Restore real nodes
if [ -f "$NODES_BACKUP" ]; then
sudo mv "$NODES_BACKUP" "$NODES_FILE"
echo -e "${GREEN}Real nodes config restored${NC}"
fi
# Disable mock mode
/opt/pulse/scripts/toggle-mock.sh off
echo -e "${GREEN}✓ Back to real nodes!${NC}"
}
case "$1" in
case "$MODE" in
on)
enable_pure_mock
echo -e "${YELLOW}Enabling PURE mock mode (disabling all real nodes)...${RESET}"
# Create the service override directory if it doesn't exist
sudo mkdir -p "$SERVICE_DIR"
# Create override to set mock mode and disable real nodes
sudo tee "$MOCK_CONF" > /dev/null <<EOF
[Service]
Environment="PULSE_MOCK_MODE=true"
Environment="PULSE_DISABLE_REAL_NODES=true"
EnvironmentFile=-/opt/pulse/mock.env
EOF
# Ensure mock.env exists with good defaults
if [ ! -f "$MOCK_ENV" ]; then
cat > "$MOCK_ENV" <<'EOF'
# Mock Mode Configuration
PULSE_MOCK_MODE=true
PULSE_MOCK_NODES=7
PULSE_MOCK_VMS_PER_NODE=5
PULSE_MOCK_LXCS_PER_NODE=8
PULSE_MOCK_RANDOM_METRICS=true
PULSE_MOCK_STOPPED_PERCENT=20
EOF
else
# Ensure mock mode is enabled in the file
sed -i 's/PULSE_MOCK_MODE=false/PULSE_MOCK_MODE=true/' "$MOCK_ENV"
fi
# Build with mock support
echo -e "${YELLOW}Building Pulse with mock support...${RESET}"
cd /opt/pulse
go build -tags "mock" -o bin/pulse ./cmd/pulse
# Reload and restart
sudo systemctl daemon-reload
sudo systemctl restart pulse-backend
echo -e "${GREEN}✓ PURE mock mode enabled!${RESET}"
echo -e "Real nodes are completely disabled."
echo -e "Access Pulse at: ${GREEN}http://localhost:7655${RESET}"
;;
off)
disable_pure_mock
echo -e "${YELLOW}Disabling mock mode (restoring real nodes)...${RESET}"
# Remove the mock override
sudo rm -f "$MOCK_CONF"
# Update mock.env to disable mock mode
if [ -f "$MOCK_ENV" ]; then
sed -i 's/PULSE_MOCK_MODE=true/PULSE_MOCK_MODE=false/' "$MOCK_ENV"
fi
# Build without mock support for production
echo -e "${YELLOW}Building Pulse for production...${RESET}"
cd /opt/pulse
go build -o bin/pulse ./cmd/pulse
# Reload and restart
sudo systemctl daemon-reload
sudo systemctl restart pulse-backend
echo -e "${GREEN}✓ Mock mode disabled!${RESET}"
echo -e "Real nodes are now active."
;;
status)
if [ -f "$MOCK_CONF" ] && grep -q "PULSE_MOCK_MODE=true" "$MOCK_CONF" 2>/dev/null; then
echo -e "${GREEN}Mock mode: ENABLED (Pure mode - real nodes disabled)${RESET}"
if [ -f "$MOCK_ENV" ]; then
echo "Mock configuration:"
grep -E "PULSE_MOCK" "$MOCK_ENV" | grep -v "^#"
fi
else
echo -e "${YELLOW}Mock mode: DISABLED (using real nodes)${RESET}"
fi
;;
*)
echo "Pure Mock Mode Toggle"
echo "====================="
echo "Usage: $0 {on|off|status}"
echo ""
echo "This completely disables real nodes for pure mock testing"
echo ""
echo "Usage: $0 {on|off}"
echo ""
echo " on - Enable pure mock mode (no real nodes)"
echo " off - Restore real nodes"
echo " on - Enable PURE mock mode (no real nodes)"
echo " off - Disable mock mode (use real nodes)"
echo " status - Show current mode"
exit 1
;;
esac