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

Adds redis and an example to run it #2096

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions examples/redis/README.md
Original file line number Diff line number Diff line change
@@ -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
```

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.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}
hughesjj marked this conversation as resolved.
Show resolved Hide resolved
- SPLUNK_REALM=${SPLUNK_REALM}
- SPLUNK_PASSWORD=changeme
hughesjj marked this conversation as resolved.
Show resolved Hide resolved
- 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
37 changes: 37 additions & 0 deletions examples/redis/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can write this as:

    metrics/both:
      receivers: [redis]
      processors: [batch]
      exporters: [logging, signalfx]

you don't have to and in effect this is going to define the exact same output, but just in case that wasn't an explicit set up.

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 @@ -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
Expand Down Expand Up @@ -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
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
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

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