Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds redis and an example to run it
Browse files Browse the repository at this point in the history
hughesjj committed Dec 14, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 50584bc commit 625b29a
Showing 15 changed files with 285 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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)
1. `SPLUNK_PASSWORD` (for splunk exporter)

Once you've verified your environment, you can run the example by

```bash
$> docker-compose up --build
```

## Splunk Collector

Note that you may get an error similar to `{"kind": "exporter", "data_type": "metrics", "name": "splunk_hec/metrics", "error": "Post \"https://splunk_redis:8088/services/collector\": dial tcp 172.21.0.2:8088: connect: connection refused", "interval": "3.877023586s"}` upon first startup. This is likely because the splunk_hec receiver has not fully started yet. Wait until you see the hec receiver output something like `PLAY RECAP *********************************************************************`, and it should work as expected.
50 changes: 50 additions & 0 deletions examples/redis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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"
#splunk:
# image: splunk/splunk:latest
# container_name: splunk_redis
# environment:
# - SPLUNK_START_ARGS=--accept-license
# - SPLUNK_HEC_TOKEN=00000000-0000-0000-0000-0000000000000
# - SPLUNK_PASSWORD=changeme
# ports:
# - 18000:8000
# healthcheck:
# test: ['CMD', 'curl', '-f', 'http://localhost:8000']
# interval: 5s
# timeout: 5s
# retries: 20
# volumes:
# - ./splunk.yml:/tmp/defaults/default.yml
# - /opt/splunk/var
# - /opt/splunk/etc
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
# - splunk
58 changes: 58 additions & 0 deletions examples/redis/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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:
splunk_hec/metrics:
# Splunk HTTP Event Collector token.
token: "00000000-0000-0000-0000-0000000000000"
# URL to a Splunk instance to send data to.
endpoint: "https://splunk_redis:8088/services/collector"
# Splunk index, optional name of the Splunk index targeted.
index: "metrics"
# Maximum HTTP connections to use simultaneously when sending data. Defaults to 100.
max_connections: 20
# Whether to disable gzip compression over HTTP. Defaults to false.
disable_compression: false
# HTTP timeout when sending data. Defaults to 10s.
timeout: 10s
tls:
# Whether to skip checking the certificate of the HEC endpoint when sending data over HTTPS. Defaults to false.
# For this demo, we use a self-signed certificate on the Splunk docker instance, so this flag is set to true.
insecure_skip_verify: true
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]
#metrics/splunk:
# receivers: [redis]
# processors: [batch]
# exporters: [splunk_hec/metrics]
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
11 changes: 11 additions & 0 deletions examples/redis/splunk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
splunk:
conf:
indexes:
directory: /opt/splunk/etc/apps/search/local
content:
metrics:
coldPath: $SPLUNK_DB/metrics/colddb
datatype: metric
homePath: $SPLUNK_DB/metrics/db
maxTotalDataSizeMB: 512000
thawedPath: $SPLUNK_DB/metrics/thaweddb
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -104,6 +104,11 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/go-redis/redis/v7 v7.4.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.66.0 // indirect
)

require (
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -751,6 +751,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=
@@ -1573,6 +1575,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=
@@ -1748,6 +1751,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusrec
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.66.0/go.mod h1:aqg+ZuY7ZPXOZPmahXYhKMQBz+YwpX3xGculeFAMkAY=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.66.0 h1:eWzLtJL5Dk55BxAhvd2kzmhTefsLK4RkiG0td8D+1jY=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator v0.66.0/go.mod h1:AvVX+4nWE9trHOtXavZo/PZ3uIlkO16jVaZ09ykZRKc=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.66.0 h1:Ia+Abx/txk19OGCI9Fge413vstQrmzxMYnpYMfBJE2I=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.66.0/go.mod h1:LAcR161C4uyiIYbrrIPl8WYBKr2tlTmlgXchNUKA0jY=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.66.0 h1:fvwx4FFfVMuN8EHzjBhcmdmRUtxCmaXApPkW0LbXW9A=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.66.0/go.mod h1:NWPG3+gKViUgAqNHa71BYeIXlPgOd5/Q8La5eC7kM7s=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver v0.66.0 h1:HHc7995McMaYac5YYcQvMQpL1nQAa6xKK87xEEndFSU=
@@ -2603,6 +2608,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=
2 changes: 2 additions & 0 deletions internal/components/components.go
Original file line number Diff line number Diff line change
@@ -63,6 +63,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"
@@ -138,6 +139,7 @@ func Get() (component.Factories, error) {
prometheusexecreceiver.NewFactory(),
prometheusreceiver.NewFactory(),
receivercreator.NewFactory(),
redisreceiver.NewFactory(),
sapmreceiver.NewFactory(),
signalfxreceiver.NewFactory(),
simpleprometheusreceiver.NewFactory(),
1 change: 1 addition & 0 deletions internal/components/components_test.go
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ func TestDefaultComponents(t *testing.T) {
"prometheus_exec",
"prometheus_simple",
"receiver_creator",
"redis",
"sapm",
"signalfx",
"smartagent",
37 changes: 37 additions & 0 deletions tests/receivers/redis/redisreceiver_test.go
Original file line number Diff line number Diff line change
@@ -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 || hi

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)
}
14 changes: 14 additions & 0 deletions tests/receivers/redis/testdata/all_metrics_config.yaml
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]
5 changes: 5 additions & 0 deletions tests/receivers/redis/testdata/client/Dockerfile
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/redis/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"
60 changes: 60 additions & 0 deletions tests/receivers/redis/testdata/resource_metrics/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
resource_metrics:
- attributes:
redis.version: <ANY>
scope_metrics:
- instrumentation_scope:
name: otelcol/redisreceiver
version: <ANY>
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
1 change: 1 addition & 0 deletions tests/receivers/redis/testdata/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM redis

0 comments on commit 625b29a

Please sign in to comment.