Skip to content

Commit

Permalink
adding mysqlreceiver dockerobserver test for discovery mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Samiur Arif committed Jan 19, 2024
1 parent d7ead56 commit 05dbd13
Show file tree
Hide file tree
Showing 14 changed files with 971 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ splunk.discovery:
k8s_observer:
enabled: true
receivers:
mysql:
enabled: false
postgresql:
enabled: true
smartagent/collectd/mysql:
enabled: true
smartagent/collectd/nginx:
enabled: true
smartagent/postgresql:
enabled: false
enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#####################################################################################
# This file is generated by the Splunk Distribution of the OpenTelemetry Collector. #
# #
# It reflects the default configuration bundled in the Collector executable for use #
# in discovery mode (--discovery) and is provided for reference or customization. #
# Please note that any changes made to this file will need to be reconciled during #
# upgrades of the Collector. #
#####################################################################################
# mysql:
# enabled: false
# rule:
# docker_observer: type == "container" and port != 33060 and any([name, image, command], {# matches "(?i)mysql"}) and not (command matches "splunk.discovery")
# host_observer: type == "hostport" and port != 33060 and command matches "(?i)mysqld"
# k8s_observer: type == "port" and port != 33060 and pod.name matches "(?i)mysql"
# config:
# default:
# username: splunk.discovery.default
# password: splunk.discovery.default
# status:
# metrics:
# successful:
# - strict: mysql.locks
# first_only: true
# log_record:
# severity_text: info
# body: Mysql receiver is working!
# statements:
# failed:
# - regexp: "Can't connect to MySQL server on .* [(]111[)]"
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: The container cannot be reached by the Collector. The container is refusing MySQL connections.
# partial:
# - regexp: 'Access denied for user'
# first_only: true
# log_record:
# severity_text: info
# append_pattern: true
# body: >-
# Make sure your user credentials are correctly specified using the
# `--set splunk.discovery.receivers.mysql.config.username="<username>"` and
# `--set splunk.discovery.receivers.mysql.config.password="<password>"` command or the
# `SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_username="<username>"` and
# `SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_password="<password>"` environment variables.
1 change: 1 addition & 0 deletions internal/confmapprovider/discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ By default, the discovery mode is provided with pre-made discovery config compon
The following components have bundled discovery configurations in the last Splunk OpenTelemetry Collector release:

I. Receivers
* `mysql` ([Linux and Windows](./bundle/bundle.d/receivers/mysql.discovery.yaml))
* `oracledb` ([Linux and Windows](./bundle/bundle.d/receivers/oracledb.discovery.yaml))
* `postgresql` ([Linux and Windows](./bundle/bundle.d/receivers/postgresql.discovery.yaml))
* `redis` ([Linux and Windows](./bundle/bundle.d/receivers/redis.discovery.yaml))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#####################################################################################
# Do not edit manually! #
# All changes must be made to associated .tmpl file before running 'make bundle.d'. #
#####################################################################################
mysql:
enabled: false
rule:
docker_observer: type == "container" and port != 33060 and any([name, image, command], {# matches "(?i)mysql"}) and not (command matches "splunk.discovery")
host_observer: type == "hostport" and port != 33060 and command matches "(?i)mysqld"
k8s_observer: type == "port" and port != 33060 and pod.name matches "(?i)mysql"
config:
default:
username: splunk.discovery.default
password: splunk.discovery.default
status:
metrics:
successful:
- strict: mysql.locks
first_only: true
log_record:
severity_text: info
body: Mysql receiver is working!
statements:
failed:
- regexp: "Can't connect to MySQL server on .* [(]111[)]"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: The container cannot be reached by the Collector. The container is refusing MySQL connections.
partial:
- regexp: 'Access denied for user'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set splunk.discovery.receivers.mysql.config.username="<username>"` and
`--set splunk.discovery.receivers.mysql.config.password="<password>"` command or the
`SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_username="<username>"` and
`SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_password="<password>"` environment variables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ receiver "mysql" }}:
enabled: false
rule:
docker_observer: type == "container" and port != 33060 and any([name, image, command], {# matches "(?i)mysql"}) and not (command matches "splunk.discovery")
host_observer: type == "hostport" and port != 33060 and command matches "(?i)mysqld"
k8s_observer: type == "port" and port != 33060 and pod.name matches "(?i)mysql"
config:
default:
username: {{ defaultValue }}
password: {{ defaultValue }}
status:
metrics:
successful:
- strict: mysql.locks
first_only: true
log_record:
severity_text: info
body: Mysql receiver is working!
statements:
failed:
- regexp: "Can't connect to MySQL server on .* [(]111[)]"
first_only: true
log_record:
severity_text: info
append_pattern: true
body: The container cannot be reached by the Collector. The container is refusing MySQL connections.
partial:
- regexp: 'Access denied for user'
first_only: true
log_record:
severity_text: info
append_pattern: true
body: >-
Make sure your user credentials are correctly specified using the
`--set {{ configProperty "username" "<username>" }}` and
`--set {{ configProperty "password" "<password>" }}` command or the
`{{ configPropertyEnvVar "username" "<username>" }}` and
`{{ configPropertyEnvVar "password" "<password>" }}` environment variables.
2 changes: 2 additions & 0 deletions internal/confmapprovider/discovery/bundle/bundle_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//go:generate discoverybundler -r -t bundle.d/extensions/k8s-observer.discovery.yaml.tmpl
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/extensions -t bundle.d/extensions/k8s-observer.discovery.yaml.tmpl

//go:generate discoverybundler -r -t bundle.d/receivers/mysql.discovery.yaml.tmpl
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/mysql.discovery.yaml.tmpl
//go:generate discoverybundler -r -t bundle.d/receivers/oracledb.discovery.yaml.tmpl
//go:generate discoverybundler -r -c -d ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/oracledb.discovery.yaml.tmpl
//go:generate discoverybundler -r -t bundle.d/receivers/postgresql.discovery.yaml.tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestBundleDir(t *testing.T) {
receivers, err := fs.Glob(BundledFS, "bundle.d/receivers/*.discovery.yaml")
require.NoError(t, err)
require.Equal(t, []string{
"bundle.d/receivers/mysql.discovery.yaml",
"bundle.d/receivers/oracledb.discovery.yaml",
"bundle.d/receivers/postgresql.discovery.yaml",
"bundle.d/receivers/redis.discovery.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
//go:embed bundle.d/extensions/docker-observer.discovery.yaml
//go:embed bundle.d/extensions/host-observer.discovery.yaml
//go:embed bundle.d/extensions/k8s-observer.discovery.yaml
//go:embed bundle.d/receivers/mysql.discovery.yaml
//go:embed bundle.d/receivers/oracledb.discovery.yaml
//go:embed bundle.d/receivers/postgresql.discovery.yaml
//go:embed bundle.d/receivers/redis.discovery.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
//go:embed bundle.d/extensions/docker-observer.discovery.yaml
//go:embed bundle.d/extensions/host-observer.discovery.yaml
//go:embed bundle.d/extensions/k8s-observer.discovery.yaml
//go:embed bundle.d/receivers/mysql.discovery.yaml
//go:embed bundle.d/receivers/oracledb.discovery.yaml
//go:embed bundle.d/receivers/postgresql.discovery.yaml
//go:embed bundle.d/receivers/redis.discovery.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestBundleDir(t *testing.T) {
receivers, err := fs.Glob(BundledFS, "bundle.d/receivers/*.discovery.yaml")
require.NoError(t, err)
require.Equal(t, []string{
"bundle.d/receivers/mysql.discovery.yaml",
"bundle.d/receivers/oracledb.discovery.yaml",
"bundle.d/receivers/postgresql.discovery.yaml",
"bundle.d/receivers/redis.discovery.yaml",
Expand Down
2 changes: 2 additions & 0 deletions internal/confmapprovider/discovery/bundle/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
// If they are desired for !windows BundledFS inclusion (and a default linux conf.d entry), ensure they are included
// in Components.Linux. If desired in windows BundledFS, ensure they are included in Components.Windows.
receivers = []string{
"mysql",
"oracledb",
"postgresql",
"redis",
Expand Down Expand Up @@ -60,6 +61,7 @@ var (
}(),
Windows: func() map[string]struct{} {
windows := map[string]struct{}{
"mysql": {},
"oracledb": {},
"postgresql": {},
"redis": {},
Expand Down
62 changes: 62 additions & 0 deletions tests/receivers/mysql/bundled_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 (
"fmt"
"path"
"runtime"
"testing"

"github.com/signalfx/splunk-otel-collector/tests/testutils"
)

func TestMysqlDockerObserver(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("unable to share sockets between mac and d4m vm: https://github.com/docker/for-mac/issues/483#issuecomment-758836836")
}
port := "3306"
mysql := []testutils.Container{testutils.NewContainer().WithContext(
path.Join(".", "testdata", "server"),
).WithName("mysql").WithExposedPorts(port + ":" + port).WillWaitForPorts(port).WillWaitForLogs("")}
testutils.SkipIfNotContainerTest(t)

testutils.AssertAllMetricsReceived(t, "bundled.yaml", "otlp_exporter.yaml",
mysql, []testutils.CollectorBuilder{
func(c testutils.Collector) testutils.Collector {
cc := c.(*testutils.CollectorContainer)
cc.Container = cc.Container.WithBinds("/var/run/docker.sock:/var/run/docker.sock:ro")
cc.Container = cc.Container.WillWaitForLogs("Discovering for next")
cc.Container = cc.Container.WithUser(fmt.Sprintf("999:%d", testutils.GetDockerGID(t)))
return cc
},
func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{
"SPLUNK_DISCOVERY_DURATION": "10s",
"SPLUNK_DISCOVERY_LOG_LEVEL": "debug",
}).WithArgs(
"--discovery",
"--set", `splunk.discovery.extensions.k8s_observer.enabled=false`,
"--set", `splunk.discovery.extensions.host_observer.enabled=false`,
"--set", `splunk.discovery.receivers.mysql.config.username=root`,
"--set", `splunk.discovery.receivers.mysql.config.password=testuser`,
"--set", `splunk.discovery.receivers.mysql.enabled=true`,
)
},
},
)
}
13 changes: 13 additions & 0 deletions tests/receivers/mysql/testdata/otlp_exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exporters:
otlp:
endpoint: "${OTLP_ENDPOINT}"
tls:
insecure: true

service:
telemetry:
logs:
level: debug
pipelines:
metrics:
exporters: [otlp]
Loading

0 comments on commit 05dbd13

Please sign in to comment.