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

Redis discovery #3731

Merged
merged 13 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#####################################################################################
# This file is generated by the Splunk Distribution of the OpenTelemetry Collector. #
# #
# It reflects the default configuration bundled in the Collector executable for use #
# in discovery mode (--discovery) and is provided for reference or customization. #
# Please note that any changes made to this file will need to be reconciled during #
# upgrades of the Collector. #
#####################################################################################
# redis:
# enabled: true
# rule:
# docker_observer: type == "container" and any([name, image, command], {# matches "(?i)redis"}) and not (command matches "splunk.discovery")
# host_observer: type == "hostport" and command matches "(?i)redis" and not (command matches "splunk.discovery")
# k8s_observer: type == "port" and pod.name matches "(?i)redis"
# config:
# default: {}
# status:
# metrics:
# successful:
# - strict: redis.uptime
# first_only: true
# log_record:
# severity_text: info
# body: redis receiver is working!
# statements:
# failed:
# - regexp: "connection refused"
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: The container is not serving http connections.
# - regexp: "received goaway and there are no active streams"
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: Unable to connect and scrape metrics.
# - regexp: "dial tcp: lookup"
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: Unable to resolve redis tcp endpoint
# partial:
# - regexp: 'NOAUTH Authentication required.'
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: >-
# Make sure your user credentials are correctly specified using the
# `--set splunk.discovery.receivers.redis.config.password="<password>"` and
# `--set splunk.discovery.receivers.redis.config.username="<username>"` commands or the
# `SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` and
# `SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` environment variables.
# - regexp: 'called without any password configured for the default user'
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: >-
# Make sure your user credentials are correctly specified using the
# `--set splunk.discovery.receivers.redis.config.password="<password>"` command or the
# `SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` environment variables.
# - regexp: 'WRONGPASS invalid username-password pair or user is disabled'
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: >-
# Make sure your user credentials are correctly specified using the
# `--set splunk.discovery.receivers.redis.config.password="<password>"` and
# `--set splunk.discovery.receivers.redis.config.username="<username>"` commands or the
# `SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` and
# `SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` environment variables.
1 change: 1 addition & 0 deletions internal/confmapprovider/discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ The following components have bundled discovery configurations in the last Splun

I. Receivers
* `oracledb` ([Linux and Windows](./bundle/bundle.d/receivers/oracledb.discovery.yaml))
* `redis` ([Linux and Windows](./bundle/bundle.d/receivers/redis.discovery.yaml))
* `smartagent` with `collectd/mysql` monitor type ([Linux](./bundle/bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml))
* `smartagent` with `collectd/nginx` monitor type ([Linux](./bundle/bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml))
* `smartagent` with `postgresql` monitor type ([Linux and Windows](./bundle/bundle.d/receivers/smartagent-postgresql.discovery.yaml))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#####################################################################################
# Do not edit manually! #
# All changes must be made to associated .tmpl file before running 'make bundle.d'. #
#####################################################################################
redis:
enabled: true
rule:
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)redis"}) and not (command matches "splunk.discovery")
host_observer: type == "hostport" and command matches "(?i)redis" and not (command matches "splunk.discovery")
k8s_observer: type == "port" and pod.name matches "(?i)redis"
config:
default: {}
status:
metrics:
successful:
- strict: redis.uptime
first_only: true
log_record:
severity_text: info
body: redis receiver is working!
statements:
failed:
- regexp: "connection refused"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: The container is not serving http connections.
- regexp: "received goaway and there are no active streams"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: Unable to connect and scrape metrics.
- regexp: "dial tcp: lookup"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: Unable to resolve redis tcp endpoint
partial:
- regexp: 'NOAUTH Authentication required.'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set splunk.discovery.receivers.redis.config.password="<password>"` and
`--set splunk.discovery.receivers.redis.config.username="<username>"` commands or the
`SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` and
`SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` environment variables.
- regexp: 'called without any password configured for the default user'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set splunk.discovery.receivers.redis.config.password="<password>"` command or the
`SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` environment variables.
- regexp: 'WRONGPASS invalid username-password pair or user is disabled'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set splunk.discovery.receivers.redis.config.password="<password>"` and
`--set splunk.discovery.receivers.redis.config.username="<username>"` commands or the
`SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` and
`SPLUNK_DISCOVERY_RECEIVERS_redis_CONFIG_password="<password>"` environment variables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{ receiver "redis" }}:
enabled: true
rule:
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)redis"}) and not (command matches "splunk.discovery")
host_observer: type == "hostport" and command matches "(?i)redis" and not (command matches "splunk.discovery")
k8s_observer: type == "port" and pod.name matches "(?i)redis"
config:
default: {}
status:
metrics:
successful:
- strict: redis.uptime
first_only: true
log_record:
severity_text: info
body: redis receiver is working!
statements:
failed:
- regexp: "connection refused"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: The container is not serving http connections.
- regexp: "received goaway and there are no active streams"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: Unable to connect and scrape metrics.
- regexp: "dial tcp: lookup"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: Unable to resolve redis tcp endpoint
partial:
- regexp: 'NOAUTH Authentication required.'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set {{ configProperty "password" "<password>" }}` and
`--set {{ configProperty "username" "<username>" }}` commands or the
`{{ configPropertyEnvVar "password" "<password>" }}` and
`{{ configPropertyEnvVar "password" "<password>" }}` environment variables.
- regexp: 'called without any password configured for the default user'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set {{ configProperty "password" "<password>" }}` command or the
`{{ configPropertyEnvVar "password" "<password>" }}` environment variables.
- regexp: 'WRONGPASS invalid username-password pair or user is disabled'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set {{ configProperty "password" "<password>" }}` and
`--set {{ configProperty "username" "<username>" }}` commands or the
`{{ configPropertyEnvVar "password" "<password>" }}` and
`{{ configPropertyEnvVar "password" "<password>" }}` environment variables.
2 changes: 2 additions & 0 deletions internal/confmapprovider/discovery/bundle/bundle_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml.tmpl
//go:generate discoverybundler -r -t bundle.d/receivers/oracledb.discovery.yaml.tmpl
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/oracledb.discovery.yaml.tmpl
//go:generate discoverybundler -r -t bundle.d/receivers/redis.discovery.yaml.tmpl
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/redis.discovery.yaml.tmpl

//go:generate discoverybundler -r -t bundle.d/extensions/docker-observer.discovery.yaml.tmpl
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/extensions -t bundle.d/extensions/docker-observer.discovery.yaml.tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestBundleDir(t *testing.T) {
require.NoError(t, err)
require.Equal(t, []string{
"bundle.d/receivers/oracledb.discovery.yaml",
"bundle.d/receivers/redis.discovery.yaml",
"bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml",
"bundle.d/receivers/smartagent-collectd-nginx.discovery.yaml",
"bundle.d/receivers/smartagent-postgresql.discovery.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ import (
//
//go:embed bundle.d/extensions/*.discovery.yaml
//go:embed bundle.d/receivers/oracledb.discovery.yaml
//go:embed bundle.d/receivers/redis.discovery.yaml
//go:embed bundle.d/receivers/smartagent-postgresql.discovery.yaml
var BundledFS embed.FS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestBundleDir(t *testing.T) {
require.NoError(t, err)
require.Equal(t, []string{
"bundle.d/receivers/oracledb.discovery.yaml",
"bundle.d/receivers/redis.discovery.yaml",
"bundle.d/receivers/smartagent-postgresql.discovery.yaml",
}, receivers)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestK8sObserver(t *testing.T) {
`SPLUNK_DEBUG_CONFIG_SERVER=false \
SPLUNK_DISCOVERY_EXTENSIONS_host_observer_ENABLED=false \
SPLUNK_DISCOVERY_EXTENSIONS_docker_observer_ENABLED=false \
SPLUNK_DISCOVERY_RECEIVERS_redis_ENABLED=false \
SPLUNK_DISCOVERY_RECEIVERS_smartagent_CONFIG_extraDimensions_x3a__x3a_three_x2e_key='three.value.from.env.var.property' \
/otelcol --config=/config/config.yaml --config-dir=/config.d --discovery --dry-run`)
require.NoError(t, err)
Expand Down
63 changes: 63 additions & 0 deletions tests/receivers/redis/bundled_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright Splunk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integration

package tests

import (
"fmt"
"path"
"runtime"
"testing"

"github.com/signalfx/splunk-otel-collector/tests/testutils"
)

func TestRedisDockerObserver(t *testing.T) {
testutils.SkipIfNotContainerTest(t)
if runtime.GOOS == "darwin" {
t.Skip("unable to share sockets between mac and d4m vm: https://github.com/docker/for-mac/issues/483#issuecomment-758836836")
}

server := testutils.NewContainer().WithContext(path.Join(".", "testdata", "server")).WithExposedPorts("6379:6379").WithNetworks("redis_network").WithName("redis-server").WillWaitForLogs("Ready to accept connections")
client := testutils.NewContainer().WithContext(path.Join(".", "testdata", "client")).WithName("redis-client").WithNetworks("redis_network").WillWaitForLogs("redis client started")
containers := []testutils.Container{server, client}

testutils.AssertAllMetricsReceived(t, "all_server_bundled.yaml", "otlp_exporter.yaml",
containers, []testutils.CollectorBuilder{
func(c testutils.Collector) testutils.Collector {
cc := c.(*testutils.CollectorContainer)
cc.Container = cc.Container.WithBinds("/var/run/docker.sock:/var/run/docker.sock:ro")
cc.Container = cc.Container.WillWaitForLogs("Discovering for next")
cc.Container = cc.Container.WithUser(fmt.Sprintf("999:%d", testutils.GetDockerGID(t)))
return cc
},
func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{
"REDIS_PASSWORD": "securepassword",
"REDIS_USERNAME": "otel",
// confirm that debug logging doesn't affect runtime
"SPLUNK_DISCOVERY_LOG_LEVEL": "debug",
}).WithArgs(
"--discovery",
"--set", "splunk.discovery.receivers.redis.config.password=${REDIS_PASSWORD}",
"--set", "splunk.discovery.receivers.redis.config.username=${REDIS_USERNAME}",
"--set", `splunk.discovery.extensions.k8s_observer.enabled=false`,
"--set", `splunk.discovery.extensions.host_observer.enabled=false`,
)
},
},
)
}
2 changes: 2 additions & 0 deletions tests/receivers/redis/testdata/all_metrics_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
receivers:
redis:
endpoint: 0.0.0.0:6379
password: "securepassword"
username: "otel"
exporters:
otlp:
endpoint: "${OTLP_ENDPOINT}"
Expand Down
13 changes: 13 additions & 0 deletions tests/receivers/redis/testdata/otlp_exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exporters:
otlp:
endpoint: "${OTLP_ENDPOINT}"
tls:
insecure: true

service:
telemetry:
logs:
level: debug
pipelines:
metrics:
exporters: [otlp]
Loading
Loading