Skip to content

Commit

Permalink
Merge pull request #5 from dmolenda-sumo/sqlqueryreceiver-add-logs-to…
Browse files Browse the repository at this point in the history
…-mysql-integration-test

SQL Query receiver: add logs to mysql integration test
  • Loading branch information
dmolenda-sumo authored May 12, 2023
2 parents 27b4c3f + e1e0684 commit 4b58330
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
41 changes: 41 additions & 0 deletions receiver/sqlqueryreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,26 @@ func TestMysqlIntegration(t *testing.T) {
},
},
},
{
SQL: "select * from simple_logs where id > ?",
TrackingColumn: "id",
TrackingStartValue: "2",
Logs: []LogsCfg{
{
BodyColumn: "body",
},
},
},
{
SQL: "select * from simple_logs where insert_time > ?",
TrackingColumn: "insert_time",
TrackingStartValue: "2022-06-03 21:59:28",
Logs: []LogsCfg{
{
BodyColumn: "body",
},
},
},
}
consumer := &consumertest.MetricsSink{}
receiver, err := factory.CreateMetricsReceiver(
Expand All @@ -444,6 +464,27 @@ func TestMysqlIntegration(t *testing.T) {
rms := metrics.ResourceMetrics()
testMovieMetrics(t, rms.At(0), genreKey)
testMysqlTypeMetrics(t, rms.At(1))

logsConsumer := &consumertest.LogsSink{}
logsReceiver, err := factory.CreateLogsReceiver(
ctx,
receivertest.NewNopCreateSettings(),
config,
logsConsumer,
)
require.NoError(t, err)
err = logsReceiver.Start(ctx, componenttest.NewNopHost())
require.NoError(t, err)
require.Eventuallyf(
t,
func() bool {
return logsConsumer.LogRecordCount() > 2
},
2*time.Minute,
1*time.Second,
"failed to receive more than 2 logs",
)
testSimpleLogs(t, logsConsumer.AllLogs())
}

func testMovieMetrics(t *testing.T, rm pmetric.ResourceMetrics, genreAttrKey string) {
Expand Down
15 changes: 15 additions & 0 deletions receiver/sqlqueryreceiver/testdata/integration/initMysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ insert into movie (title, genre, imdb_rating)
values ('Die Hard', 'Action', 8.2);
insert into movie (title, genre, imdb_rating)
values ('Mission Impossible', 'Action', 7.1);

create table simple_logs
(
id integer,
insert_time timestamp,
body text,
primary key (id)
);

insert into simple_logs (id, insert_time, body) values
(1, '2022-06-03 21:59:26', '- - - [03/Jun/2022:21:59:26 +0000] "GET /api/health HTTP/1.1" 200 6197 4 "-" "-" 445af8e6c428303f -'),
(2, '2022-06-03 21:59:26', '- - - [03/Jun/2022:21:59:26 +0000] "GET /api/health HTTP/1.1" 200 6205 5 "-" "-" 3285f43cd4baa202 -'),
(3, '2022-06-03 21:59:29', '- - - [03/Jun/2022:21:59:29 +0000] "GET /api/health HTTP/1.1" 200 6233 4 "-" "-" 579e8362d3185b61 -'),
(4, '2022-06-03 21:59:31', '- - - [03/Jun/2022:21:59:31 +0000] "GET /api/health HTTP/1.1" 200 6207 5 "-" "-" 8c6ac61ae66e509f -'),
(5, '2022-06-03 21:59:31', '- - - [03/Jun/2022:21:59:31 +0000] "GET /api/health HTTP/1.1" 200 6200 4 "-" "-" c163495861e873d8 -');

0 comments on commit 4b58330

Please sign in to comment.