From b77e717a5e30e7ed80a93101b195bbc09d3d6ef0 Mon Sep 17 00:00:00 2001 From: hughesjj Date: Mon, 10 Oct 2022 09:43:13 -0700 Subject: [PATCH] Adds redis and an example to run it --- examples/redis/README.md | 15 +++++ examples/redis/docker-compose.yml | 31 ++++++++++ examples/redis/otel-collector-config.yaml | 32 +++++++++++ examples/redis/redis.conf | 4 ++ go.mod | 4 +- go.sum | 6 ++ internal/components/components.go | 2 + internal/components/components_test.go | 1 + .../redisreceiver/redisreceiver_test.go | 28 +++++++++ .../testdata/all_metrics_config.yaml | 14 +++++ .../redisreceiver/testdata/client/Dockerfile | 5 ++ .../redisreceiver/testdata/client/init.sh | 11 ++++ .../testdata/resource_metrics/all.yaml | 57 +++++++++++++++++++ .../redisreceiver/testdata/server/Dockerfile | 1 + 14 files changed, 209 insertions(+), 2 deletions(-) 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/adopted/redisreceiver/redisreceiver_test.go create mode 100644 tests/receivers/adopted/redisreceiver/testdata/all_metrics_config.yaml create mode 100644 tests/receivers/adopted/redisreceiver/testdata/client/Dockerfile create mode 100755 tests/receivers/adopted/redisreceiver/testdata/client/init.sh create mode 100644 tests/receivers/adopted/redisreceiver/testdata/resource_metrics/all.yaml create mode 100644 tests/receivers/adopted/redisreceiver/testdata/server/Dockerfile diff --git a/examples/redis/README.md b/examples/redis/README.md new file mode 100644 index 0000000000..ae0db45c1f --- /dev/null +++ b/examples/redis/README.md @@ -0,0 +1,15 @@ +# Splunk Redis+SignalFX 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 --build +``` diff --git a/examples/redis/docker-compose.yml b/examples/redis/docker-compose.yml new file mode 100644 index 0000000000..2c2ba38195 --- /dev/null +++ b/examples/redis/docker-compose.yml @@ -0,0 +1,31 @@ +version: "3.8" +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" + # OpenTelemetry Collector + 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} + - 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..9c1d841076 --- /dev/null +++ b/examples/redis/otel-collector-config.yaml @@ -0,0 +1,32 @@ +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} +extensions: + health_check: + endpoint: 0.0.0.0:13133 +processors: + batch: +exporters: + signalfx: + # https://aws-otel.github.io/docs/partners/splunk#configuring-signalfx-exporter + 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 f140481537..f04cc343d0 100644 --- a/go.mod +++ b/go.mod @@ -188,6 +188,7 @@ require ( github.com/go-openapi/swag v0.22.1 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-redis/redis/v7 v7.4.1 // indirect github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/go-stack/stack v1.8.1 // indirect @@ -332,6 +333,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.61.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/signalfx v0.61.0 // indirect + github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.61.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect github.com/opencontainers/runc v1.1.3 // indirect @@ -502,5 +504,3 @@ replace github.com/googleapis/gnostic v0.5.6 => github.com/googleapis/gnostic v0 // required to drop dependency on deprecated git.apache.org/thrift.git exclude go.opencensus.io v0.19.1 - - diff --git a/go.sum b/go.sum index 469308a077..8c3a3a6e1d 100644 --- a/go.sum +++ b/go.sum @@ -722,6 +722,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-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 h1:JVrqSeQfdhYRFk24TvhTZWU0q8lfCojxZQFi3Ou7+uY= @@ -1524,6 +1526,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= @@ -1690,6 +1693,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusrec github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.61.0/go.mod h1:R+2n+2LvFuRFhqs/Zo6V676ya0XzWjzSQYybIp7cisI= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.61.0 h1:yP3iOTGAdx8EFZLOhYnFWkNblXJSdZ5m982ZkrO626k= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.61.0/go.mod h1:KSeX1+phY0FHfdC3trQFCgqL7QgFD/7+b0TzXEpx8Zo= +github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.61.0 h1:jrIeKneQ2FE1A1P8JosyGe4L5Ydl3/ASdwNRtKq7G00= +github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.61.0/go.mod h1:uDEbxiREqSLVL8gPwQCan5V/OCryxGLC0WZwHsv6sIw= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.61.0 h1:YxRU4gxayNip5skw5UUHTBehXIVN95Bk4B4ffp+5ChY= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.61.0/go.mod h1:HDCFSQHBV/IjvmCJqqCYr0jxe28EjoD5pJVbFhVsYQA= github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver v0.61.0 h1:6o7DPQY5o9mAjATdDGQuuc5wLH3lMuFG9TqnzhGnPa4= @@ -2555,6 +2560,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 4dec3cce27..f0d79135ed 100644 --- a/internal/components/components.go +++ b/internal/components/components.go @@ -60,6 +60,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" @@ -128,6 +129,7 @@ func Get() (component.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 59e635a913..04c8a4fb70 100644 --- a/internal/components/components_test.go +++ b/internal/components/components_test.go @@ -60,6 +60,7 @@ func TestDefaultComponents(t *testing.T) { "prometheus_exec", "prometheus_simple", "receiver_creator", + "redis", "sapm", "signalfx", "smartagent", diff --git a/tests/receivers/adopted/redisreceiver/redisreceiver_test.go b/tests/receivers/adopted/redisreceiver/redisreceiver_test.go new file mode 100644 index 0000000000..88648d0331 --- /dev/null +++ b/tests/receivers/adopted/redisreceiver/redisreceiver_test.go @@ -0,0 +1,28 @@ +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/adopted/redisreceiver/testdata/all_metrics_config.yaml b/tests/receivers/adopted/redisreceiver/testdata/all_metrics_config.yaml new file mode 100644 index 0000000000..64ebfad8bf --- /dev/null +++ b/tests/receivers/adopted/redisreceiver/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/adopted/redisreceiver/testdata/client/Dockerfile b/tests/receivers/adopted/redisreceiver/testdata/client/Dockerfile new file mode 100644 index 0000000000..980131b1a4 --- /dev/null +++ b/tests/receivers/adopted/redisreceiver/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/adopted/redisreceiver/testdata/client/init.sh b/tests/receivers/adopted/redisreceiver/testdata/client/init.sh new file mode 100755 index 0000000000..7200603e60 --- /dev/null +++ b/tests/receivers/adopted/redisreceiver/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/adopted/redisreceiver/testdata/resource_metrics/all.yaml b/tests/receivers/adopted/redisreceiver/testdata/resource_metrics/all.yaml new file mode 100644 index 0000000000..083bd1a4ff --- /dev/null +++ b/tests/receivers/adopted/redisreceiver/testdata/resource_metrics/all.yaml @@ -0,0 +1,57 @@ +resource_metrics: + - instrumentation_library_metrics: + - instrumentation_library: + name: otelcol/redis + 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 \ No newline at end of file diff --git a/tests/receivers/adopted/redisreceiver/testdata/server/Dockerfile b/tests/receivers/adopted/redisreceiver/testdata/server/Dockerfile new file mode 100644 index 0000000000..bf0a7a9756 --- /dev/null +++ b/tests/receivers/adopted/redisreceiver/testdata/server/Dockerfile @@ -0,0 +1 @@ +FROM redis