Skip to content

Commit e396866

Browse files
committed
added traces and metrics
1 parent c91d23a commit e396866

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

pkg/gofr/datasource/file/gcs/file.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gcs
22

33
import (
4+
"context"
45
"errors"
56
"io"
67
"time"
@@ -147,4 +148,6 @@ func (f *GCSFile) sendOperationStats(fl *FileLog, startTime time.Time) {
147148
fl.Duration = duration
148149

149150
f.logger.Debug(fl)
151+
f.metrics.RecordHistogram(context.Background(), appFTPStats, float64(duration),
152+
"type", fl.Operation, "status", clean(fl.Status))
150153
}

pkg/gofr/datasource/file/gcs/file_parse.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
)
2222

2323
const (
24+
appFTPStats = "app_ftp_stats"
2425
statusErr = "ERROR"
2526
statusSuccess = "SUCCESS"
2627
)

pkg/gofr/datasource/file/gcs/fs_dir_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func Test_Mkdir_GCS(t *testing.T) {
7272
mockLogger.EXPECT().Debugf(gomock.Any()).AnyTimes()
7373
mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes()
7474
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
75+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
76+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
7577

7678
tests := []testCase{
7779
{
@@ -136,6 +138,8 @@ func Test_ReadDir_GCS(t *testing.T) {
136138
mockLogger.EXPECT().Logf(gomock.Any(), gomock.Any()).AnyTimes()
137139
mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes()
138140
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
141+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
142+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
139143

140144
for _, tt := range getReadDirTestCases(mockGCS) {
141145
t.Run(tt.name, func(t *testing.T) {

pkg/gofr/datasource/file/gcs/fs_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func Test_CreateFile(t *testing.T) {
4949
mockLogger.EXPECT().Logf(gomock.Any(), gomock.Any()).AnyTimes()
5050
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
5151
mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes()
52+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
53+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
5254

5355
tests := []testCase{
5456
{
@@ -122,6 +124,8 @@ func Test_Remove_GCS(t *testing.T) {
122124
mockLogger.EXPECT().Logf(gomock.Any(), gomock.Any()).AnyTimes()
123125
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
124126
mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes()
127+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
128+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
125129

126130
mockGCS.EXPECT().
127131
DeleteObject(gomock.Any(), "abc/a1.txt").
@@ -211,6 +215,8 @@ func TestRenameFile(t *testing.T) {
211215
mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes()
212216
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
213217
mockLogger.EXPECT().Debug(gomock.Any(), gomock.Any()).AnyTimes()
218+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
219+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
214220

215221
for _, tt := range tests {
216222
t.Run(tt.name, func(t *testing.T) {
@@ -290,6 +296,8 @@ func Test_StatFile_GCS(t *testing.T) {
290296
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
291297

292298
mockGCS.EXPECT().StatObject(gomock.Any(), tt.filePath).Return(tt.mockAttr, tt.mockError)
299+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
300+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
293301

294302
res, err := fs.Stat(tt.filePath)
295303
if tt.expectError {
@@ -329,6 +337,8 @@ func Test_Stat_FileAndDir(t *testing.T) {
329337
mockLogger.EXPECT().Logf(gomock.Any(), gomock.Any()).AnyTimes()
330338
mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes()
331339
mockLogger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
340+
mockMetrics.EXPECT().RecordHistogram(gomock.Any(), appFTPStats, gomock.Any(),
341+
"type", gomock.Any(), "status", gomock.Any()).AnyTimes()
332342

333343
fileName := "documents/testfile.txt"
334344
fileAttrs := &storage.ObjectAttrs{

pkg/gofr/datasource/file/gcs/interface.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ type gcsClientImpl struct {
2424
}
2525

2626
type gcsClient interface {
27-
// NewWriter(ctx context.Context, name string) *storage.Writer
2827
NewWriter(ctx context.Context, name string) io.WriteCloser
2928
NewReader(ctx context.Context, name string) (*storage.Reader, error)
3029
DeleteObject(ctx context.Context, name string) error
3130
CopyObject(ctx context.Context, src, dst string) error
3231
ListObjects(ctx context.Context, prefix string) ([]string, error)
3332
ListDir(ctx context.Context, prefix string) ([]*storage.ObjectAttrs, []string, error)
3433
StatObject(ctx context.Context, name string) (*storage.ObjectAttrs, error)
35-
// GetSignedURL(ctx context.Context, object string, expiry time.Duration) (string, error)
3634
}
3735

3836
type Metrics interface {

0 commit comments

Comments
 (0)