From a028b6c2503aa5e61dca09360f9c37e6faf1bc4b Mon Sep 17 00:00:00 2001 From: Divya Darshana Date: Mon, 18 Nov 2024 10:44:02 +0530 Subject: [PATCH 1/3] correcting time unit for logs of added http-service --- pkg/gofr/service/new.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gofr/service/new.go b/pkg/gofr/service/new.go index 9e2850dba..46bf56ba2 100644 --- a/pkg/gofr/service/new.go +++ b/pkg/gofr/service/new.go @@ -170,7 +170,7 @@ func (h *httpService) createAndSendRequest(ctx context.Context, method string, p respTime := time.Since(requestStart) - log.ResponseTime = respTime.Milliseconds() + log.ResponseTime = respTime.Microseconds() if err != nil { log.ResponseCode = http.StatusInternalServerError From 9cd1fe6a4461041b20221dfd29cb37c89f62b573 Mon Sep 17 00:00:00 2001 From: Divya Darshana Date: Mon, 18 Nov 2024 14:01:38 +0530 Subject: [PATCH 2/3] changing time unit to microseconds from milliseconds to accurately display duration in logs --- pkg/gofr/datasource/cassandra/cassandra.go | 2 +- pkg/gofr/datasource/clickhouse/clickhouse.go | 2 +- pkg/gofr/datasource/file/ftp/file.go | 2 +- pkg/gofr/datasource/file/ftp/fs.go | 2 +- pkg/gofr/datasource/file/s3/file.go | 2 +- pkg/gofr/datasource/file/s3/fs_dir.go | 2 +- pkg/gofr/datasource/file/sftp/fs.go | 2 +- pkg/gofr/datasource/kv-store/badger/badger.go | 2 +- pkg/gofr/datasource/mongo/mongo.go | 2 +- pkg/gofr/datasource/redis/hook.go | 2 +- pkg/gofr/datasource/solr/solr.go | 2 +- pkg/gofr/datasource/sql/db.go | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/gofr/datasource/cassandra/cassandra.go b/pkg/gofr/datasource/cassandra/cassandra.go index 76d1fa93f..89b7c7837 100644 --- a/pkg/gofr/datasource/cassandra/cassandra.go +++ b/pkg/gofr/datasource/cassandra/cassandra.go @@ -328,7 +328,7 @@ func (*Client) getColumnsFromColumnsInfo(columns []gocql.ColumnInfo) []string { } func (c *Client) sendOperationStats(ql *QueryLog, startTime time.Time, method string, span trace.Span) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() ql.Duration = duration diff --git a/pkg/gofr/datasource/clickhouse/clickhouse.go b/pkg/gofr/datasource/clickhouse/clickhouse.go index 3e21221cf..2775fa766 100644 --- a/pkg/gofr/datasource/clickhouse/clickhouse.go +++ b/pkg/gofr/datasource/clickhouse/clickhouse.go @@ -169,7 +169,7 @@ func (c *client) AsyncInsert(ctx context.Context, query string, wait bool, args func (c *client) sendOperationStats(start time.Time, methodType, query string, method string, span trace.Span, args ...interface{}) { - duration := time.Since(start).Milliseconds() + duration := time.Since(start).Microseconds() c.logger.Debug(&Log{ Type: methodType, diff --git a/pkg/gofr/datasource/file/ftp/file.go b/pkg/gofr/datasource/file/ftp/file.go index b88086ff0..22ea3ea85 100644 --- a/pkg/gofr/datasource/file/ftp/file.go +++ b/pkg/gofr/datasource/file/ftp/file.go @@ -389,7 +389,7 @@ func (f *file) WriteAt(p []byte, off int64) (n int, err error) { } func (f *file) sendOperationStats(fl *FileLog, startTime time.Time) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() fl.Duration = duration diff --git a/pkg/gofr/datasource/file/ftp/fs.go b/pkg/gofr/datasource/file/ftp/fs.go index 857464002..9d5367281 100644 --- a/pkg/gofr/datasource/file/ftp/fs.go +++ b/pkg/gofr/datasource/file/ftp/fs.go @@ -324,7 +324,7 @@ func (f *fileSystem) Rename(oldname, newname string) error { } func (f *fileSystem) sendOperationStats(fl *FileLog, startTime time.Time) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() fl.Duration = duration diff --git a/pkg/gofr/datasource/file/s3/file.go b/pkg/gofr/datasource/file/s3/file.go index ab7dd0e9e..5f6a347cb 100644 --- a/pkg/gofr/datasource/file/s3/file.go +++ b/pkg/gofr/datasource/file/s3/file.go @@ -468,7 +468,7 @@ func (f *s3file) Seek(offset int64, whence int) (int64, error) { // sendOperationStats logs the FileLog of any file operations performed in S3. func (f *s3file) sendOperationStats(fl *FileLog, startTime time.Time) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() fl.Duration = duration diff --git a/pkg/gofr/datasource/file/s3/fs_dir.go b/pkg/gofr/datasource/file/s3/fs_dir.go index c6cd33e86..60e13a6c2 100644 --- a/pkg/gofr/datasource/file/s3/fs_dir.go +++ b/pkg/gofr/datasource/file/s3/fs_dir.go @@ -291,7 +291,7 @@ func (f *fileSystem) renameDirectory(st, msg *string, oldPath, newPath string) e // sendOperationStats logs the FileLog of any file operations performed in S3. func (f *fileSystem) sendOperationStats(fl *FileLog, startTime time.Time) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() fl.Duration = duration diff --git a/pkg/gofr/datasource/file/sftp/fs.go b/pkg/gofr/datasource/file/sftp/fs.go index fd39d1baa..e5185c65a 100644 --- a/pkg/gofr/datasource/file/sftp/fs.go +++ b/pkg/gofr/datasource/file/sftp/fs.go @@ -255,7 +255,7 @@ func (f *fileSystem) Getwd() (string, error) { } func (f *fileSystem) sendOperationStats(fl *FileLog, startTime time.Time) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() fl.Duration = duration diff --git a/pkg/gofr/datasource/kv-store/badger/badger.go b/pkg/gofr/datasource/kv-store/badger/badger.go index e8c4e93b0..c2abcaa3e 100644 --- a/pkg/gofr/datasource/kv-store/badger/badger.go +++ b/pkg/gofr/datasource/kv-store/badger/badger.go @@ -145,7 +145,7 @@ func (c *client) useTransaction(f func(txn *badger.Txn) error) error { func (c *client) sendOperationStats(start time.Time, methodType string, method string, span trace.Span, kv ...string) { - duration := time.Since(start).Milliseconds() + duration := time.Since(start).Microseconds() c.logger.Debug(&Log{ Type: methodType, diff --git a/pkg/gofr/datasource/mongo/mongo.go b/pkg/gofr/datasource/mongo/mongo.go index 08c6d9d82..c847320d2 100644 --- a/pkg/gofr/datasource/mongo/mongo.go +++ b/pkg/gofr/datasource/mongo/mongo.go @@ -265,7 +265,7 @@ func (c *Client) CreateCollection(ctx context.Context, name string) error { } func (c *Client) sendOperationStats(ql *QueryLog, startTime time.Time, method string, span trace.Span) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() ql.Duration = duration diff --git a/pkg/gofr/datasource/redis/hook.go b/pkg/gofr/datasource/redis/hook.go index cab12df2f..372f7f1f5 100644 --- a/pkg/gofr/datasource/redis/hook.go +++ b/pkg/gofr/datasource/redis/hook.go @@ -65,7 +65,7 @@ func (ql *QueryLog) String() string { // logQuery logs the Redis query information. func (r *redisHook) sendOperationStats(start time.Time, query string, args ...interface{}) { - duration := time.Since(start).Milliseconds() + duration := time.Since(start).Microseconds() r.logger.Debug(&QueryLog{ Query: query, diff --git a/pkg/gofr/datasource/solr/solr.go b/pkg/gofr/datasource/solr/solr.go index 68f53c4e5..8af638ab4 100644 --- a/pkg/gofr/datasource/solr/solr.go +++ b/pkg/gofr/datasource/solr/solr.go @@ -274,7 +274,7 @@ func (c *Client) createRequest(ctx context.Context, method, url string, params m } func (c *Client) sendOperationStats(ctx context.Context, ql *QueryLog, startTime time.Time, method string, span trace.Span) { - duration := time.Since(startTime).Milliseconds() + duration := time.Since(startTime).Microseconds() ql.Duration = duration diff --git a/pkg/gofr/datasource/sql/db.go b/pkg/gofr/datasource/sql/db.go index e025f0b24..fc06a1c9c 100644 --- a/pkg/gofr/datasource/sql/db.go +++ b/pkg/gofr/datasource/sql/db.go @@ -45,7 +45,7 @@ func clean(query string) string { } func (d *DB) sendOperationStats(start time.Time, queryType, query string, args ...interface{}) { - duration := time.Since(start).Milliseconds() + duration := time.Since(start).Microseconds() d.logger.Debug(&Log{ Type: queryType, From f383233432726f2cce2984edb5e2cc48e137e4bf Mon Sep 17 00:00:00 2001 From: Divya Darshana Date: Thu, 21 Nov 2024 13:42:58 +0530 Subject: [PATCH 3/3] change milliseconds to microseconds for calculating duration --- pkg/gofr/datasource/opentsdb/observability.go | 2 +- pkg/gofr/datasource/sql/db.go | 2 +- pkg/gofr/grpc/log.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/gofr/datasource/opentsdb/observability.go b/pkg/gofr/datasource/opentsdb/observability.go index abba6635c..b08ac6127 100644 --- a/pkg/gofr/datasource/opentsdb/observability.go +++ b/pkg/gofr/datasource/opentsdb/observability.go @@ -36,7 +36,7 @@ func (ql *QueryLog) PrettyPrint(writer io.Writer) { } func sendOperationStats(logger Logger, start time.Time, operation string, status, message *string, span trace.Span) { - duration := time.Since(start).Milliseconds() + duration := time.Since(start).Microseconds() logger.Debug(&QueryLog{ Operation: operation, diff --git a/pkg/gofr/datasource/sql/db.go b/pkg/gofr/datasource/sql/db.go index fc06a1c9c..1399e5946 100644 --- a/pkg/gofr/datasource/sql/db.go +++ b/pkg/gofr/datasource/sql/db.go @@ -129,7 +129,7 @@ type Tx struct { } func (t *Tx) sendOperationStats(start time.Time, queryType, query string, args ...interface{}) { - duration := time.Since(start).Milliseconds() + duration := time.Since(start).Microseconds() t.logger.Debug(&Log{ Type: queryType, diff --git a/pkg/gofr/grpc/log.go b/pkg/gofr/grpc/log.go index dbcdbf808..d4b1a58b9 100644 --- a/pkg/gofr/grpc/log.go +++ b/pkg/gofr/grpc/log.go @@ -67,7 +67,7 @@ func LoggingInterceptor(logger Logger) grpc.UnaryServerInterceptor { l := RPCLog{ ID: trace.SpanFromContext(ctx).SpanContext().TraceID().String(), StartTime: start.Format("2006-01-02T15:04:05.999999999-07:00"), - ResponseTime: time.Since(start).Milliseconds(), + ResponseTime: time.Since(start).Microseconds(), Method: info.FullMethod, }