From 121f19d2fee438f52cde367deda4a00e8793e75f Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 27 Jan 2020 12:52:52 +0100 Subject: [PATCH] Use RFC3339 format for timestamps in SQL module (#15847) This way timezone and more precise information is stored in the final events in case they are lately parsed as dates. --- CHANGELOG.next.asciidoc | 2 ++ .../module/sql/query/_meta/data_postgres.json | 16 ++++++++-------- x-pack/metricbeat/module/sql/query/query.go | 2 +- .../module/sql/query/query_integration_test.go | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 39a0e511984..611bf8e90d6 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -63,6 +63,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Metricbeat* +- Use RFC3339 format for timestamps collected using the SQL module. {pull}15847[15847] + *Packetbeat* diff --git a/x-pack/metricbeat/module/sql/query/_meta/data_postgres.json b/x-pack/metricbeat/module/sql/query/_meta/data_postgres.json index 0f2db40c5b1..273c434c382 100644 --- a/x-pack/metricbeat/module/sql/query/_meta/data_postgres.json +++ b/x-pack/metricbeat/module/sql/query/_meta/data_postgres.json @@ -10,7 +10,7 @@ "period": 10000 }, "service": { - "address": "172.22.0.2:5432", + "address": "192.168.0.3:5432", "type": "sql" }, "sql": { @@ -19,8 +19,8 @@ "numeric": { "blk_read_time": 0, "blk_write_time": 0, - "blks_hit": 1923, - "blks_read": 111, + "blks_hit": 948, + "blks_read": 96, "conflicts": 0, "datid": 12379, "deadlocks": 0, @@ -28,18 +28,18 @@ "temp_bytes": 0, "temp_files": 0, "tup_deleted": 0, - "tup_fetched": 1249, + "tup_fetched": 616, "tup_inserted": 0, - "tup_returned": 1356, + "tup_returned": 717, "tup_updated": 0, - "xact_commit": 18, + "xact_commit": 3, "xact_rollback": 0 }, "string": { "datname": "postgres", - "stats_reset": "2020-01-21 11:23:56.53" + "stats_reset": "2020-01-25T18:21:44.869405Z" } }, - "query": "select * from pg_stat_database" + "query": "select * from pg_stat_database where datname='postgres'" } } \ No newline at end of file diff --git a/x-pack/metricbeat/module/sql/query/query.go b/x-pack/metricbeat/module/sql/query/query.go index c3507cd964e..07c9c9350b2 100644 --- a/x-pack/metricbeat/module/sql/query/query.go +++ b/x-pack/metricbeat/module/sql/query/query.go @@ -150,7 +150,7 @@ func getValue(pval *interface{}) string { case []byte: return string(v) case time.Time: - return v.Format("2006-01-02 15:04:05.999") + return v.Format(time.RFC3339Nano) default: return fmt.Sprint(v) } diff --git a/x-pack/metricbeat/module/sql/query/query_integration_test.go b/x-pack/metricbeat/module/sql/query/query_integration_test.go index d7e04f23c40..6e23be8ce9a 100644 --- a/x-pack/metricbeat/module/sql/query/query_integration_test.go +++ b/x-pack/metricbeat/module/sql/query/query_integration_test.go @@ -73,7 +73,7 @@ func TestPostgreSQL(t *testing.T) { config = testFetchConfig{ Driver: "postgres", - Query: "select * from pg_stat_database", + Query: "select * from pg_stat_database where datname='postgres'", Host: fmt.Sprintf("postgres://%s:%s@%s:%s/?sslmode=disable", user, password, host, port), Assertion: assertFieldNotContains("service.address", ":"+password+"@"), }