diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index b20d297e8f..29332d012b 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -221,6 +221,10 @@ jobs: image: quay.io/splunko11ytest/redis_server:latest ports: - "6379:6379" + mysql: + image: quay.io/splunko11ytest/mysql:latest + ports: + - "3306:3306" strategy: matrix: ARCH: [ "amd64", "arm64" ] diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile new file mode 100644 index 0000000000..37895da7bf --- /dev/null +++ b/docker/mysql/Dockerfile @@ -0,0 +1,6 @@ +FROM mysql:latest +ENV MYSQL_DATABASE testdb +ENV MYSQL_USER testuser +ENV MYSQL_PASSWORD testpass +ENV MYSQL_ROOT_PASSWORD testpass +COPY init.sql /docker-entrypoint-initdb.d diff --git a/tests/receivers/mysql/testdata/server/initMySqlDB.sql b/docker/mysql/init.sql similarity index 81% rename from tests/receivers/mysql/testdata/server/initMySqlDB.sql rename to docker/mysql/init.sql index d595a58fb6..9762113ccc 100644 --- a/tests/receivers/mysql/testdata/server/initMySqlDB.sql +++ b/docker/mysql/init.sql @@ -1,3 +1,4 @@ +grant PROCESS on *.* TO 'testuser'@'%'; CREATE USER 'otelu'@'localhost' IDENTIFIED BY 'otelp'; GRANT ALL PRIVILEGES ON *.* TO 'otelu'@'localhost' WITH GRANT OPTION; @@ -8,3 +9,4 @@ USE otel; CREATE TABLE dummytable (myfield VARCHAR(20)); INSERT INTO dummytable VALUES ('bar'), ('foo'); +flush privileges; diff --git a/tests/receivers/mysql/bundled_test.go b/tests/receivers/mysql/bundled_test.go index 9e84fec778..5a33f56c46 100644 --- a/tests/receivers/mysql/bundled_test.go +++ b/tests/receivers/mysql/bundled_test.go @@ -18,7 +18,6 @@ package tests import ( "fmt" - "path" "runtime" "testing" @@ -30,14 +29,10 @@ 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{ + nil, []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") @@ -54,7 +49,7 @@ func TestMysqlDockerObserver(t *testing.T) { "--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.config.password=testpass`, ) }, }, diff --git a/tests/receivers/mysql/mysql_test.go b/tests/receivers/mysql/mysql_test.go index 02f318ed7b..b56d5f3c09 100644 --- a/tests/receivers/mysql/mysql_test.go +++ b/tests/receivers/mysql/mysql_test.go @@ -18,7 +18,6 @@ package tests import ( - "path" "testing" "github.com/signalfx/splunk-otel-collector/tests/testutils" @@ -29,18 +28,14 @@ import ( // The reported telemetry may need to be updated (resource metric file changes), // They can detect breaking changes or bugs that may have been missed upstream. func TestMysqlIntegration(t *testing.T) { - port := "3306" - mysql := []testutils.Container{testutils.NewContainer().WithContext( - path.Join(".", "testdata", "server"), - ).WithName("mysql").WithExposedPorts(port + ":" + port).WillWaitForPorts(port).WillWaitForLogs("X Plugin ready for connections. Bind-address:")} testutils.AssertAllMetricsReceived(t, "all.yaml", "all_metrics_config.yaml", - mysql, []testutils.CollectorBuilder{ + nil, []testutils.CollectorBuilder{ func(collector testutils.Collector) testutils.Collector { return collector.WithEnv(map[string]string{ - "MYSQLDB_ENDPOINT": "127.0.0.1:" + port, + "MYSQLDB_ENDPOINT": "127.0.0.1:3306", "MYSQLDB_USERNAME": "root", - "MYSQLDB_PASSWORD": "testuser", + "MYSQLDB_PASSWORD": "testpass", }) }, }, diff --git a/tests/receivers/mysql/testdata/server/Dockerfile b/tests/receivers/mysql/testdata/server/Dockerfile deleted file mode 100644 index a0e923f180..0000000000 --- a/tests/receivers/mysql/testdata/server/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM mysql:8.2.0 - -RUN chown -R mysql:root /var/lib/mysql/ - -ENV MYSQL_ROOT_PASSWORD='testuser' - -COPY initMySqlDB.sql /docker-entrypoint-initdb.d/ - -EXPOSE 3306 \ No newline at end of file diff --git a/tests/receivers/smartagent/collectd-mysql/collectd_mysql_test.go b/tests/receivers/smartagent/collectd-mysql/collectd_mysql_test.go index cfd9c63393..8e03d25d17 100644 --- a/tests/receivers/smartagent/collectd-mysql/collectd_mysql_test.go +++ b/tests/receivers/smartagent/collectd-mysql/collectd_mysql_test.go @@ -17,10 +17,8 @@ package tests import ( - "context" "database/sql" "fmt" - "io" "strings" "testing" "time" @@ -39,42 +37,11 @@ const ( dbName = "testdb" ) -var mysqlServer = testutils.NewContainer().WithImage("mysql:latest").WithEnv( - map[string]string{ - "MYSQL_DATABASE": dbName, - "MYSQL_USER": user, - "MYSQL_PASSWORD": password, - "MYSQL_ROOT_PASSWORD": password, - }).WithExposedPorts("3306:3306").WithName("mysql-server").WithNetworks( - "mysql", -).WillWaitForPorts("3306").WillWaitForLogs( - "MySQL init process done. Ready for start up.", - "ready for connections. Bind-address:", -) - func TestCollectdMySQLProvidesAllMetrics(t *testing.T) { tc := testutils.NewTestcase(t) defer tc.PrintLogsOnFailure() defer tc.ShutdownOTLPReceiverSink() - cntrs, shutdown := tc.Containers(mysqlServer) - defer shutdown() - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - rc, r, err := cntrs[0].Exec(ctx, []string{"mysql", "-uroot", "-ptestpass", "-e", "grant PROCESS on *.* TO 'testuser'@'%'; flush privileges;"}) - if r != nil { - defer func() { - if t.Failed() { - out, readErr := io.ReadAll(r) - require.NoError(t, readErr) - fmt.Printf("mysql:\n%s\n", string(out)) - } - }() - } - require.NoError(t, err) - require.Zero(t, rc) - cfg := mysql.Config{ User: user, Passwd: password, @@ -112,9 +79,6 @@ func TestCollectdIsolatedLogger(t *testing.T) { tc := testutils.NewTestcase(t) defer tc.ShutdownOTLPReceiverSink() - _, shutdown := tc.Containers(mysqlServer) - defer shutdown() - for _, test := range []struct { config string expectedLogContent map[string]bool