-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding mysqlreceiver dockerobserver test for discovery mode
- Loading branch information
Samiur Arif
committed
Dec 20, 2023
1 parent
c5e933a
commit 2df5d1a
Showing
18 changed files
with
1,035 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
cmd/otelcol/config/collector/config.d.linux/receivers/mysql.discovery.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
##################################################################################### | ||
# 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: true | ||
# rule: | ||
# docker_observer: type == "container" and any([name, image, command], {# matches "(?i)mysql"}) and not (command matches "splunk.discovery") | ||
# host_observer: type == "hostport" and command matches "(?i)mysqld" | ||
# k8s_observer: type == "port" 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. | ||
# - regexp: '.* Unknown database .*' | ||
# first_only: true | ||
# log_record: | ||
# severity_text: info | ||
# append_pattern: true | ||
# body: >- | ||
# Make sure your MySQL database is correctly specified using the | ||
# `--set splunk.discovery.receivers.mysql.config.database="<db-name>"` command or the | ||
# `SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_database="<db-name>"` environment variable. | ||
# - regexp: 'mysql: Failed to connect to database .* at server .* Access denied for user .* to database' | ||
# first_only: true | ||
# log_record: | ||
# severity_text: info | ||
# append_pattern: true | ||
# body: >- | ||
# Make sure your MySQL database and auth information are correctly specified using the | ||
# `--set splunk.discovery.receivers.mysql.config.database="<db-name>"` command or the | ||
# `SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_database="<db-name>"` environment variable. | ||
# `--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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
internal/confmapprovider/discovery/bundle/bundle.d/receivers/mysql.discovery.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
##################################################################################### | ||
# Do not edit manually! # | ||
# All changes must be made to associated .tmpl file before running 'make bundle.d'. # | ||
##################################################################################### | ||
mysql: | ||
enabled: true | ||
rule: | ||
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)mysql"}) and not (command matches "splunk.discovery") | ||
host_observer: type == "hostport" and command matches "(?i)mysqld" | ||
k8s_observer: type == "port" 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. | ||
- regexp: '.* Unknown database .*' | ||
first_only: true | ||
log_record: | ||
severity_text: info | ||
append_pattern: true | ||
body: >- | ||
Make sure your MySQL database is correctly specified using the | ||
`--set splunk.discovery.receivers.mysql.config.database="<db-name>"` command or the | ||
`SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_database="<db-name>"` environment variable. | ||
- regexp: 'mysql: Failed to connect to database .* at server .* Access denied for user .* to database' | ||
first_only: true | ||
log_record: | ||
severity_text: info | ||
append_pattern: true | ||
body: >- | ||
Make sure your MySQL database and auth information are correctly specified using the | ||
`--set splunk.discovery.receivers.mysql.config.database="<db-name>"` command or the | ||
`SPLUNK_DISCOVERY_RECEIVERS_mysql_CONFIG_database="<db-name>"` environment variable. | ||
`--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. |
60 changes: 60 additions & 0 deletions
60
internal/confmapprovider/discovery/bundle/bundle.d/receivers/mysql.discovery.yaml.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{{ receiver "mysql" }}: | ||
enabled: true | ||
rule: | ||
docker_observer: type == "container" and any([name, image, command], {# matches "(?i)mysql"}) and not (command matches "splunk.discovery") | ||
host_observer: type == "hostport" and command matches "(?i)mysqld" | ||
k8s_observer: type == "port" 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. | ||
- regexp: '.* Unknown database .*' | ||
first_only: true | ||
log_record: | ||
severity_text: info | ||
append_pattern: true | ||
body: >- | ||
Make sure your MySQL database is correctly specified using the | ||
`--set {{ configProperty "database" "<db-name>" }}` command or the | ||
`{{ configPropertyEnvVar "database" "<db-name>" }}` environment variable. | ||
- regexp: 'mysql: Failed to connect to database .* at server .* Access denied for user .* to database' | ||
first_only: true | ||
log_record: | ||
severity_text: info | ||
append_pattern: true | ||
body: >- | ||
Make sure your MySQL database and auth information are correctly specified using the | ||
`--set {{ configProperty "database" "<db-name>" }}` command or the | ||
`{{ configPropertyEnvVar "database" "<db-name>" }}` environment variable. | ||
`--set {{ configProperty "username" "<username>" }}` and | ||
`--set {{ configProperty "password" "<password>" }}` command or the | ||
`{{ configPropertyEnvVar "username" "<username>" }}` and | ||
`{{ configPropertyEnvVar "password" "<password>" }}` environment variables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rovider/discovery/bundle/bundle.d/receivers/smartagent-collectd-mysql.discovery.yaml.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright Splunk, Inc. | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// 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. | ||
|
||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/signalfx/splunk-otel-collector/tests/testutils" | ||
) | ||
|
||
func TestMysqlDockerObserver(t *testing.T) { | ||
port := "3306" | ||
mysql := []testutils.Container{testutils.NewContainer().WithContext( | ||
path.Join(".", "testdata", "server"), | ||
).WithName("mysql").WithExposedPorts(port + ":" + port).WillWaitForPorts(port).WillWaitForLogs("")} | ||
testutils.SkipIfNotContainerTest(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") | ||
} | ||
|
||
testutils.AssertAllMetricsReceived(t, "bundled.yaml", "all_metrics_config.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", | ||
"MYSQLDB_ENDPOINT": "127.0.0.1:" + port, | ||
"MYSQLDB_USERNAME": "root", | ||
"MYSQLDB_PASSWORD": "testuser", | ||
}).WithArgs( | ||
"--discovery", | ||
"--set", `splunk.discovery.extensions.k8s_observer.enabled=false`, | ||
"--set", `splunk.discovery.extensions.host_observer.enabled=false`, | ||
"--set", `splunk.discovery.receivers.mysql.enabled=true`, | ||
) | ||
}, | ||
}, | ||
) | ||
} |
Oops, something went wrong.