Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using specific pass for each host in redis output #16206

Merged
merged 21 commits into from
Feb 24, 2020
Merged
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0d9cb32
Using specific pass for each host in redis output
rvillablanca Feb 9, 2020
b88f2a7
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca Feb 13, 2020
02fb2b1
Partials advances parsing redis scheme
rvillablanca Feb 13, 2020
abb0df4
Validate tls config when schema is 'rediss'
rvillablanca Feb 13, 2020
3f23756
Fix collition name with package url
rvillablanca Feb 13, 2020
9ce4c41
* fix bug with host
rvillablanca Feb 13, 2020
79ad5a2
More validations in url
rvillablanca Feb 14, 2020
a37d524
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca Feb 14, 2020
b219e24
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca Feb 16, 2020
56cfc0e
Add some corrections
rvillablanca Feb 16, 2020
f8d1161
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca Feb 20, 2020
2d9e68b
Typo
rvillablanca Feb 20, 2020
7e53c61
unit test and integration tests
rvillablanca Feb 21, 2020
877f1fa
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca Feb 21, 2020
ed763da
Fix redis output integration tests
rvillablanca Feb 21, 2020
2296621
Minor improvements when testing redis output
rvillablanca Feb 21, 2020
30a2bf0
Add license header
rvillablanca Feb 22, 2020
df66485
Add changes to changelog
rvillablanca Feb 22, 2020
87106f9
Fix license header
rvillablanca Feb 22, 2020
0bd9c96
Fix imports
rvillablanca Feb 22, 2020
831348c
Formatting using make fmt update
rvillablanca Feb 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions libbeat/outputs/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ package redis

import (
"errors"
"fmt"
"net/url"
"strconv"
"strings"
"time"

"github.com/elastic/beats/libbeat/beat"
Expand All @@ -42,6 +46,8 @@ const (
defaultWaitRetry = 1 * time.Second
defaultMaxWaitRetry = 60 * time.Second
defaultPort = 6379
redisScheme = "redis"
tlsRedisScheme = "rediss"
)

func init() {
Expand Down Expand Up @@ -118,19 +124,57 @@ func makeRedis(
}

clients := make([]outputs.NetworkClient, len(hosts))
for i, host := range hosts {
enc, err := codec.CreateEncoder(beat, config.Codec)
for i, h := range hosts {
if parts := strings.SplitN(h, "://", 2); len(parts) != 2 {
h = fmt.Sprintf("%s://%s", redisScheme, h)
}

hostUrl, err := url.Parse(h)
if err != nil {
return outputs.Fail(err)
}

if hostUrl.Host == "" {
return outputs.Fail(fmt.Errorf("invalid redis url host %s", hostUrl.Host))
}

if hostUrl.Scheme != redisScheme && hostUrl.Scheme != tlsRedisScheme {
return outputs.Fail(fmt.Errorf("invalid redis url scheme %s", hostUrl.Scheme))
}

if hostUrl.Scheme == tlsRedisScheme && transp.TLS == nil {
transp.TLS = &transport.TLSConfig{}
}
rvillablanca marked this conversation as resolved.
Show resolved Hide resolved

var host string
var port int
if hostUrl.Port() != "" {
parts := strings.SplitN(hostUrl.Host, ":", 2)
rvillablanca marked this conversation as resolved.
Show resolved Hide resolved
host = parts[0]
port, _ = strconv.Atoi(parts[1])
} else {
host = strings.ReplaceAll(hostUrl.Host, ":", "")
port = defaultPort
}
rvillablanca marked this conversation as resolved.
Show resolved Hide resolved

conn, err := transport.NewClient(transp, "tcp", host, port)
if err != nil {
return outputs.Fail(err)
}

conn, err := transport.NewClient(transp, "tcp", host, defaultPort)
pass := config.Password
hostPass, passSet := hostUrl.User.Password()
if passSet {
pass = hostPass
}
urso marked this conversation as resolved.
Show resolved Hide resolved

enc, err := codec.CreateEncoder(beat, config.Codec)
if err != nil {
return outputs.Fail(err)
}

client := newClient(conn, observer, config.Timeout,
config.Password, config.Db, key, dataType, config.Index, enc)
pass, config.Db, key, dataType, config.Index, enc)
clients[i] = newBackoffClient(client, config.Backoff.Init, config.Backoff.Max)
}

Expand Down