Remove RoutingTableHandler and snapshotter, use database for route stats
- Remove RoutingTableHandler as PrefixHandler maintains live_routes table - Update server to get route counts from database instead of in-memory routing table - Add GetLiveRouteCounts method to database for IPv4/IPv6 route counts - Use metrics tracker in PrefixHandler for route update rates - Remove snapshotter entirely as database contains all information - Update tests to work without routing table
This commit is contained in:
@@ -522,3 +522,20 @@ func (d *Database) GetPrefixDistribution() (ipv4 []PrefixDistribution, ipv6 []Pr
|
||||
|
||||
return ipv4, ipv6, nil
|
||||
}
|
||||
|
||||
// GetLiveRouteCounts returns the count of IPv4 and IPv6 routes
|
||||
func (d *Database) GetLiveRouteCounts() (ipv4Count, ipv6Count int, err error) {
|
||||
// Get IPv4 count
|
||||
err = d.db.QueryRow("SELECT COUNT(*) FROM live_routes WHERE ip_version = 4").Scan(&ipv4Count)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("failed to count IPv4 routes: %w", err)
|
||||
}
|
||||
|
||||
// Get IPv6 count
|
||||
err = d.db.QueryRow("SELECT COUNT(*) FROM live_routes WHERE ip_version = 6").Scan(&ipv6Count)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("failed to count IPv6 routes: %w", err)
|
||||
}
|
||||
|
||||
return ipv4Count, ipv6Count, nil
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ type Store interface {
|
||||
UpsertLiveRoute(route *LiveRoute) error
|
||||
DeleteLiveRoute(prefix string, originASN int, peerIP string) error
|
||||
GetPrefixDistribution() (ipv4 []PrefixDistribution, ipv6 []PrefixDistribution, err error)
|
||||
GetLiveRouteCounts() (ipv4Count, ipv6Count int, err error)
|
||||
|
||||
// Lifecycle
|
||||
Close() error
|
||||
|
||||
Reference in New Issue
Block a user