From 03131c443cb935f51428e223318491d1b8abdb56 Mon Sep 17 00:00:00 2001 From: Kwitsch Date: Wed, 20 Dec 2023 21:38:33 +0100 Subject: [PATCH] Refactoring/config struct names (#1315) * vscode config changed in new version * FilteringConfig -> Filtering * CachingConfig -> Caching * QueryLogConfig -> QueryLog * MetricsConfig -> Metrics * HostsFileConfig -> HostsFile * PortsConfig -> Ports * BootstrapDNSConfig -> BootstrapDNS * BootstrappedUpstreamConfig -> BootstrappedUpstream * bootstrapDNSConfig -> bootstrapDNS * bootstrappedUpstreamConfig -> bootstrappedUpstream * SourceLoadingConfig -> SourceLoading * DownloaderConfig -> Downloader --- .vscode/settings.json | 4 +- config/blocking.go | 2 +- config/caching.go | 10 +-- config/caching_test.go | 14 ++--- config/config.go | 82 ++++++++++++------------- config/config_test.go | 18 +++--- config/filtering.go | 6 +- config/filtering_test.go | 8 +-- config/hosts_file.go | 16 ++--- config/hosts_file_test.go | 12 ++-- config/metrics.go | 8 +-- config/metrics_test.go | 8 +-- config/query_log.go | 10 +-- config/query_log_test.go | 10 +-- lists/downloader.go | 6 +- lists/downloader_test.go | 12 ++-- lists/list_cache.go | 4 +- lists/list_cache_benchmark_test.go | 4 +- lists/list_cache_test.go | 6 +- metrics/metrics.go | 2 +- resolver/blocking_resolver_test.go | 4 +- resolver/bootstrap.go | 6 +- resolver/bootstrap_test.go | 20 +++--- resolver/caching_resolver.go | 8 +-- resolver/caching_resolver_test.go | 20 +++--- resolver/filtering_resolver.go | 4 +- resolver/filtering_resolver_test.go | 6 +- resolver/hosts_file_resolver.go | 4 +- resolver/hosts_file_resolver_test.go | 8 +-- resolver/metrics_resolver.go | 4 +- resolver/metrics_resolver_test.go | 2 +- resolver/mocks_test.go | 2 +- resolver/query_logging_resolver.go | 4 +- resolver/query_logging_resolver_test.go | 20 +++--- server/server_test.go | 10 +-- 35 files changed, 182 insertions(+), 182 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4f04c36b..5dd5d8d3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,8 +5,8 @@ "editor.formatOnSave": true, "editor.formatOnPaste": true, "editor.codeActionsOnSave": { - "source.organizeImports": true, - "source.fixAll": true + "source.organizeImports": "explicit", + "source.fixAll": "explicit" }, "editor.rulers": [120], "go.showWelcome": false, diff --git a/config/blocking.go b/config/blocking.go index af4d8e35..aa7520d3 100644 --- a/config/blocking.go +++ b/config/blocking.go @@ -13,7 +13,7 @@ type Blocking struct { ClientGroupsBlock map[string][]string `yaml:"clientGroupsBlock"` BlockType string `yaml:"blockType" default:"ZEROIP"` BlockTTL Duration `yaml:"blockTTL" default:"6h"` - Loading SourceLoadingConfig `yaml:"loading"` + Loading SourceLoading `yaml:"loading"` // Deprecated options Deprecated struct { diff --git a/config/caching.go b/config/caching.go index 0d86a383..49aa98b3 100644 --- a/config/caching.go +++ b/config/caching.go @@ -6,8 +6,8 @@ import ( "github.com/sirupsen/logrus" ) -// CachingConfig configuration for domain caching -type CachingConfig struct { +// Caching configuration for domain caching +type Caching struct { MinCachingTime Duration `yaml:"minTime"` MaxCachingTime Duration `yaml:"maxTime"` CacheTimeNegative Duration `yaml:"cacheTimeNegative" default:"30m"` @@ -19,12 +19,12 @@ type CachingConfig struct { } // IsEnabled implements `config.Configurable`. -func (c *CachingConfig) IsEnabled() bool { +func (c *Caching) IsEnabled() bool { return c.MaxCachingTime.IsAtLeastZero() } // LogConfig implements `config.Configurable`. -func (c *CachingConfig) LogConfig(logger *logrus.Entry) { +func (c *Caching) LogConfig(logger *logrus.Entry) { logger.Infof("minTime = %s", c.MinCachingTime) logger.Infof("maxTime = %s", c.MaxCachingTime) logger.Infof("cacheTimeNegative = %s", c.CacheTimeNegative) @@ -39,7 +39,7 @@ func (c *CachingConfig) LogConfig(logger *logrus.Entry) { } } -func (c *CachingConfig) EnablePrefetch() { +func (c *Caching) EnablePrefetch() { const day = Duration(24 * time.Hour) if !c.IsEnabled() { diff --git a/config/caching_test.go b/config/caching_test.go index 8be9dace..80a1241a 100644 --- a/config/caching_test.go +++ b/config/caching_test.go @@ -9,19 +9,19 @@ import ( ) var _ = Describe("CachingConfig", func() { - var cfg CachingConfig + var cfg Caching suiteBeforeEach() BeforeEach(func() { - cfg = CachingConfig{ + cfg = Caching{ MaxCachingTime: Duration(time.Hour), } }) Describe("IsEnabled", func() { It("should be true by default", func() { - cfg := CachingConfig{} + cfg := Caching{} Expect(defaults.Set(&cfg)).Should(Succeed()) Expect(cfg.IsEnabled()).Should(BeTrue()) @@ -29,7 +29,7 @@ var _ = Describe("CachingConfig", func() { When("the config is disabled", func() { BeforeEach(func() { - cfg = CachingConfig{ + cfg = Caching{ MaxCachingTime: Duration(time.Hour * -1), } }) @@ -46,7 +46,7 @@ var _ = Describe("CachingConfig", func() { When("the config is disabled", func() { It("should be false", func() { - cfg := CachingConfig{ + cfg := Caching{ MaxCachingTime: Duration(-1), } @@ -58,7 +58,7 @@ var _ = Describe("CachingConfig", func() { Describe("LogConfig", func() { When("prefetching is enabled", func() { BeforeEach(func() { - cfg = CachingConfig{ + cfg = Caching{ Prefetching: true, } }) @@ -75,7 +75,7 @@ var _ = Describe("CachingConfig", func() { Describe("EnablePrefetch", func() { When("prefetching is enabled", func() { BeforeEach(func() { - cfg = CachingConfig{} + cfg = Caching{} }) It("should return configuration", func() { diff --git a/config/config.go b/config/config.go index c2525258..9875609f 100644 --- a/config/config.go +++ b/config/config.go @@ -171,41 +171,41 @@ func (l *ListenConfig) UnmarshalText(data []byte) error { return nil } -// UnmarshalYAML creates BootstrapDNSConfig from YAML -func (b *BootstrapDNSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { - var single BootstrappedUpstreamConfig +// UnmarshalYAML creates BootstrapDNS from YAML +func (b *BootstrapDNS) UnmarshalYAML(unmarshal func(interface{}) error) error { + var single BootstrappedUpstream if err := unmarshal(&single); err == nil { - *b = BootstrapDNSConfig{single} + *b = BootstrapDNS{single} return nil } - // bootstrapDNSConfig is used to avoid infinite recursion: - // if we used BootstrapDNSConfig, unmarshal would just call us again. - var c bootstrapDNSConfig + // bootstrapDNS is used to avoid infinite recursion: + // if we used BootstrapDNS, unmarshal would just call us again. + var c bootstrapDNS if err := unmarshal(&c); err != nil { return err } - *b = BootstrapDNSConfig(c) + *b = BootstrapDNS(c) return nil } -// UnmarshalYAML creates BootstrapConfig from YAML -func (b *BootstrappedUpstreamConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { +// UnmarshalYAML creates BootstrappedUpstream from YAML +func (b *BootstrappedUpstream) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := unmarshal(&b.Upstream); err == nil { return nil } - // bootstrapConfig is used to avoid infinite recursion: - // if we used BootstrapConfig, unmarshal would just call us again. - var c bootstrappedUpstreamConfig + // bootstrappedUpstream is used to avoid infinite recursion: + // if we used BootstrappedUpstream, unmarshal would just call us again. + var c bootstrappedUpstream if err := unmarshal(&c); err != nil { return err } - *b = BootstrappedUpstreamConfig(c) + *b = BootstrappedUpstream(c) return nil } @@ -218,19 +218,19 @@ type Config struct { Conditional ConditionalUpstream `yaml:"conditional"` Blocking Blocking `yaml:"blocking"` ClientLookup ClientLookup `yaml:"clientLookup"` - Caching CachingConfig `yaml:"caching"` - QueryLog QueryLogConfig `yaml:"queryLog"` - Prometheus MetricsConfig `yaml:"prometheus"` + Caching Caching `yaml:"caching"` + QueryLog QueryLog `yaml:"queryLog"` + Prometheus Metrics `yaml:"prometheus"` Redis Redis `yaml:"redis"` Log log.Config `yaml:"log"` - Ports PortsConfig `yaml:"ports"` + Ports Ports `yaml:"ports"` MinTLSServeVer TLSVersion `yaml:"minTlsServeVersion" default:"1.2"` CertFile string `yaml:"certFile"` KeyFile string `yaml:"keyFile"` - BootstrapDNS BootstrapDNSConfig `yaml:"bootstrapDns"` - HostsFile HostsFileConfig `yaml:"hostsFile"` + BootstrapDNS BootstrapDNS `yaml:"bootstrapDns"` + HostsFile HostsFile `yaml:"hostsFile"` FQDNOnly FQDNOnly `yaml:"fqdnOnly"` - Filtering FilteringConfig `yaml:"filtering"` + Filtering Filtering `yaml:"filtering"` EDE EDE `yaml:"ede"` ECS ECS `yaml:"ecs"` SUDN SUDN `yaml:"specialUseDomains"` @@ -253,40 +253,40 @@ type Config struct { } `yaml:",inline"` } -type PortsConfig struct { +type Ports struct { DNS ListenConfig `yaml:"dns" default:"53"` HTTP ListenConfig `yaml:"http"` HTTPS ListenConfig `yaml:"https"` TLS ListenConfig `yaml:"tls"` } -func (c *PortsConfig) LogConfig(logger *logrus.Entry) { +func (c *Ports) LogConfig(logger *logrus.Entry) { logger.Infof("DNS = %s", c.DNS) logger.Infof("TLS = %s", c.TLS) logger.Infof("HTTP = %s", c.HTTP) logger.Infof("HTTPS = %s", c.HTTPS) } -// split in two types to avoid infinite recursion. See `BootstrapDNSConfig.UnmarshalYAML`. +// split in two types to avoid infinite recursion. See `BootstrapDNS.UnmarshalYAML`. type ( - BootstrapDNSConfig bootstrapDNSConfig - bootstrapDNSConfig []BootstrappedUpstreamConfig + BootstrapDNS bootstrapDNS + bootstrapDNS []BootstrappedUpstream ) -func (b *BootstrapDNSConfig) IsEnabled() bool { +func (b *BootstrapDNS) IsEnabled() bool { return len(*b) != 0 } -func (b *BootstrapDNSConfig) LogConfig(*logrus.Entry) { +func (b *BootstrapDNS) LogConfig(*logrus.Entry) { // This should not be called, at least for now: // The Boostrap resolver is not in the chain and thus its config is not logged panic("not implemented") } -// split in two types to avoid infinite recursion. See `BootstrappedUpstreamConfig.UnmarshalYAML`. +// split in two types to avoid infinite recursion. See `BootstrappedUpstream.UnmarshalYAML`. type ( - BootstrappedUpstreamConfig bootstrappedUpstreamConfig - bootstrappedUpstreamConfig struct { + BootstrappedUpstream bootstrappedUpstream + bootstrappedUpstream struct { Upstream Upstream `yaml:"upstream"` IPs []net.IP `yaml:"ips"` } @@ -319,16 +319,16 @@ func (c *Init) LogConfig(logger *logrus.Entry) { logger.Debugf("strategy = %s", c.Strategy) } -type SourceLoadingConfig struct { +type SourceLoading struct { Init `yaml:",inline"` - Concurrency uint `yaml:"concurrency" default:"4"` - MaxErrorsPerSource int `yaml:"maxErrorsPerSource" default:"5"` - RefreshPeriod Duration `yaml:"refreshPeriod" default:"4h"` - Downloads DownloaderConfig `yaml:"downloads"` + Concurrency uint `yaml:"concurrency" default:"4"` + MaxErrorsPerSource int `yaml:"maxErrorsPerSource" default:"5"` + RefreshPeriod Duration `yaml:"refreshPeriod" default:"4h"` + Downloads Downloader `yaml:"downloads"` } -func (c *SourceLoadingConfig) LogConfig(logger *logrus.Entry) { +func (c *SourceLoading) LogConfig(logger *logrus.Entry) { c.Init.LogConfig(logger) logger.Infof("concurrency = %d", c.Concurrency) logger.Debugf("maxErrorsPerSource = %d", c.MaxErrorsPerSource) @@ -343,7 +343,7 @@ func (c *SourceLoadingConfig) LogConfig(logger *logrus.Entry) { log.WithIndent(logger, " ", c.Downloads.LogConfig) } -func (c *SourceLoadingConfig) StartPeriodicRefresh( +func (c *SourceLoading) StartPeriodicRefresh( ctx context.Context, refresh func(context.Context) error, logErr func(error), ) error { err := c.Strategy.Do(ctx, refresh, logErr) @@ -358,7 +358,7 @@ func (c *SourceLoadingConfig) StartPeriodicRefresh( return nil } -func (c *SourceLoadingConfig) periodically( +func (c *SourceLoading) periodically( ctx context.Context, refresh func(context.Context) error, logErr func(error), ) { refresh = recoverToError(refresh, func(panicVal any) error { @@ -394,13 +394,13 @@ func recoverToError(do func(context.Context) error, onPanic func(any) error) fun } } -type DownloaderConfig struct { +type Downloader struct { Timeout Duration `yaml:"timeout" default:"5s"` Attempts uint `yaml:"attempts" default:"3"` Cooldown Duration `yaml:"cooldown" default:"500ms"` } -func (c *DownloaderConfig) LogConfig(logger *logrus.Entry) { +func (c *Downloader) LogConfig(logger *logrus.Entry) { logger.Infof("timeout = %s", c.Timeout) logger.Infof("attempts = %d", c.Attempts) logger.Debugf("cooldown = %s", c.Cooldown) diff --git a/config/config_test.go b/config/config_test.go index 0bc52140..444aff93 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -547,10 +547,10 @@ bootstrapDns: ) Describe("SourceLoadingConfig", func() { - var cfg SourceLoadingConfig + var cfg SourceLoading BeforeEach(func() { - cfg = SourceLoadingConfig{ + cfg = SourceLoading{ Concurrency: 12, RefreshPeriod: Duration(time.Hour), } @@ -744,22 +744,22 @@ bootstrapDns: Describe("BootstrapDNSConfig", func() { It("is not enabled when empty", func() { - var sut BootstrapDNSConfig + var sut BootstrapDNS Expect(sut.IsEnabled()).Should(BeFalse()) }) It("is enabled if non empty", func() { - sut := BootstrapDNSConfig{ - BootstrappedUpstreamConfig{}, - BootstrappedUpstreamConfig{}, + sut := BootstrapDNS{ + BootstrappedUpstream{}, + BootstrappedUpstream{}, } Expect(sut.IsEnabled()).Should(BeTrue()) }) It("LogConfig panics", func() { - sut := BootstrapDNSConfig{} + sut := BootstrapDNS{} Expect(func() { sut.LogConfig(logger) @@ -777,7 +777,7 @@ bootstrapDns: DeferCleanup(cancelFn) }) It("handles panics", func() { - sut := SourceLoadingConfig{ + sut := SourceLoading{ Init: Init{Strategy: InitStrategyFailOnError}, } @@ -793,7 +793,7 @@ bootstrapDns: }) It("periodically calls refresh", func() { - sut := SourceLoadingConfig{ + sut := SourceLoading{ Init: Init{Strategy: InitStrategyFast}, RefreshPeriod: Duration(5 * time.Millisecond), } diff --git a/config/filtering.go b/config/filtering.go index dcc37ac7..6902f595 100644 --- a/config/filtering.go +++ b/config/filtering.go @@ -4,17 +4,17 @@ import ( "github.com/sirupsen/logrus" ) -type FilteringConfig struct { +type Filtering struct { QueryTypes QTypeSet `yaml:"queryTypes"` } // IsEnabled implements `config.Configurable`. -func (c *FilteringConfig) IsEnabled() bool { +func (c *Filtering) IsEnabled() bool { return len(c.QueryTypes) != 0 } // LogConfig implements `config.Configurable`. -func (c *FilteringConfig) LogConfig(logger *logrus.Entry) { +func (c *Filtering) LogConfig(logger *logrus.Entry) { logger.Info("query types:") for qType := range c.QueryTypes { diff --git a/config/filtering_test.go b/config/filtering_test.go index 794cf126..3cd1edfe 100644 --- a/config/filtering_test.go +++ b/config/filtering_test.go @@ -9,19 +9,19 @@ import ( ) var _ = Describe("FilteringConfig", func() { - var cfg FilteringConfig + var cfg Filtering suiteBeforeEach() BeforeEach(func() { - cfg = FilteringConfig{ + cfg = Filtering{ QueryTypes: NewQTypeSet(AAAA, MX), } }) Describe("IsEnabled", func() { It("should be false by default", func() { - cfg := FilteringConfig{} + cfg := Filtering{} Expect(defaults.Set(&cfg)).Should(Succeed()) Expect(cfg.IsEnabled()).Should(BeFalse()) @@ -35,7 +35,7 @@ var _ = Describe("FilteringConfig", func() { When("disabled", func() { It("should be false", func() { - cfg := FilteringConfig{} + cfg := Filtering{} Expect(cfg.IsEnabled()).Should(BeFalse()) }) diff --git a/config/hosts_file.go b/config/hosts_file.go index d3c7230a..042f1b31 100644 --- a/config/hosts_file.go +++ b/config/hosts_file.go @@ -6,11 +6,11 @@ import ( "github.com/sirupsen/logrus" ) -type HostsFileConfig struct { - Sources []BytesSource `yaml:"sources"` - HostsTTL Duration `yaml:"hostsTTL" default:"1h"` - FilterLoopback bool `yaml:"filterLoopback"` - Loading SourceLoadingConfig `yaml:"loading"` +type HostsFile struct { + Sources []BytesSource `yaml:"sources"` + HostsTTL Duration `yaml:"hostsTTL" default:"1h"` + FilterLoopback bool `yaml:"filterLoopback"` + Loading SourceLoading `yaml:"loading"` // Deprecated options Deprecated struct { @@ -19,7 +19,7 @@ type HostsFileConfig struct { } `yaml:",inline"` } -func (c *HostsFileConfig) migrate(logger *logrus.Entry) bool { +func (c *HostsFile) migrate(logger *logrus.Entry) bool { return Migrate(logger, "hostsFile", c.Deprecated, map[string]Migrator{ "refreshPeriod": Move(To("loading.refreshPeriod", &c.Loading)), "filePath": Apply(To("sources", c), func(value BytesSource) { @@ -29,12 +29,12 @@ func (c *HostsFileConfig) migrate(logger *logrus.Entry) bool { } // IsEnabled implements `config.Configurable`. -func (c *HostsFileConfig) IsEnabled() bool { +func (c *HostsFile) IsEnabled() bool { return len(c.Sources) != 0 } // LogConfig implements `config.Configurable`. -func (c *HostsFileConfig) LogConfig(logger *logrus.Entry) { +func (c *HostsFile) LogConfig(logger *logrus.Entry) { logger.Infof("TTL: %s", c.HostsTTL) logger.Infof("filter loopback addresses: %t", c.FilterLoopback) diff --git a/config/hosts_file_test.go b/config/hosts_file_test.go index d364a646..26cbef1a 100644 --- a/config/hosts_file_test.go +++ b/config/hosts_file_test.go @@ -9,25 +9,25 @@ import ( ) var _ = Describe("HostsFileConfig", func() { - var cfg HostsFileConfig + var cfg HostsFile suiteBeforeEach() BeforeEach(func() { - cfg = HostsFileConfig{ + cfg = HostsFile{ Sources: append( NewBytesSources("/a/file/path"), TextBytesSource("127.0.0.1 localhost"), ), HostsTTL: Duration(29 * time.Minute), - Loading: SourceLoadingConfig{RefreshPeriod: Duration(30 * time.Minute)}, + Loading: SourceLoading{RefreshPeriod: Duration(30 * time.Minute)}, FilterLoopback: true, } }) Describe("IsEnabled", func() { It("should be false by default", func() { - cfg := HostsFileConfig{} + cfg := HostsFile{} Expect(defaults.Set(&cfg)).Should(Succeed()) Expect(cfg.IsEnabled()).Should(BeFalse()) @@ -41,7 +41,7 @@ var _ = Describe("HostsFileConfig", func() { When("disabled", func() { It("should be false", func() { - cfg := HostsFileConfig{} + cfg := HostsFile{} Expect(cfg.IsEnabled()).Should(BeFalse()) }) @@ -62,7 +62,7 @@ var _ = Describe("HostsFileConfig", func() { Describe("migrate", func() { It("should", func() { - cfg, err := WithDefaults[HostsFileConfig]() + cfg, err := WithDefaults[HostsFile]() Expect(err).Should(Succeed()) cfg.Deprecated.Filepath = ptrOf(newBytesSource("/a/file/path")) diff --git a/config/metrics.go b/config/metrics.go index 69d9e4f7..a7d66c62 100644 --- a/config/metrics.go +++ b/config/metrics.go @@ -2,18 +2,18 @@ package config import "github.com/sirupsen/logrus" -// MetricsConfig contains the config values for prometheus -type MetricsConfig struct { +// Metrics contains the config values for prometheus +type Metrics struct { Enable bool `yaml:"enable" default:"false"` Path string `yaml:"path" default:"/metrics"` } // IsEnabled implements `config.Configurable`. -func (c *MetricsConfig) IsEnabled() bool { +func (c *Metrics) IsEnabled() bool { return c.Enable } // LogConfig implements `config.Configurable`. -func (c *MetricsConfig) LogConfig(logger *logrus.Entry) { +func (c *Metrics) LogConfig(logger *logrus.Entry) { logger.Infof("url path: %s", c.Path) } diff --git a/config/metrics_test.go b/config/metrics_test.go index b5f968b2..9b75f353 100644 --- a/config/metrics_test.go +++ b/config/metrics_test.go @@ -7,12 +7,12 @@ import ( ) var _ = Describe("MetricsConfig", func() { - var cfg MetricsConfig + var cfg Metrics suiteBeforeEach() BeforeEach(func() { - cfg = MetricsConfig{ + cfg = Metrics{ Enable: true, Path: "/custom/path", } @@ -20,7 +20,7 @@ var _ = Describe("MetricsConfig", func() { Describe("IsEnabled", func() { It("should be false by default", func() { - cfg := MetricsConfig{} + cfg := Metrics{} Expect(defaults.Set(&cfg)).Should(Succeed()) Expect(cfg.IsEnabled()).Should(BeFalse()) @@ -34,7 +34,7 @@ var _ = Describe("MetricsConfig", func() { When("disabled", func() { It("should be false", func() { - cfg := MetricsConfig{} + cfg := Metrics{} Expect(cfg.IsEnabled()).Should(BeFalse()) }) diff --git a/config/query_log.go b/config/query_log.go index a0ecd055..616ecdfd 100644 --- a/config/query_log.go +++ b/config/query_log.go @@ -4,8 +4,8 @@ import ( "github.com/sirupsen/logrus" ) -// QueryLogConfig configuration for the query logging -type QueryLogConfig struct { +// QueryLog configuration for the query logging +type QueryLog struct { Target string `yaml:"target"` Type QueryLogType `yaml:"type"` LogRetentionDays uint64 `yaml:"logRetentionDays"` @@ -16,19 +16,19 @@ type QueryLogConfig struct { } // SetDefaults implements `defaults.Setter`. -func (c *QueryLogConfig) SetDefaults() { +func (c *QueryLog) SetDefaults() { // Since the default depends on the enum values, set it dynamically // to avoid having to repeat the values in the annotation. c.Fields = QueryLogFieldValues() } // IsEnabled implements `config.Configurable`. -func (c *QueryLogConfig) IsEnabled() bool { +func (c *QueryLog) IsEnabled() bool { return c.Type != QueryLogTypeNone } // LogConfig implements `config.Configurable`. -func (c *QueryLogConfig) LogConfig(logger *logrus.Entry) { +func (c *QueryLog) LogConfig(logger *logrus.Entry) { logger.Infof("type: %s", c.Type) if c.Target != "" { diff --git a/config/query_log_test.go b/config/query_log_test.go index 582fa34b..e632fc6c 100644 --- a/config/query_log_test.go +++ b/config/query_log_test.go @@ -9,12 +9,12 @@ import ( ) var _ = Describe("QueryLogConfig", func() { - var cfg QueryLogConfig + var cfg QueryLog suiteBeforeEach() BeforeEach(func() { - cfg = QueryLogConfig{ + cfg = QueryLog{ Target: "/dev/null", Type: QueryLogTypeCsvClient, LogRetentionDays: 0, @@ -25,7 +25,7 @@ var _ = Describe("QueryLogConfig", func() { Describe("IsEnabled", func() { It("should be true by default", func() { - cfg := QueryLogConfig{} + cfg := QueryLog{} Expect(defaults.Set(&cfg)).Should(Succeed()) Expect(cfg.IsEnabled()).Should(BeTrue()) @@ -39,7 +39,7 @@ var _ = Describe("QueryLogConfig", func() { When("disabled", func() { It("should be false", func() { - cfg := QueryLogConfig{ + cfg := QueryLog{ Type: QueryLogTypeNone, } @@ -59,7 +59,7 @@ var _ = Describe("QueryLogConfig", func() { Describe("SetDefaults", func() { It("should log configuration", func() { - cfg := QueryLogConfig{} + cfg := QueryLog{} Expect(cfg.Fields).Should(BeEmpty()) Expect(defaults.Set(&cfg)).Should(Succeed()) diff --git a/lists/downloader.go b/lists/downloader.go index ff95c862..d2e964b3 100644 --- a/lists/downloader.go +++ b/lists/downloader.go @@ -33,16 +33,16 @@ type FileDownloader interface { // httpDownloader downloads files via HTTP protocol type httpDownloader struct { - cfg config.DownloaderConfig + cfg config.Downloader client http.Client } -func NewDownloader(cfg config.DownloaderConfig, transport http.RoundTripper) FileDownloader { +func NewDownloader(cfg config.Downloader, transport http.RoundTripper) FileDownloader { return newDownloader(cfg, transport) } -func newDownloader(cfg config.DownloaderConfig, transport http.RoundTripper) *httpDownloader { +func newDownloader(cfg config.Downloader, transport http.RoundTripper) *httpDownloader { return &httpDownloader{ cfg: cfg, diff --git a/lists/downloader_test.go b/lists/downloader_test.go index f3a91438..6cb59ed4 100644 --- a/lists/downloader_test.go +++ b/lists/downloader_test.go @@ -22,7 +22,7 @@ import ( var _ = Describe("Downloader", func() { var ( - sutConfig config.DownloaderConfig + sutConfig config.Downloader sut *httpDownloader failedDownloadCountEvtChannel chan string loggerHook *test.Hook @@ -30,7 +30,7 @@ var _ = Describe("Downloader", func() { BeforeEach(func() { var err error - sutConfig, err = config.WithDefaults[config.DownloaderConfig]() + sutConfig, err = config.WithDefaults[config.Downloader]() Expect(err).Should(Succeed()) failedDownloadCountEvtChannel = make(chan string, 5) @@ -57,7 +57,7 @@ var _ = Describe("Downloader", func() { transport := &http.Transport{} sut = NewDownloader( - config.DownloaderConfig{ + config.Downloader{ Attempts: 5, Cooldown: config.Duration(2 * time.Second), Timeout: config.Duration(5 * time.Second), @@ -128,7 +128,7 @@ var _ = Describe("Downloader", func() { var attempt uint64 = 1 BeforeEach(func() { - sutConfig = config.DownloaderConfig{ + sutConfig = config.Downloader{ Timeout: config.Duration(20 * time.Millisecond), Attempts: 3, Cooldown: config.Duration(time.Millisecond), @@ -165,7 +165,7 @@ var _ = Describe("Downloader", func() { }) When("If timeout occurs on all request", func() { BeforeEach(func() { - sutConfig = config.DownloaderConfig{ + sutConfig = config.Downloader{ Timeout: config.Duration(10 * time.Millisecond), Attempts: 3, Cooldown: config.Duration(time.Millisecond), @@ -191,7 +191,7 @@ var _ = Describe("Downloader", func() { }) When("DNS resolution of passed URL fails", func() { BeforeEach(func() { - sutConfig = config.DownloaderConfig{ + sutConfig = config.Downloader{ Timeout: config.Duration(500 * time.Millisecond), Attempts: 3, Cooldown: 200 * config.Duration(time.Millisecond), diff --git a/lists/list_cache.go b/lists/list_cache.go index 70ae15bd..409591f9 100644 --- a/lists/list_cache.go +++ b/lists/list_cache.go @@ -40,7 +40,7 @@ type ListCache struct { groupedCache stringcache.GroupedStringCache regexCache stringcache.GroupedStringCache - cfg config.SourceLoadingConfig + cfg config.SourceLoading listType ListCacheType groupSources map[string][]config.BytesSource downloader FileDownloader @@ -70,7 +70,7 @@ func (b *ListCache) LogConfig(logger *logrus.Entry) { // NewListCache creates new list instance func NewListCache(ctx context.Context, - t ListCacheType, cfg config.SourceLoadingConfig, + t ListCacheType, cfg config.SourceLoading, groupSources map[string][]config.BytesSource, downloader FileDownloader, ) (*ListCache, error) { regexCache := stringcache.NewInMemoryGroupedRegexCache() diff --git a/lists/list_cache_benchmark_test.go b/lists/list_cache_benchmark_test.go index 1a710250..0a0c325c 100644 --- a/lists/list_cache_benchmark_test.go +++ b/lists/list_cache_benchmark_test.go @@ -15,11 +15,11 @@ func BenchmarkRefresh(b *testing.B) { "gr1": config.NewBytesSources(file1, file2, file3), } - cfg := config.SourceLoadingConfig{ + cfg := config.SourceLoading{ Concurrency: 5, RefreshPeriod: config.Duration(-1), } - downloader := NewDownloader(config.DownloaderConfig{}, nil) + downloader := NewDownloader(config.Downloader{}, nil) cache, _ := NewListCache(context.Background(), ListCacheTypeBlacklist, cfg, lists, downloader) b.ReportAllocs() diff --git a/lists/list_cache_test.go b/lists/list_cache_test.go index 8b68525b..dbcd910d 100644 --- a/lists/list_cache_test.go +++ b/lists/list_cache_test.go @@ -29,7 +29,7 @@ var _ = Describe("ListCache", func() { server1, server2, server3 *httptest.Server sut *ListCache - sutConfig config.SourceLoadingConfig + sutConfig config.SourceLoading listCacheType ListCacheType lists map[string][]config.BytesSource @@ -48,12 +48,12 @@ var _ = Describe("ListCache", func() { listCacheType = ListCacheTypeBlacklist - sutConfig, err = config.WithDefaults[config.SourceLoadingConfig]() + sutConfig, err = config.WithDefaults[config.SourceLoading]() Expect(err).Should(Succeed()) sutConfig.RefreshPeriod = -1 - downloader = NewDownloader(config.DownloaderConfig{}, nil) + downloader = NewDownloader(config.Downloader{}, nil) mockDownloader = nil server1 = TestServer("blocked1.com\nblocked1a.com\n192.168.178.55") diff --git a/metrics/metrics.go b/metrics/metrics.go index a35c7526..c8767917 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -18,7 +18,7 @@ func RegisterMetric(c prometheus.Collector) { } // Start starts prometheus endpoint -func Start(router *chi.Mux, cfg config.MetricsConfig) { +func Start(router *chi.Mux, cfg config.Metrics) { if cfg.Enable { _ = reg.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})) _ = reg.Register(collectors.NewGoCollector()) diff --git a/resolver/blocking_resolver_test.go b/resolver/blocking_resolver_test.go index 70db11b3..e110849e 100644 --- a/resolver/blocking_resolver_test.go +++ b/resolver/blocking_resolver_test.go @@ -170,7 +170,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() { ClientGroupsBlock: map[string][]string{ "default": {"gr1"}, }, - Loading: config.SourceLoadingConfig{ + Loading: config.SourceLoading{ Init: config.Init{Strategy: config.InitStrategyFast}, }, } @@ -1126,7 +1126,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() { _, err := NewBlockingResolver(ctx, config.Blocking{ BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources("wrongPath")}, WhiteLists: map[string][]config.BytesSource{"whitelist": config.NewBytesSources("wrongPath")}, - Loading: config.SourceLoadingConfig{ + Loading: config.SourceLoading{ Init: config.Init{Strategy: config.InitStrategyFailOnError}, }, BlockType: "zeroIp", diff --git a/resolver/bootstrap.go b/resolver/bootstrap.go index 5152e0d5..0e6ba4b1 100644 --- a/resolver/bootstrap.go +++ b/resolver/bootstrap.go @@ -26,7 +26,7 @@ var errArbitrarySystemResolverRequest = errors.New( ) type bootstrapConfig struct { - config.BootstrapDNSConfig + config.BootstrapDNS connectIPVersion config.IPVersion timeout config.Duration @@ -34,7 +34,7 @@ type bootstrapConfig struct { func newBootstrapConfig(cfg *config.Config) *bootstrapConfig { return &bootstrapConfig{ - BootstrapDNSConfig: cfg.BootstrapDNS, + BootstrapDNS: cfg.BootstrapDNS, connectIPVersion: cfg.ConnectIPVersion, timeout: cfg.Upstreams.Timeout, @@ -266,7 +266,7 @@ func (b *Bootstrap) resolveType(ctx context.Context, hostname string, qType dns. type bootstrapedResolvers map[Resolver][]net.IP func newBootstrapedResolvers( - b *Bootstrap, cfg config.BootstrapDNSConfig, upstreamsCfg config.Upstreams, + b *Bootstrap, cfg config.BootstrapDNS, upstreamsCfg config.Upstreams, ) (bootstrapedResolvers, error) { upstreamIPs := make(bootstrapedResolvers, len(cfg)) diff --git a/resolver/bootstrap_test.go b/resolver/bootstrap_test.go index f4f88a78..d0d4df00 100644 --- a/resolver/bootstrap_test.go +++ b/resolver/bootstrap_test.go @@ -34,7 +34,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { BeforeEach(func() { sutConfig = config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpTls, @@ -58,7 +58,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { Describe("configuration", func() { When("is not specified", func() { BeforeEach(func() { - sutConfig.BootstrapDNS = config.BootstrapDNSConfig{} + sutConfig.BootstrapDNS = config.BootstrapDNS{} }) It("should use the system resolver", func() { @@ -89,7 +89,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { When("one of multiple upstreams is invalid", func() { It("errors", func() { cfg := config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ // valid Net: config.NetProtocolTcpUdp, @@ -115,7 +115,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { When("hostname is an IP", func() { BeforeEach(func() { sutConfig = config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpUdp, @@ -137,7 +137,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { When("using non IP hostname", func() { It("errors", func() { cfg := config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpUdp, @@ -156,7 +156,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { When("extra IPs are configured", func() { BeforeEach(func() { sutConfig = config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpUdp, @@ -181,7 +181,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { When("IPs are missing", func() { It("errors", func() { cfg := config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpTls, @@ -200,7 +200,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { When("hostname is IP", func() { It("doesn't require extra IPs", func() { cfg := config.Config{ - BootstrapDNS: []config.BootstrappedUpstreamConfig{ + BootstrapDNS: []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpTls, @@ -223,7 +223,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { BeforeEach(func() { bootstrapUpstream = &mockResolver{} - sutConfig.BootstrapDNS = []config.BootstrappedUpstreamConfig{ + sutConfig.BootstrapDNS = []config.BootstrappedUpstream{ { Upstream: config.Upstream{ Net: config.NetProtocolTcpTls, @@ -596,7 +596,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() { mockUpstream1 = NewMockUDPUpstreamServer().WithAnswerRR("example.com 123 IN A 123.124.122.122") mockUpstream2 = NewMockUDPUpstreamServer().WithAnswerRR("example.com 123 IN A 123.124.122.122") - sutConfig.BootstrapDNS = []config.BootstrappedUpstreamConfig{ + sutConfig.BootstrapDNS = []config.BootstrappedUpstream{ {Upstream: mockUpstream1.Start()}, {Upstream: mockUpstream2.Start()}, } diff --git a/resolver/caching_resolver.go b/resolver/caching_resolver.go index d10ae278..ed056c17 100644 --- a/resolver/caching_resolver.go +++ b/resolver/caching_resolver.go @@ -24,7 +24,7 @@ const defaultCachingCleanUpInterval = 5 * time.Second // CachingResolver caches answers from dns queries with their TTL time, // to avoid external resolver calls for recurrent queries type CachingResolver struct { - configurable[*config.CachingConfig] + configurable[*config.Caching] NextResolver typed @@ -37,14 +37,14 @@ type CachingResolver struct { // NewCachingResolver creates a new resolver instance func NewCachingResolver(ctx context.Context, - cfg config.CachingConfig, + cfg config.Caching, redis *redis.Client, ) *CachingResolver { return newCachingResolver(ctx, cfg, redis, true) } func newCachingResolver(ctx context.Context, - cfg config.CachingConfig, + cfg config.Caching, redis *redis.Client, emitMetricEvents bool, ) *CachingResolver { @@ -66,7 +66,7 @@ func newCachingResolver(ctx context.Context, return c } -func configureCaches(ctx context.Context, c *CachingResolver, cfg *config.CachingConfig) { +func configureCaches(ctx context.Context, c *CachingResolver, cfg *config.Caching) { options := expirationcache.Options{ CleanupInterval: defaultCachingCleanUpInterval, MaxSize: uint(cfg.MaxItemsCount), diff --git a/resolver/caching_resolver_test.go b/resolver/caching_resolver_test.go index 3f88ef4b..5081ab54 100644 --- a/resolver/caching_resolver_test.go +++ b/resolver/caching_resolver_test.go @@ -25,7 +25,7 @@ import ( var _ = Describe("CachingResolver", func() { var ( sut *CachingResolver - sutConfig config.CachingConfig + sutConfig config.Caching m *mockResolver mockAnswer *dns.Msg ctx context.Context @@ -39,7 +39,7 @@ var _ = Describe("CachingResolver", func() { }) BeforeEach(func() { - sutConfig = config.CachingConfig{} + sutConfig = config.Caching{} if err := defaults.Set(&sutConfig); err != nil { panic(err) } @@ -63,7 +63,7 @@ var _ = Describe("CachingResolver", func() { When("max caching time is negative", func() { BeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ MaxCachingTime: config.Duration(time.Minute * -1), } }) @@ -86,7 +86,7 @@ var _ = Describe("CachingResolver", func() { Describe("Caching responses", func() { When("prefetching is enabled", func() { BeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ Prefetching: true, PrefetchExpires: config.Duration(time.Minute * 120), PrefetchThreshold: 5, @@ -198,7 +198,7 @@ var _ = Describe("CachingResolver", func() { }) When("min caching time is defined", func() { BeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ MinCachingTime: config.Duration(time.Minute * 5), } }) @@ -341,7 +341,7 @@ var _ = Describe("CachingResolver", func() { }) Context("max caching time is negative -> caching is disabled", func() { BeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ MaxCachingTime: config.Duration(time.Minute * -1), } }) @@ -378,7 +378,7 @@ var _ = Describe("CachingResolver", func() { Context("max caching time is positive", func() { BeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ MaxCachingTime: config.Duration(time.Minute * 4), } }) @@ -419,7 +419,7 @@ var _ = Describe("CachingResolver", func() { }) Context("max caching time is defined", func() { BeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ MaxCachingTime: config.Duration(time.Minute * 1), } }) @@ -500,7 +500,7 @@ var _ = Describe("CachingResolver", func() { When("Upstream resolver returns NXDOMAIN without caching", func() { BeforeEach(func() { mockAnswer.Rcode = dns.RcodeNameError - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ CacheTimeNegative: config.Duration(time.Minute * -1), } }) @@ -758,7 +758,7 @@ var _ = Describe("CachingResolver", func() { }) When("cache", func() { JustBeforeEach(func() { - sutConfig = config.CachingConfig{ + sutConfig = config.Caching{ MaxCachingTime: config.Duration(time.Second * 10), } mockAnswer, _ = util.NewMsgWithAnswer("example.com.", 1000, A, "1.1.1.1") diff --git a/resolver/filtering_resolver.go b/resolver/filtering_resolver.go index c6344efd..370de979 100644 --- a/resolver/filtering_resolver.go +++ b/resolver/filtering_resolver.go @@ -11,12 +11,12 @@ import ( // FilteringResolver filters DNS queries (for example can drop all AAAA query) // returns empty ANSWER with NOERROR type FilteringResolver struct { - configurable[*config.FilteringConfig] + configurable[*config.Filtering] NextResolver typed } -func NewFilteringResolver(cfg config.FilteringConfig) *FilteringResolver { +func NewFilteringResolver(cfg config.Filtering) *FilteringResolver { return &FilteringResolver{ configurable: withConfig(&cfg), typed: withType("filtering"), diff --git a/resolver/filtering_resolver_test.go b/resolver/filtering_resolver_test.go index cccadd2e..79b60ba9 100644 --- a/resolver/filtering_resolver_test.go +++ b/resolver/filtering_resolver_test.go @@ -17,7 +17,7 @@ import ( var _ = Describe("FilteringResolver", func() { var ( sut *FilteringResolver - sutConfig config.FilteringConfig + sutConfig config.Filtering m *mockResolver mockAnswer *dns.Msg @@ -63,7 +63,7 @@ var _ = Describe("FilteringResolver", func() { When("Filtering query types are defined", func() { BeforeEach(func() { - sutConfig = config.FilteringConfig{ + sutConfig = config.Filtering{ QueryTypes: config.NewQTypeSet(AAAA, MX), } }) @@ -95,7 +95,7 @@ var _ = Describe("FilteringResolver", func() { When("No filtering query types are defined", func() { BeforeEach(func() { - sutConfig = config.FilteringConfig{} + sutConfig = config.Filtering{} }) It("Should return empty answer without error", func() { Expect(sut.Resolve(ctx, newRequest("example.com.", AAAA))). diff --git a/resolver/hosts_file_resolver.go b/resolver/hosts_file_resolver.go index dd50a816..1dec7eb0 100644 --- a/resolver/hosts_file_resolver.go +++ b/resolver/hosts_file_resolver.go @@ -26,7 +26,7 @@ const ( type HostsFileEntry = parsers.HostsFileEntry type HostsFileResolver struct { - configurable[*config.HostsFileConfig] + configurable[*config.HostsFile] NextResolver typed @@ -35,7 +35,7 @@ type HostsFileResolver struct { } func NewHostsFileResolver(ctx context.Context, - cfg config.HostsFileConfig, + cfg config.HostsFile, bootstrap *Bootstrap, ) (*HostsFileResolver, error) { r := HostsFileResolver{ diff --git a/resolver/hosts_file_resolver_test.go b/resolver/hosts_file_resolver_test.go index cc0da945..b769c63a 100644 --- a/resolver/hosts_file_resolver_test.go +++ b/resolver/hosts_file_resolver_test.go @@ -19,7 +19,7 @@ var _ = Describe("HostsFileResolver", func() { TTL = uint32(time.Now().Second()) sut *HostsFileResolver - sutConfig config.HostsFileConfig + sutConfig config.HostsFile m *mockResolver tmpDir *TmpFolder tmpFile *TmpFile @@ -43,11 +43,11 @@ var _ = Describe("HostsFileResolver", func() { tmpDir = NewTmpFolder("HostsFileResolver") tmpFile = writeHostFile(tmpDir) - sutConfig = config.HostsFileConfig{ + sutConfig = config.HostsFile{ Sources: config.NewBytesSources(tmpFile.Path), HostsTTL: config.Duration(time.Duration(TTL) * time.Second), FilterLoopback: true, - Loading: config.SourceLoadingConfig{ + Loading: config.SourceLoading{ RefreshPeriod: -1, MaxErrorsPerSource: 5, }, @@ -82,7 +82,7 @@ var _ = Describe("HostsFileResolver", func() { Describe("Using hosts file", func() { When("Hosts file cannot be located", func() { BeforeEach(func() { - sutConfig = config.HostsFileConfig{ + sutConfig = config.HostsFile{ Sources: config.NewBytesSources("/this/file/does/not/exist"), HostsTTL: config.Duration(time.Duration(TTL) * time.Second), } diff --git a/resolver/metrics_resolver.go b/resolver/metrics_resolver.go index 80894e6d..48b85d46 100644 --- a/resolver/metrics_resolver.go +++ b/resolver/metrics_resolver.go @@ -15,7 +15,7 @@ import ( // MetricsResolver resolver that records metrics about requests/response type MetricsResolver struct { - configurable[*config.MetricsConfig] + configurable[*config.Metrics] NextResolver typed @@ -59,7 +59,7 @@ func (r *MetricsResolver) Resolve(ctx context.Context, request *model.Request) ( } // NewMetricsResolver creates a new intance of the MetricsResolver type -func NewMetricsResolver(cfg config.MetricsConfig) *MetricsResolver { +func NewMetricsResolver(cfg config.Metrics) *MetricsResolver { m := MetricsResolver{ configurable: withConfig(&cfg), typed: withType("metrics"), diff --git a/resolver/metrics_resolver_test.go b/resolver/metrics_resolver_test.go index d62cf597..87821858 100644 --- a/resolver/metrics_resolver_test.go +++ b/resolver/metrics_resolver_test.go @@ -37,7 +37,7 @@ var _ = Describe("MetricResolver", func() { ctx, cancelFn = context.WithCancel(context.Background()) DeferCleanup(cancelFn) - sut = NewMetricsResolver(config.MetricsConfig{Enable: true}) + sut = NewMetricsResolver(config.Metrics{Enable: true}) m = &mockResolver{} m.On("Resolve", mock.Anything).Return(&Response{Res: new(dns.Msg)}, nil) sut.Next(m) diff --git a/resolver/mocks_test.go b/resolver/mocks_test.go index cc99220e..3ae046ff 100644 --- a/resolver/mocks_test.go +++ b/resolver/mocks_test.go @@ -128,7 +128,7 @@ ips: bootstrapUpstream := &mockResolver{} - var bCfg config.BootstrapDNSConfig + var bCfg config.BootstrapDNS err := yaml.UnmarshalStrict([]byte(cfgTxt), &bCfg) util.FatalOnError("test bootstrap config is broken, did you change the struct?", err) diff --git a/resolver/query_logging_resolver.go b/resolver/query_logging_resolver.go index 106d2f76..3a229df7 100644 --- a/resolver/query_logging_resolver.go +++ b/resolver/query_logging_resolver.go @@ -21,7 +21,7 @@ const ( // QueryLoggingResolver writes query information (question, answer, duration, ...) type QueryLoggingResolver struct { - configurable[*config.QueryLogConfig] + configurable[*config.QueryLog] NextResolver typed @@ -30,7 +30,7 @@ type QueryLoggingResolver struct { } // NewQueryLoggingResolver returns a new resolver instance -func NewQueryLoggingResolver(ctx context.Context, cfg config.QueryLogConfig) *QueryLoggingResolver { +func NewQueryLoggingResolver(ctx context.Context, cfg config.QueryLog) *QueryLoggingResolver { logger := log.PrefixedLog(queryLoggingResolverType) var writer querylog.Writer diff --git a/resolver/query_logging_resolver_test.go b/resolver/query_logging_resolver_test.go index a2de6157..4e7968a3 100644 --- a/resolver/query_logging_resolver_test.go +++ b/resolver/query_logging_resolver_test.go @@ -40,7 +40,7 @@ func (m *SlowMockWriter) CleanUp() { var _ = Describe("QueryLoggingResolver", func() { var ( sut *QueryLoggingResolver - sutConfig config.QueryLogConfig + sutConfig config.QueryLog m *mockResolver tmpDir *TmpFolder mockAnswer *dns.Msg @@ -93,7 +93,7 @@ var _ = Describe("QueryLoggingResolver", func() { Describe("Process request", func() { When("Resolver has no configuration", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ CreationAttempts: 1, CreationCooldown: config.Duration(time.Millisecond), } @@ -111,7 +111,7 @@ var _ = Describe("QueryLoggingResolver", func() { }) When("Configuration with logging per client", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Target: tmpDir.Path, Type: config.QueryLogTypeCsvClient, CreationAttempts: 1, @@ -179,7 +179,7 @@ var _ = Describe("QueryLoggingResolver", func() { }) When("Configuration with logging in one file for all clients", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Target: tmpDir.Path, Type: config.QueryLogTypeCsv, CreationAttempts: 1, @@ -239,7 +239,7 @@ var _ = Describe("QueryLoggingResolver", func() { }) When("Configuration with specific fields to log", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Target: tmpDir.Path, Type: config.QueryLogTypeCsv, CreationAttempts: 1, @@ -287,7 +287,7 @@ var _ = Describe("QueryLoggingResolver", func() { Describe("Slow writer", func() { When("writer is too slow", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Type: config.QueryLogTypeNone, CreationAttempts: 1, CreationCooldown: config.Duration(time.Millisecond), @@ -310,7 +310,7 @@ var _ = Describe("QueryLoggingResolver", func() { Describe("Clean up of query log directory", func() { When("fallback logger is enabled, log retention is enabled", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ LogRetentionDays: 7, Type: config.QueryLogTypeConsole, CreationAttempts: 1, @@ -323,7 +323,7 @@ var _ = Describe("QueryLoggingResolver", func() { }) When("log directory contains old files", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Target: tmpDir.Path, Type: config.QueryLogTypeCsv, LogRetentionDays: 7, @@ -352,7 +352,7 @@ var _ = Describe("QueryLoggingResolver", func() { Describe("Wrong target configuration", func() { When("mysql database path is wrong", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Target: "dummy", Type: config.QueryLogTypeMysql, CreationAttempts: 1, @@ -366,7 +366,7 @@ var _ = Describe("QueryLoggingResolver", func() { When("postgresql database path is wrong", func() { BeforeEach(func() { - sutConfig = config.QueryLogConfig{ + sutConfig = config.QueryLog{ Target: "dummy", Type: config.QueryLogTypePostgresql, CreationAttempts: 1, diff --git a/server/server_test.go b/server/server_test.go index b0cf2eb0..6a3f56e2 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -148,7 +148,7 @@ var _ = BeforeSuite(func() { Upstream: upstreamClient, }, - Ports: config.PortsConfig{ + Ports: config.Ports{ DNS: config.ListenConfig{GetStringPort(dnsBasePort)}, TLS: config.ListenConfig{GetStringPort(tlsBasePort)}, HTTP: config.ListenConfig{GetStringPort(httpBasePort)}, @@ -156,7 +156,7 @@ var _ = BeforeSuite(func() { }, CertFile: certPem.Path, KeyFile: keyPem.Path, - Prometheus: config.MetricsConfig{ + Prometheus: config.Metrics{ Enable: true, Path: "/metrics", }, @@ -603,7 +603,7 @@ var _ = Describe("Running DNS server", func() { }, }, Blocking: config.Blocking{BlockType: "zeroIp"}, - Ports: config.PortsConfig{ + Ports: config.Ports{ DNS: config.ListenConfig{"127.0.0.1:" + GetStringPort(dnsBasePort2)}, }, }) @@ -649,7 +649,7 @@ var _ = Describe("Running DNS server", func() { }, }, Blocking: config.Blocking{BlockType: "zeroIp"}, - Ports: config.PortsConfig{ + Ports: config.Ports{ DNS: config.ListenConfig{"127.0.0.1:" + GetStringPort(dnsBasePort2)}, }, }) @@ -712,7 +712,7 @@ var _ = Describe("Running DNS server", func() { It("should create self-signed certificate if key/cert files are not provided", func() { cfg.KeyFile = "" cfg.CertFile = "" - cfg.Ports = config.PortsConfig{ + cfg.Ports = config.Ports{ HTTPS: []string{fmt.Sprintf(":%d", GetIntPort(httpsBasePort)+100)}, } sut, err := NewServer(ctx, &cfg)