From d6f3be5f27098cb8dbb1857dfbf69e1a8f0a4adb Mon Sep 17 00:00:00 2001 From: hughesjj Date: Mon, 10 Oct 2022 09:43:13 -0700 Subject: [PATCH 1/2] Adds redis and an example to run it --- examples/redis/README.md | 16 +++++ examples/redis/docker-compose.yml | 31 ++++++++++ examples/redis/otel-collector-config.yaml | 37 ++++++++++++ examples/redis/redis.conf | 4 ++ go.mod | 2 + go.sum | 6 ++ internal/components/components.go | 2 + internal/components/components_test.go | 1 + tests/receivers/redis/redisreceiver_test.go | 37 ++++++++++++ .../redis/testdata/all_metrics_config.yaml | 14 +++++ .../redis/testdata/client/Dockerfile | 5 ++ tests/receivers/redis/testdata/client/init.sh | 11 ++++ .../redis/testdata/resource_metrics/all.yaml | 60 +++++++++++++++++++ .../redis/testdata/server/Dockerfile | 1 + 14 files changed, 227 insertions(+) create mode 100644 examples/redis/README.md create mode 100644 examples/redis/docker-compose.yml create mode 100644 examples/redis/otel-collector-config.yaml create mode 100644 examples/redis/redis.conf create mode 100644 tests/receivers/redis/redisreceiver_test.go create mode 100644 tests/receivers/redis/testdata/all_metrics_config.yaml create mode 100644 tests/receivers/redis/testdata/client/Dockerfile create mode 100755 tests/receivers/redis/testdata/client/init.sh create mode 100644 tests/receivers/redis/testdata/resource_metrics/all.yaml create mode 100644 tests/receivers/redis/testdata/server/Dockerfile diff --git a/examples/redis/README.md b/examples/redis/README.md new file mode 100644 index 0000000000..876453f635 --- /dev/null +++ b/examples/redis/README.md @@ -0,0 +1,16 @@ +# Redis Infrastructure Monitoring Example + +This example provides a `docker-compose` environment that sends redis data to stdout and sfx. You can change the exporters to your liking by modifying `otel-collector-config.yaml`. + +You'll need to install docker at a minimum. Ensure the following environment variables are properly set: + +1. `REDIS_PASSWORD` (default: `changeme`, see `redis.conf`) +1. `SPLUNK_ACCESS_TOKEN` (for sfx exporter) +1. `SPLUNK_REALM` (for sfx exporter) + +Once you've verified your environment, you can run the example by + +```bash +$> docker-compose up +``` + diff --git a/examples/redis/docker-compose.yml b/examples/redis/docker-compose.yml new file mode 100644 index 0000000000..3823475a2d --- /dev/null +++ b/examples/redis/docker-compose.yml @@ -0,0 +1,31 @@ +version: "3.1" +services: + # Redis instance (the thing we're instrumenting) + redis_db: + container_name: redis_db + image: redis:latest + command: redis-server /etc/redis/redis.conf + volumes: + - "./redis.conf:/etc/redis/redis.conf" + ports: + - "6379:6379" + - "6329:6329" + otelcollector: + # if you want to run with the currently released image, + #image: quay.io/signalfx/splunk-otel-collector:latest + # if building locally via `make docker-otel`, + image: otelcol:latest + container_name: otelcollector-redis-receiver-example + environment: + - SPLUNK_ACCESS_TOKEN=${SPLUNK_ACCESS_TOKEN} + - SPLUNK_REALM=${SPLUNK_REALM} + - SPLUNK_PASSWORD=changeme + - REDIS_PASSWORD=${REDIS_PASSWORD} + command: ["--config=/etc/otel-collector-config.yaml", "--set=service.telemetry.logs.level=debug"] + volumes: + - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml + ports: + - "18088:8088" + - "8888:8888" + depends_on: + - redis_db diff --git a/examples/redis/otel-collector-config.yaml b/examples/redis/otel-collector-config.yaml new file mode 100644 index 0000000000..629f10f978 --- /dev/null +++ b/examples/redis/otel-collector-config.yaml @@ -0,0 +1,37 @@ +receivers: + redis: + # For more information on redis specific configuration, see + # See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/redisreceiver + endpoint: "redis_db:6379" + collection_interval: 10s + password: ${REDIS_PASSWORD} + metrics: + redis.role: + enabled: true + redis.cmd.calls: + enabled: true +extensions: + health_check: + endpoint: 0.0.0.0:13133 +processors: + batch: +exporters: + signalfx: + # to configure, see https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/signalfxexporter + access_token: ${SPLUNK_ACCESS_TOKEN} + realm: "${SPLUNK_REALM}" + logging: + loglevel: debug +service: + telemetry: + metrics: + address: ":8888" + pipelines: + metrics/sfx: + receivers: [redis] + processors: [batch] + exporters: [signalfx] + metrics/logging: + receivers: [redis] + processors: [batch] + exporters: [logging] diff --git a/examples/redis/redis.conf b/examples/redis/redis.conf new file mode 100644 index 0000000000..db7e02a25f --- /dev/null +++ b/examples/redis/redis.conf @@ -0,0 +1,4 @@ +bind * -::* +port 6379 +protected-mode no +requirepass changeme diff --git a/go.mod b/go.mod index d9cdcc0c67..74c4fad838 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusexecreceiver v0.68.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.68.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.68.0 + github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.68.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.68.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver v0.68.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver v0.68.0 @@ -108,6 +109,7 @@ require ( require ( github.com/Azure/azure-amqp-common-go/v4 v4.0.0 // indirect github.com/bmatcuk/doublestar/v4 v4.4.0 // indirect + github.com/go-redis/redis/v7 v7.4.1 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.68.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.68.0 // indirect github.com/ovh/go-ovh v1.3.0 // indirect diff --git a/go.sum b/go.sum index a397dce988..581e6e7955 100644 --- a/go.sum +++ b/go.sum @@ -742,6 +742,8 @@ github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-redis/redis/v7 v7.4.1 h1:PASvf36gyUpr2zdOUS/9Zqc80GbM+9BDyiJSJDDOrTI= +github.com/go-redis/redis/v7 v7.4.1/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 h1:JVrqSeQfdhYRFk24TvhTZWU0q8lfCojxZQFi3Ou7+uY= github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48/go.mod h1:dZGr0i9PLlaaTD4H/hoZIDjQ+r6xq8mgbRzHZf7f2J8= @@ -1564,6 +1566,7 @@ github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= @@ -1741,6 +1744,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusrec github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.68.1-0.20221222071356-5909db48a28d/go.mod h1:X4PVmrkPOuUsSXB+UjA+zMgqHaUdQR8ZCKSnw+l73xo= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.68.0 h1:qTznqz7WlxCVdnPz9s0rZlfeJAU3x5Mc56xe4XJfm7c= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.68.0/go.mod h1:hHUKl265CTkzTdZsxPiS7PGbYu/7KdJ+7DdDe0LKyfg= +github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.68.0 h1:b0qWPR4845j+Eura30eXh/bxnhIx4jgDa43yaBSDp5Y= +github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.68.0/go.mod h1:bS0Ym9LRcIkEA1LDQh1wYTTkoqfUX0RQ3boaqfuEolk= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.68.0 h1:70mfYCC7pvvCnoIgPg6Fa3o5fCGJORuCpWBiqSqE2N4= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.68.0/go.mod h1:DLodPA7viqYjtaGDrYxX3d1+1sJHtUk5x0MnAGDmjVk= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver v0.68.0 h1:CcmlEKbl+FA/603fSFW5iVTwqjJcTOHxUb2Rig8KBqc= @@ -2609,6 +2614,7 @@ golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/internal/components/components.go b/internal/components/components.go index 12a0338f99..c2fbce6615 100644 --- a/internal/components/components.go +++ b/internal/components/components.go @@ -64,6 +64,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusexecreceiver" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver" @@ -142,6 +143,7 @@ func Get() (otelcol.Factories, error) { prometheusexecreceiver.NewFactory(), prometheusreceiver.NewFactory(), receivercreator.NewFactory(), + redisreceiver.NewFactory(), sapmreceiver.NewFactory(), signalfxreceiver.NewFactory(), simpleprometheusreceiver.NewFactory(), diff --git a/internal/components/components_test.go b/internal/components/components_test.go index 02552f044d..45d3cc93c9 100644 --- a/internal/components/components_test.go +++ b/internal/components/components_test.go @@ -64,6 +64,7 @@ func TestDefaultComponents(t *testing.T) { "prometheus_exec", "prometheus_simple", "receiver_creator", + "redis", "sapm", "signalfx", "smartagent", diff --git a/tests/receivers/redis/redisreceiver_test.go b/tests/receivers/redis/redisreceiver_test.go new file mode 100644 index 0000000000..049d6403e2 --- /dev/null +++ b/tests/receivers/redis/redisreceiver_test.go @@ -0,0 +1,37 @@ +// 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 ( + "path" + "testing" + + "github.com/signalfx/splunk-otel-collector/tests/testutils" +) + +func TestRedisReceiverProvidesAllMetrics(t *testing.T) { + server := testutils.NewContainer().WithContext(path.Join(".", "testdata", "server")).WithExposedPorts("6379:6379").WithName("redis-server").WillWaitForPorts("6379").WillWaitForLogs("Ready to accept connections") + containers := []testutils.Container{server} + testutils.AssertAllMetricsReceived(t, "all.yaml", "all_metrics_config.yaml", containers) +} + +func TestRedisReceiverProvidesAllMetricsWithServer(t *testing.T) { + 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.yaml", "all_metrics_config.yaml", containers) +} diff --git a/tests/receivers/redis/testdata/all_metrics_config.yaml b/tests/receivers/redis/testdata/all_metrics_config.yaml new file mode 100644 index 0000000000..64ebfad8bf --- /dev/null +++ b/tests/receivers/redis/testdata/all_metrics_config.yaml @@ -0,0 +1,14 @@ +receivers: + redis: + endpoint: 0.0.0.0:6379 +exporters: + otlp: + endpoint: "${OTLP_ENDPOINT}" + insecure: true + +service: + pipelines: + metrics: + receivers: + - redis + exporters: [otlp] \ No newline at end of file diff --git a/tests/receivers/redis/testdata/client/Dockerfile b/tests/receivers/redis/testdata/client/Dockerfile new file mode 100644 index 0000000000..980131b1a4 --- /dev/null +++ b/tests/receivers/redis/testdata/client/Dockerfile @@ -0,0 +1,5 @@ +FROM redis + +COPY init.sh /usr/local/bin/init.sh + +CMD ["init.sh"] \ No newline at end of file diff --git a/tests/receivers/redis/testdata/client/init.sh b/tests/receivers/redis/testdata/client/init.sh new file mode 100755 index 0000000000..7200603e60 --- /dev/null +++ b/tests/receivers/redis/testdata/client/init.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Beginning redis client" + +# Checking for the connection, return "PONG" if succeded +redis-cli -h redis-server ping + +# Setting key value pair in the redis server from the client, return "OK" if succeded +redis-cli -h redis-server set tempkey tempvalue + +echo "redis client started" \ No newline at end of file diff --git a/tests/receivers/redis/testdata/resource_metrics/all.yaml b/tests/receivers/redis/testdata/resource_metrics/all.yaml new file mode 100644 index 0000000000..f78fdd3f7d --- /dev/null +++ b/tests/receivers/redis/testdata/resource_metrics/all.yaml @@ -0,0 +1,60 @@ +resource_metrics: + - attributes: + redis.version: + scope_metrics: + - instrumentation_scope: + name: otelcol/redisreceiver + version: + metrics: + - name: redis.uptime + type: IntMonotonicCumulativeSum + - name: redis.cpu.time + type: DoubleMonotonicCumulativeSum + - name: redis.clients.connected + type: IntNonmonotonicCumulativeSum + - name: redis.clients.max_input_buffer + type: IntGauge + - name: redis.clients.max_output_buffer + type: IntGauge + - name: redis.clients.blocked + type: IntNonmonotonicCumulativeSum + - name: redis.keys.expired + type: IntMonotonicCumulativeSum + - name: redis.keys.evicted + type: IntMonotonicCumulativeSum + - name: redis.connections.rejected + type: IntMonotonicCumulativeSum + - name: redis.memory.used + type: IntGauge + - name: redis.memory.rss + type: IntGauge + - name: redis.memory.peak + type: IntGauge + - name: redis.memory.lua + type: IntGauge + - name: redis.memory.fragmentation_ratio + type: DoubleGauge + - name: redis.rdb.changes_since_last_save + type: IntNonmonotonicCumulativeSum + - name: redis.commands + type: IntGauge + - name: redis.connections.received + type: IntMonotonicCumulativeSum + - name: redis.commands.processed + type: IntMonotonicCumulativeSum + - name: redis.net.input + type: IntMonotonicCumulativeSum + - name: redis.net.output + type: IntMonotonicCumulativeSum + - name: redis.keyspace.hits + type: IntMonotonicCumulativeSum + - name: redis.keyspace.misses + type: IntMonotonicCumulativeSum + - name: redis.latest_fork + type: IntGauge + - name: redis.slaves.connected + type: IntNonmonotonicCumulativeSum + - name: redis.replication.backlog_first_byte_offset + type: IntGauge + - name: redis.replication.offset + type: IntGauge diff --git a/tests/receivers/redis/testdata/server/Dockerfile b/tests/receivers/redis/testdata/server/Dockerfile new file mode 100644 index 0000000000..bf0a7a9756 --- /dev/null +++ b/tests/receivers/redis/testdata/server/Dockerfile @@ -0,0 +1 @@ +FROM redis From 55f0a20cd597a1b901113ec8134c264afa0e71f2 Mon Sep 17 00:00:00 2001 From: "James Hughes (Splunk)" Date: Tue, 3 Jan 2023 18:16:26 -0800 Subject: [PATCH 2/2] Update examples/redis/docker-compose.yml Co-authored-by: Antoine Toulme --- examples/redis/docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/redis/docker-compose.yml b/examples/redis/docker-compose.yml index 3823475a2d..31a6aa9baa 100644 --- a/examples/redis/docker-compose.yml +++ b/examples/redis/docker-compose.yml @@ -19,7 +19,6 @@ services: environment: - SPLUNK_ACCESS_TOKEN=${SPLUNK_ACCESS_TOKEN} - SPLUNK_REALM=${SPLUNK_REALM} - - SPLUNK_PASSWORD=changeme - REDIS_PASSWORD=${REDIS_PASSWORD} command: ["--config=/etc/otel-collector-config.yaml", "--set=service.telemetry.logs.level=debug"] volumes: