configure community filter cutoff

This commit is contained in:
Annika Hannig 2024-01-15 11:16:13 +01:00
parent 01491ec0b4
commit 6fe7856808
5 changed files with 49 additions and 19 deletions

View File

@ -69,22 +69,28 @@ const (
// DefaultHTTPTimeout is the time in seconds after which the // DefaultHTTPTimeout is the time in seconds after which the
// server will timeout. // server will timeout.
DefaultHTTPTimeout = 120 DefaultHTTPTimeout = 120
// DefaultPrefixLookupCommunityFilterCutoff is the number of
// routes after which the community filter will not be
// available.
DefaultPrefixLookupCommunityFilterCutoff = 100000
) )
// A ServerConfig holds the runtime configuration // A ServerConfig holds the runtime configuration
// for the backend. // for the backend.
type ServerConfig struct { type ServerConfig struct {
Listen string `ini:"listen_http"` Listen string `ini:"listen_http"`
HTTPTimeout int `ini:"http_timeout"` HTTPTimeout int `ini:"http_timeout"`
EnablePrefixLookup bool `ini:"enable_prefix_lookup"` EnablePrefixLookup bool `ini:"enable_prefix_lookup"`
NeighborsStoreRefreshInterval int `ini:"neighbors_store_refresh_interval"` PrefixLookupCommunityFilterCutoff int `ini:"prefix_lookup_community_filter_cutoff"`
NeighborsStoreRefreshParallelism int `ini:"neighbors_store_refresh_parallelism"` NeighborsStoreRefreshInterval int `ini:"neighbors_store_refresh_interval"`
RoutesStoreRefreshInterval int `ini:"routes_store_refresh_interval"` NeighborsStoreRefreshParallelism int `ini:"neighbors_store_refresh_parallelism"`
RoutesStoreRefreshParallelism int `ini:"routes_store_refresh_parallelism"` RoutesStoreRefreshInterval int `ini:"routes_store_refresh_interval"`
StoreBackend string `ini:"store_backend"` RoutesStoreRefreshParallelism int `ini:"routes_store_refresh_parallelism"`
DefaultAsn int `ini:"asn"` StoreBackend string `ini:"store_backend"`
EnableNeighborsStatusRefresh bool `ini:"enable_neighbors_status_refresh"` DefaultAsn int `ini:"asn"`
StreamParserThrottle int `ini:"stream_parser_throttle"` EnableNeighborsStatusRefresh bool `ini:"enable_neighbors_status_refresh"`
StreamParserThrottle int `ini:"stream_parser_throttle"`
} }
// PostgresConfig is the configuration for the database // PostgresConfig is the configuration for the database
@ -928,10 +934,11 @@ func LoadConfig(file string) (*Config, error) {
// Map sections // Map sections
server := ServerConfig{ server := ServerConfig{
HTTPTimeout: DefaultHTTPTimeout, HTTPTimeout: DefaultHTTPTimeout,
StoreBackend: "memory", PrefixLookupCommunityFilterCutoff: DefaultPrefixLookupCommunityFilterCutoff,
RoutesStoreRefreshParallelism: 1, StoreBackend: "memory",
NeighborsStoreRefreshParallelism: 1, RoutesStoreRefreshParallelism: 1,
NeighborsStoreRefreshParallelism: 1,
} }
if err := parsedConfig.Section("server").MapTo(&server); err != nil { if err := parsedConfig.Section("server").MapTo(&server); err != nil {
return nil, err return nil, err

View File

@ -38,6 +38,11 @@ func TestLoadConfigs(t *testing.T) {
t.Error("expcted to find example community 1:23 with 'some tag'", t.Error("expcted to find example community 1:23 with 'some tag'",
"but got:", label) "but got:", label)
} }
// Check prefix lookup cutoff
if config.Server.PrefixLookupCommunityFilterCutoff != 123 {
t.Error("Expected PrefixLookupCommunityFilterCutoff to be 123")
}
} }
// TestSourceConfig checks that the proper backend type was identified for each // TestSourceConfig checks that the proper backend type was identified for each

View File

@ -18,6 +18,13 @@ enable_prefix_lookup = true
enable_neighbors_status_refresh = false enable_neighbors_status_refresh = false
# this ASN is used as a fallback value in the RPKI feature and for route # this ASN is used as a fallback value in the RPKI feature and for route
# filtering evaluation with large BGP communities # filtering evaluation with large BGP communities
#
# Prefix lookup community filter cutoff defines an upper limit
# of returned routes for which the community filters list is
# available. If the number of routes exceeds this limit, the
# communities filters become available if there is a specific
# route server selected.
prefix_lookup_community_filter_cutoff = 123
# how many route servers will be refreshed at the same time # how many route servers will be refreshed at the same time
# if set to 0 (or for the matter of fact 1), refresh will be # if set to 0 (or for the matter of fact 1), refresh will be

View File

@ -78,9 +78,10 @@ func (s *Server) apiLookupPrefixGlobal(
imported := make(api.LookupRoutes, 0, totalResults) imported := make(api.LookupRoutes, 0, totalResults)
filtered := make(api.LookupRoutes, 0, totalResults) filtered := make(api.LookupRoutes, 0, totalResults)
// TODO: Make configurable // Check if we should calculate community filter
communityFilterCutoff := 100000 // cardinalities.
canFilterCommunities := totalResults <= communityFilterCutoff filterCutoff := s.cfg.Server.PrefixLookupCommunityFilterCutoff
canFilterCommunities := totalResults <= filterCutoff
// In case there is a source filter applied, we can filter communities // In case there is a source filter applied, we can filter communities
if filtersApplied.HasGroup(api.SearchKeySources) { if filtersApplied.HasGroup(api.SearchKeySources) {
@ -89,7 +90,8 @@ func (s *Server) apiLookupPrefixGlobal(
filtersNotAvailable := []string{} filtersNotAvailable := []string{}
if !canFilterCommunities { if !canFilterCommunities {
filtersNotAvailable = append(filtersNotAvailable, api.SearchKeyCommunities) filtersNotAvailable = append(
filtersNotAvailable, api.SearchKeyCommunities)
} }
// Now, as we have allocated even more space process routes by, splitting, // Now, as we have allocated even more space process routes by, splitting,

View File

@ -54,6 +54,15 @@ func (s *Server) Start(ctx context.Context) {
httpTimeout := time.Duration(s.cfg.Server.HTTPTimeout) * time.Second httpTimeout := time.Duration(s.cfg.Server.HTTPTimeout) * time.Second
log.Println("Web server HTTP timeout set to:", httpTimeout) log.Println("Web server HTTP timeout set to:", httpTimeout)
log.Println("Listening on:", s.cfg.Server.Listen)
if s.cfg.Server.EnablePrefixLookup {
log.Println("Prefix Lookup (Search): enabled")
log.Println("Prefix Lookup Community Filter Cutoff:",
s.cfg.Server.PrefixLookupCommunityFilterCutoff)
} else {
log.Println("Prefix Lookup (Search): disabled")
}
s.Server = &http.Server{ s.Server = &http.Server{
Addr: s.cfg.Server.Listen, Addr: s.cfg.Server.Listen,