From 165d01b905fcdc3a589c951be679fd2e640795d3 Mon Sep 17 00:00:00 2001 From: sheyanjie Date: Mon, 13 Nov 2023 09:58:29 +0800 Subject: [PATCH] fix timestamp PRECISION bug --- api/audit.go | 2 +- api/audit_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/audit.go b/api/audit.go index d6bb673..dc33aa1 100644 --- a/api/audit.go +++ b/api/audit.go @@ -115,7 +115,7 @@ func parseSql(audit AuditInfo) string { details = details[:MAX_DETAIL_LEN] } - ts := time.UnixMilli(audit.Timestamp).Format(time.RFC3339) + ts := time.UnixMilli(audit.Timestamp).Format(time.RFC3339Nano) return fmt.Sprintf( "insert into %s using operations_v2 tags ('%s') values ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", getTableName(audit), audit.ClusterID, ts, audit.User, audit.Operation, audit.Db, audit.Resource, audit.ClientAdd, details) diff --git a/api/audit_test.go b/api/audit_test.go index f31fa4c..586d118 100644 --- a/api/audit_test.go +++ b/api/audit_test.go @@ -44,20 +44,20 @@ func TestAudit(t *testing.T) { }{ { name: "1", - ts: 1692840000000, - data: `{"timestamp": 1692840000000, "cluster_id": "cluster_id", "user": "user", "operation": "operation", "db":"dbnamea", "resource":"resourcenamea", "client_add": "localhost:30000", "details": "detail"}`, + ts: 1699839716440, + data: `{"timestamp": 1699839716440, "cluster_id": "cluster_id", "user": "user", "operation": "operation", "db":"dbnamea", "resource":"resourcenamea", "client_add": "localhost:30000", "details": "detail"}`, expect: "detail", }, { name: "2", - ts: 1692850000000, - data: `{"timestamp": 1692850000000, "cluster_id": "cluster_id", "user": "user", "operation": "operation", "db":"dbnamea", "resource":"resourcenamea", "client_add": "localhost:30000", "details": "` + longDetails + `"}`, + ts: 1699839716441, + data: `{"timestamp": 1699839716441, "cluster_id": "cluster_id", "user": "user", "operation": "operation", "db":"dbnamea", "resource":"resourcenamea", "client_add": "localhost:30000", "details": "` + longDetails + `"}`, expect: longDetails[:50000], }, { name: "3", - ts: 1692860000000, - data: "{\"timestamp\": 1692860000000, \"cluster_id\": \"cluster_id\", \"user\": \"user\", \"operation\": \"operation\", \"db\":\"dbnameb\", \"resource\":\"resourcenameb\", \"client_add\": \"localhost:30000\", \"details\": \"create database `meter` buffer 32 cachemodel 'none' duration 50d keep 3650d single_stable 0 wal_retention_period 3600 precision 'ms'\"}", + ts: 1699839716442, + data: "{\"timestamp\": 1699839716442, \"cluster_id\": \"cluster_id\", \"user\": \"user\", \"operation\": \"operation\", \"db\":\"dbnameb\", \"resource\":\"resourcenameb\", \"client_add\": \"localhost:30000\", \"details\": \"create database `meter` buffer 32 cachemodel 'none' duration 50d keep 3650d single_stable 0 wal_retention_period 3600 precision 'ms'\"}", expect: "create database `meter` buffer 32 cachemodel 'none' duration 50d keep 3650d single_stable 0 wal_retention_period 3600 precision 'ms'", }, }