Skip to content

Commit

Permalink
Adds redis and an example to run it
Browse files Browse the repository at this point in the history
  • Loading branch information
hughesjj committed Jan 4, 2023
1 parent 2a42c1f commit 23a523c
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/redis/README.md
Original file line number Diff line number Diff line change
@@ -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
```
31 changes: 31 additions & 0 deletions examples/redis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions examples/redis/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 4 additions & 0 deletions examples/redis/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bind * -::*
port 6379
protected-mode no
requirepass changeme
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ 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/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.68.0 // indirect
github.com/ovh/go-ovh v1.3.0 // indirect
github.com/relvacode/iso8601 v1.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions internal/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -142,6 +143,7 @@ func Get() (otelcol.Factories, error) {
prometheusexecreceiver.NewFactory(),
prometheusreceiver.NewFactory(),
receivercreator.NewFactory(),
redisreceiver.NewFactory(),
sapmreceiver.NewFactory(),
signalfxreceiver.NewFactory(),
simpleprometheusreceiver.NewFactory(),
Expand Down
1 change: 1 addition & 0 deletions internal/components/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestDefaultComponents(t *testing.T) {
"prometheus_exec",
"prometheus_simple",
"receiver_creator",
"redis",
"sapm",
"signalfx",
"smartagent",
Expand Down
28 changes: 28 additions & 0 deletions tests/receivers/adopted/redisreceiver/redisreceiver_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM redis

COPY init.sh /usr/local/bin/init.sh

CMD ["init.sh"]
11 changes: 11 additions & 0 deletions tests/receivers/adopted/redisreceiver/testdata/client/init.sh
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM redis

0 comments on commit 23a523c

Please sign in to comment.