Pulse/internal/config
rcourtman 20854256c3 Fix VM migration issue where custom alert thresholds are lost
Resolves #641

## Problem
When a VM migrates between Proxmox nodes, Pulse was treating it as a new
resource and discarding custom alert threshold overrides. This occurred
because guest IDs included the node name (e.g., `instance-node-VMID`),
causing the ID to change when the VM moved to a different node.

Users reported that after migrating a VM, previously disabled alerts
(e.g., memory threshold set to 0) would resume firing.

## Root Cause
Guest IDs were constructed as:
- Standalone: `node-VMID`
- Cluster: `instance-node-VMID`

When a VM migrated from node1 to node2, the ID changed from
`instance-node1-100` to `instance-node2-100`, causing:
- Alert threshold overrides to be orphaned (keyed by old ID)
- Guest metadata (custom URLs, descriptions) to be orphaned
- Active alerts to reference the wrong resource ID

## Solution
Changed guest ID format to be stable across node migrations:
- New format: `instance-VMID` (for both standalone and cluster)
- Retains uniqueness across instances while being node-independent
- Allows VMs to migrate freely without losing configuration

## Implementation

### Backend Changes
1. **Guest ID Construction** (`monitor_polling.go`):
   - Simplified to always use `instance-VMID` format
   - Removed node from the ID construction logic

2. **Alert Override Migration** (`alerts.go`):
   - Added lazy migration in `getGuestThresholds()`
   - Detects legacy ID formats and migrates to new format
   - Preserves user configurations automatically

3. **Guest Metadata Migration** (`guest_metadata.go`):
   - Added `GetWithLegacyMigration()` helper method
   - Called during VM/container polling to migrate metadata
   - Preserves custom URLs and descriptions

4. **Active Alerts Migration** (`alerts.go`):
   - Added migration logic in `LoadActiveAlerts()`
   - Translates legacy alert resource IDs to new format
   - Preserves alert acknowledgments across restarts

### Frontend Changes
5. **ID Construction Updates**:
   - `ThresholdsTable.tsx`: Updated fallback from `instance-node-vmid` to `instance-vmid`
   - `Dashboard.tsx`: Simplified guest ID construction
   - `GuestRow.tsx`: Updated `buildGuestId()` helper

## Migration Strategy
- **Lazy Migration**: Configs are migrated as guests are discovered
- **Backwards Compatible**: Old IDs are detected and automatically converted
- **Zero Downtime**: No manual intervention required
- **Persisted**: Migrated configs are saved on next config write cycle

## Testing Recommendations
After deployment:
1. Verify existing alert overrides still apply
2. Test VM migration - confirm thresholds persist
3. Check guest metadata (custom URLs) survive migration
4. Verify active alerts maintain acknowledgment state

## Related
- Addresses similar issues with guest metadata and active alert tracking
- Lays groundwork for any future guest-specific configuration features
- Aligns with project philosophy: correctness and UX over implementation complexity
2025-11-06 10:27:15 +00:00
..
api_tokens.go feat: add native Windows service support and expandable host details 2025-10-23 22:11:56 +00:00
api_tokens_test.go Add API token scopes and standalone host agent 2025-10-23 11:40:31 +00:00
client_helpers.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
config.go Add configurable SSH port for temperature monitoring 2025-11-05 20:03:29 +00:00
credentials.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
docker_metadata.go Implement Docker metadata API endpoints 2025-10-28 22:56:53 +00:00
export.go feat: production-ready import/export with API tokens and transactional rollback 2025-10-21 14:37:44 +00:00
guest_metadata.go Fix VM migration issue where custom alert thresholds are lost 2025-11-06 10:27:15 +00:00
import_transaction.go feat: production-ready import/export with API tokens and transactional rollback 2025-10-21 14:37:44 +00:00
oidc.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
persistence.go Add configurable SSH port for temperature monitoring 2025-11-05 20:03:29 +00:00
persistence_fail_test.go Harden setup token flow and enforce encrypted persistence 2025-10-25 16:00:37 +00:00
persistence_test.go Add API token scopes and standalone host agent 2025-10-23 11:40:31 +00:00
registration.go Fix settings security tab navigation 2025-10-11 23:29:47 +00:00
watcher.go Add disk metrics, block I/O, and mount details to Docker monitoring 2025-10-29 12:05:36 +00:00