Skip to content

Commit

Permalink
Merge pull request #1011 from Permify/next
Browse files Browse the repository at this point in the history
feat(datastore): optimize logging for datastore
  • Loading branch information
tolgaOzen authored Jan 17, 2024
2 parents a747784 + 25c4508 commit 1f869bb
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 122 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func DefaultConfig() *Config {
Enabled: false,
},
},
RateLimit: 100,
RateLimit: 10_000,
},
Profiler: Profiler{
Enabled: false,
Expand Down
4 changes: 2 additions & 2 deletions internal/storage/postgres/bundleReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle

query, args, err = builder.ToSql()
if err != nil {
return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
return nil, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
}

slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args))
Expand All @@ -55,7 +55,7 @@ func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle
if errors.Is(err, sql.ErrNoRows) {
return nil, errors.New(base.ErrorCode_ERROR_CODE_BUNDLE_NOT_FOUND.String())
}
return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SCAN)
return nil, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SCAN)
}

m := jsonpb.Unmarshaler{}
Expand Down
10 changes: 5 additions & 5 deletions internal/storage/postgres/bundleWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (b *BundleWriter) Write(ctx context.Context, bundles []storage.Bundle) (nam
m := jsonpb.Marshaler{}
jsonStr, err := m.MarshalToString(bundle.DataBundle)
if err != nil {
return names, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_INVALID_ARGUMENT)
return names, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_INVALID_ARGUMENT)
}

insertBuilder = insertBuilder.Values(bundle.Name, jsonStr, bundle.TenantID)
Expand All @@ -55,14 +55,14 @@ func (b *BundleWriter) Write(ctx context.Context, bundles []storage.Bundle) (nam

query, args, err = insertBuilder.ToSql()
if err != nil {
return names, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
return names, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
}

slog.Debug("executing sql insert query", slog.Any("query", query), slog.Any("arguments", args))

_, err = b.database.DB.ExecContext(ctx, query, args...)
if err != nil {
return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION)
return nil, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_EXECUTION)
}

slog.Debug("successfully wrote bundles to the database", slog.Any("number_of_bundles", len(bundles)))
Expand All @@ -83,12 +83,12 @@ func (b *BundleWriter) Delete(ctx context.Context, tenantID, name string) (err e

query, args, err = deleteBuilder.ToSql()
if err != nil {
return utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
return utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER)
}

_, err = b.database.DB.ExecContext(ctx, query, args...)
if err != nil {
return utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION)
return utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_EXECUTION)
}

slog.Debug("bundle successfully deleted")
Expand Down
Loading

0 comments on commit 1f869bb

Please sign in to comment.