Skip to content

Commit

Permalink
FR: DNS cache sync between multiple blocky instances (#344) (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwitsch authored Dec 21, 2021
1 parent a3edada commit d3611fb
Show file tree
Hide file tree
Showing 11 changed files with 598 additions and 22 deletions.
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ type Config struct {
Caching CachingConfig `yaml:"caching"`
QueryLog QueryLogConfig `yaml:"queryLog"`
Prometheus PrometheusConfig `yaml:"prometheus"`
Redis RedisConfig `yaml:"redis"`
LogLevel log.Level `yaml:"logLevel" default:"info"`
LogFormat log.FormatType `yaml:"logFormat" default:"text"`
LogPrivacy bool `yaml:"logPrivacy" default:"false"`
Expand Down Expand Up @@ -373,6 +374,16 @@ type QueryLogConfig struct {
LogRetentionDays uint64 `yaml:"logRetentionDays"`
}

// RedisConfig configuration for the redis connection
type RedisConfig struct {
Address string `yaml:"address"`
Password string `yaml:"password" default:""`
Database int `yaml:"database" default:"0"`
Required bool `yaml:"required" default:"false"`
ConnectionAttempts int `yaml:"connectionAttempts" default:"3"`
ConnectionCooldown Duration `yaml:"connectionCooldown" default:"1s"`
}

// nolint:gochecknoglobals
var config = &Config{}

Expand Down
26 changes: 26 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,32 @@ With following parameters you can tune the caching behavior:
maxTime: 30m
prefetching: true
```

## Redis

Blocky can synchronize its cache between multiple instances through redis.
Synchronization is disabled if no address is configured.

| Parameter | Type | Mandatory | Default value | Description |
| ----------------------------- | --------------- | --------- | ------------------ | ------------------------------------------------- |
| redis.address | string | no | | Server address and port |
| redis.password | string | no | | Password if necessary |
| redis.database | int | no | 0 | Database |
| redis.required | bool | no | false | Connection is required for blocky to start |
| redis.connectionAttempts | int | no | 3 | Max connection attempts |
| redis.connectionCooldown | duration format | no | 1s | Time between the connection attempts |

!!! example

```yaml
redis:
address: redis:6379
password: passwd
database: 2
required: true
connectionAttempts: 10
connectionCooldown: 3s
```

## Prometheus

Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ go 1.17

require (
github.com/0xERR0R/go-cache v1.6.0
github.com/alicebob/miniredis/v2 v2.17.0
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/creasty/defaults v1.5.2
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/cors v1.2.0
github.com/go-redis/redis/v8 v8.11.4
github.com/google/uuid v1.3.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/hashicorp/go-multierror v1.1.1
github.com/mattn/go-colorable v0.1.12 // indirect
Expand Down Expand Up @@ -35,12 +38,14 @@ require (
)

require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand All @@ -52,6 +57,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand All @@ -64,6 +70,7 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand All @@ -73,4 +80,4 @@ require (
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
)
Loading

0 comments on commit d3611fb

Please sign in to comment.