Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shmsr committed Jun 8, 2023
1 parent c40400e commit baa1059
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
17 changes: 2 additions & 15 deletions metricbeat/module/redis/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
package redis

import (
"crypto/tls"
"fmt"
"net/url"
"strconv"
"strings"
"time"

rd "github.com/gomodule/redigo/redis"

Expand All @@ -37,20 +35,10 @@ type MetricSet struct {
pool *Pool
}

type ModuleConfig struct {
IdleTimeout time.Duration `config:"idle_timeout"`
Network string `config:"network"`
MaxConn int `config:"maxconn" validate:"min=1"`
TLS *tlscommon.Config `config:"ssl"`

UseTLS bool
UseTLSConfig *tls.Config
}

// NewMetricSet creates the base for Redis metricsets
// NewMetricSet creates the base for Redis metricsets.
func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
// Unpack additional configuration options.
config := ModuleConfig{Network: "tcp", MaxConn: 10}
config := DefaultConfig()

err := base.Module().UnpackConfig(&config)
if err != nil {
Expand All @@ -67,7 +55,6 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
if err != nil {
return nil, fmt.Errorf("could not load provided TLS configuration: %w", err)
}
config.UseTLS = true
config.UseTLSConfig = tlsConfig.ToConfig()
}

Expand Down
17 changes: 12 additions & 5 deletions metricbeat/module/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,28 @@ func (p *Pool) DBNumber() int {
}

// CreatePool creates a redis connection pool
func CreatePool(host, username, password string, dbNumber int, config *ModuleConfig, connTimeout time.Duration) *Pool {
func CreatePool(host, username, password string, dbNumber int, config *Config, connTimeout time.Duration) *Pool {
pool := &rd.Pool{
MaxIdle: config.MaxConn,
IdleTimeout: config.IdleTimeout,
Dial: func() (rd.Conn, error) {
return rd.Dial(config.Network, host,
dialOptions := []rd.DialOption{
rd.DialUsername(username),
rd.DialPassword(password),
rd.DialDatabase(dbNumber),
rd.DialConnectTimeout(connTimeout),
rd.DialReadTimeout(connTimeout),
rd.DialWriteTimeout(connTimeout),
rd.DialUseTLS(config.UseTLS),
rd.DialTLSConfig(config.UseTLSConfig),
)
}

if config.TLS.IsEnabled() {
dialOptions = append(dialOptions,
rd.DialUseTLS(true),
rd.DialTLSConfig(config.UseTLSConfig),
)
}

return rd.Dial(config.Network, host, dialOptions...)
},
}

Expand Down

0 comments on commit baa1059

Please sign in to comment.