Skip to content

Commit

Permalink
[receiver/redis] Add username parameter for connecting to redis (open…
Browse files Browse the repository at this point in the history
…-telemetry#24408)

**Description:** Adding a feature - Adding username for redis receiver
for connecting to redis over ACL

**Testing:** Running go test is ok. Generating my custom OpenTelemetry
Collector binary with redis receiver and otlp exporter (using ocb). This
custom Opentelemetry Collector collecting redis data by connecting with
a username and password work fine. I test to collect data using password
only, it works too.

**Documentation:** Mardown file has been updated
  • Loading branch information
NicoL49 committed Aug 21, 2023
1 parent 15a71d9 commit 175bb59
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .chloggen/add-username-parameter-for-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: redisreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adding username parameter for connecting to redis

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24408]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
8 changes: 7 additions & 1 deletion receiver/redisreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ type Config struct {

// TODO allow users to add additional resource key value pairs?

// Optional username. Use the specified Username to authenticate the current connection
// with one of the connections defined in the ACL list when connecting
// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
Username string `mapstructure:"username"`

// Optional password. Must match the password specified in the
// requirepass server configuration option.
// requirepass server configuration option, or the user's password when connecting
// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
Password configopaque.String `mapstructure:"password"`

TLS configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion receiver/redisreceiver/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ and extend it with more fields if needed.
| collection_interval |[time-Duration](#time-Duration)| 10s | |
| endpoint |string| | Endpoint configures the address for this network connection. For TCP and UDP networks, the address has the form "host:port". The host must be a literal IP address, or a host name that can be resolved to IP addresses. The port must be a literal port number or a service name. If the host is a literal IPv6 address it must be enclosed in square brackets, as in "[2001:db8::1]:80" or "[fe80::1%zone]:80". The zone specifies the scope of the literal IPv6 address as defined in RFC 4007. |
| transport |string| tcp | Transport to use. Known protocols are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket". |
| password |string| | Optional password. Must match the password specified in the requirepass server configuration option. |
| username |string| | Optional username. Use the specified username to authenticate the current connection with one of the connections defined in the ACL list when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system. |
| password |string| | Optional password. Must match the password specified in the requirepass server configuration option or the user's password when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system. |
| tls |[tls-TLSClientSetting](#tls-TLSClientSetting)| <no value> | TLSClientSetting contains TLS configurations that are specific to client connections in addition to the common configurations. This should be used by components configuring TLS client connections. |
| metrics |[metrics-MetricsSettings](#metrics-MetricsSettings)| <no value> | MetricsSettings provides settings for redisreceiver metrics. |

Expand Down
1 change: 1 addition & 0 deletions receiver/redisreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestConfig(t *testing.T) {
TLS: configtls.TLSClientSetting{
Insecure: true,
},
Username: "test",
Password: "test",
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
CollectionInterval: 10 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions receiver/redisreceiver/redis_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const redisMaxDbs = 16 // Maximum possible number of redis databases
func newRedisScraper(cfg *Config, settings receiver.CreateSettings) (scraperhelper.Scraper, error) {
opts := &redis.Options{
Addr: cfg.Endpoint,
Username: cfg.Username,
Password: string(cfg.Password),
Network: cfg.Transport,
}
Expand Down
1 change: 1 addition & 0 deletions receiver/redisreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
redis:
endpoint: "localhost:6379"
username: "test"
password: "test"
collection_interval: 10s
tls:
Expand Down

0 comments on commit 175bb59

Please sign in to comment.