From 175bb59ae69c8ccca58952350e477f4775f31e30 Mon Sep 17 00:00:00 2001 From: Nicolas <140058673+NicoL49@users.noreply.github.com> Date: Mon, 21 Aug 2023 07:24:24 +0200 Subject: [PATCH] [receiver/redis] Add username parameter for connecting to redis (#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 --- ...add-username-parameter-for-connection.yaml | 20 +++++++++++++++++++ receiver/redisreceiver/config.go | 8 +++++++- receiver/redisreceiver/config.md | 3 ++- receiver/redisreceiver/config_test.go | 1 + receiver/redisreceiver/redis_scraper.go | 1 + receiver/redisreceiver/testdata/config.yaml | 1 + 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .chloggen/add-username-parameter-for-connection.yaml diff --git a/.chloggen/add-username-parameter-for-connection.yaml b/.chloggen/add-username-parameter-for-connection.yaml new file mode 100644 index 000000000000..440353da45ad --- /dev/null +++ b/.chloggen/add-username-parameter-for-connection.yaml @@ -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: \ No newline at end of file diff --git a/receiver/redisreceiver/config.go b/receiver/redisreceiver/config.go index 65ff7b30afcb..d8580c690fd2 100644 --- a/receiver/redisreceiver/config.go +++ b/receiver/redisreceiver/config.go @@ -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"` diff --git a/receiver/redisreceiver/config.md b/receiver/redisreceiver/config.md index ceea59bbf224..48ca8477a84b 100644 --- a/receiver/redisreceiver/config.md +++ b/receiver/redisreceiver/config.md @@ -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)| | 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)| | MetricsSettings provides settings for redisreceiver metrics. | diff --git a/receiver/redisreceiver/config_test.go b/receiver/redisreceiver/config_test.go index f672f4c8edf5..9e0789d22249 100644 --- a/receiver/redisreceiver/config_test.go +++ b/receiver/redisreceiver/config_test.go @@ -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, diff --git a/receiver/redisreceiver/redis_scraper.go b/receiver/redisreceiver/redis_scraper.go index 107132d71d08..efe0a0c8e433 100644 --- a/receiver/redisreceiver/redis_scraper.go +++ b/receiver/redisreceiver/redis_scraper.go @@ -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, } diff --git a/receiver/redisreceiver/testdata/config.yaml b/receiver/redisreceiver/testdata/config.yaml index 018061947a15..6f7ffe158b3b 100644 --- a/receiver/redisreceiver/testdata/config.yaml +++ b/receiver/redisreceiver/testdata/config.yaml @@ -1,5 +1,6 @@ redis: endpoint: "localhost:6379" + username: "test" password: "test" collection_interval: 10s tls: