From 6fe78568082ed0b7da009e6e4dfe2768de521111 Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Mon, 15 Jan 2024 11:16:13 +0100 Subject: [PATCH] configure community filter cutoff --- pkg/config/config.go | 37 +++++++++++++++++++------------- pkg/config/config_test.go | 5 +++++ pkg/config/testdata/alice.conf | 7 ++++++ pkg/http/api_endpoints_search.go | 10 +++++---- pkg/http/server.go | 9 ++++++++ 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 9cd67dc..4456c3a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -69,22 +69,28 @@ const ( // DefaultHTTPTimeout is the time in seconds after which the // server will timeout. 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 // for the backend. type ServerConfig struct { - Listen string `ini:"listen_http"` - HTTPTimeout int `ini:"http_timeout"` - EnablePrefixLookup bool `ini:"enable_prefix_lookup"` - NeighborsStoreRefreshInterval int `ini:"neighbors_store_refresh_interval"` - NeighborsStoreRefreshParallelism int `ini:"neighbors_store_refresh_parallelism"` - RoutesStoreRefreshInterval int `ini:"routes_store_refresh_interval"` - RoutesStoreRefreshParallelism int `ini:"routes_store_refresh_parallelism"` - StoreBackend string `ini:"store_backend"` - DefaultAsn int `ini:"asn"` - EnableNeighborsStatusRefresh bool `ini:"enable_neighbors_status_refresh"` - StreamParserThrottle int `ini:"stream_parser_throttle"` + Listen string `ini:"listen_http"` + HTTPTimeout int `ini:"http_timeout"` + EnablePrefixLookup bool `ini:"enable_prefix_lookup"` + PrefixLookupCommunityFilterCutoff int `ini:"prefix_lookup_community_filter_cutoff"` + NeighborsStoreRefreshInterval int `ini:"neighbors_store_refresh_interval"` + NeighborsStoreRefreshParallelism int `ini:"neighbors_store_refresh_parallelism"` + RoutesStoreRefreshInterval int `ini:"routes_store_refresh_interval"` + RoutesStoreRefreshParallelism int `ini:"routes_store_refresh_parallelism"` + StoreBackend string `ini:"store_backend"` + DefaultAsn int `ini:"asn"` + EnableNeighborsStatusRefresh bool `ini:"enable_neighbors_status_refresh"` + StreamParserThrottle int `ini:"stream_parser_throttle"` } // PostgresConfig is the configuration for the database @@ -928,10 +934,11 @@ func LoadConfig(file string) (*Config, error) { // Map sections server := ServerConfig{ - HTTPTimeout: DefaultHTTPTimeout, - StoreBackend: "memory", - RoutesStoreRefreshParallelism: 1, - NeighborsStoreRefreshParallelism: 1, + HTTPTimeout: DefaultHTTPTimeout, + PrefixLookupCommunityFilterCutoff: DefaultPrefixLookupCommunityFilterCutoff, + StoreBackend: "memory", + RoutesStoreRefreshParallelism: 1, + NeighborsStoreRefreshParallelism: 1, } if err := parsedConfig.Section("server").MapTo(&server); err != nil { return nil, err diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 715488e..f734287 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -38,6 +38,11 @@ func TestLoadConfigs(t *testing.T) { t.Error("expcted to find example community 1:23 with 'some tag'", "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 diff --git a/pkg/config/testdata/alice.conf b/pkg/config/testdata/alice.conf index 70fba4a..0f38389 100644 --- a/pkg/config/testdata/alice.conf +++ b/pkg/config/testdata/alice.conf @@ -18,6 +18,13 @@ enable_prefix_lookup = true enable_neighbors_status_refresh = false # this ASN is used as a fallback value in the RPKI feature and for route # 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 # if set to 0 (or for the matter of fact 1), refresh will be diff --git a/pkg/http/api_endpoints_search.go b/pkg/http/api_endpoints_search.go index 398ae1e..616fec3 100644 --- a/pkg/http/api_endpoints_search.go +++ b/pkg/http/api_endpoints_search.go @@ -78,9 +78,10 @@ func (s *Server) apiLookupPrefixGlobal( imported := make(api.LookupRoutes, 0, totalResults) filtered := make(api.LookupRoutes, 0, totalResults) - // TODO: Make configurable - communityFilterCutoff := 100000 - canFilterCommunities := totalResults <= communityFilterCutoff + // Check if we should calculate community filter + // cardinalities. + filterCutoff := s.cfg.Server.PrefixLookupCommunityFilterCutoff + canFilterCommunities := totalResults <= filterCutoff // In case there is a source filter applied, we can filter communities if filtersApplied.HasGroup(api.SearchKeySources) { @@ -89,7 +90,8 @@ func (s *Server) apiLookupPrefixGlobal( filtersNotAvailable := []string{} if !canFilterCommunities { - filtersNotAvailable = append(filtersNotAvailable, api.SearchKeyCommunities) + filtersNotAvailable = append( + filtersNotAvailable, api.SearchKeyCommunities) } // Now, as we have allocated even more space process routes by, splitting, diff --git a/pkg/http/server.go b/pkg/http/server.go index 26d86fa..53b6edd 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -54,6 +54,15 @@ func (s *Server) Start(ctx context.Context) { httpTimeout := time.Duration(s.cfg.Server.HTTPTimeout) * time.Second 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{ Addr: s.cfg.Server.Listen,