diff --git a/docs/api-reference/apidocs.swagger.json b/docs/api-reference/apidocs.swagger.json index 89e66c602..4bc1815cc 100644 --- a/docs/api-reference/apidocs.swagger.json +++ b/docs/api-reference/apidocs.swagger.json @@ -3,7 +3,7 @@ "info": { "title": "Permify API", "description": "Permify is an open source authorization service for creating fine-grained and scalable authorization systems.", - "version": "v0.8.3", + "version": "v0.8.4", "contact": { "name": "API Support", "url": "https://github.com/Permify/permify/issues", diff --git a/go.mod b/go.mod index fec339508..fcae4351d 100644 --- a/go.mod +++ b/go.mod @@ -67,6 +67,7 @@ require ( require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/distribution/reference v0.5.0 // indirect + github.com/exaring/otelpgx v0.5.4 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/goccy/go-json v0.10.2 // indirect diff --git a/go.sum b/go.sum index 247e0f391..c9db99e7f 100644 --- a/go.sum +++ b/go.sum @@ -72,6 +72,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= +github.com/exaring/otelpgx v0.5.4 h1:uytSs8A9/8tpnJ4J8jsusbRtNgP6Cn5npnffCxE2Unk= +github.com/exaring/otelpgx v0.5.4/go.mod h1:DuRveXIeRNz6VJrMTj2uCBFqiocMx4msCN1mIMmbZUI= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= diff --git a/internal/info.go b/internal/info.go index 279d4f693..98b3e8864 100644 --- a/internal/info.go +++ b/internal/info.go @@ -23,7 +23,7 @@ var Identifier = "" */ const ( // Version is the last release of the Permify (e.g. v0.1.0) - Version = "v0.8.3" + Version = "v0.8.4" ) // Function to create a single line of the ASCII art with centered content and color diff --git a/internal/storage/postgres/utils/common.go b/internal/storage/postgres/utils/common.go index 6ccda0191..ed416dfa4 100644 --- a/internal/storage/postgres/utils/common.go +++ b/internal/storage/postgres/utils/common.go @@ -128,17 +128,26 @@ func GenerateGCQuery(table string, value uint64) squirrel.DeleteBuilder { // This function is used for consistent error handling across different parts of the application. func HandleError(ctx context.Context, span trace.Span, err error, errorCode base.ErrorCode) error { // Check if the error is context-related - if IsContextRelatedError(ctx, err) || IsSerializationRelatedError(err) { - // Use debug level logging for context or serialization-related errors - slog.Debug("an error related to context or serialization was encountered during the operation", slog.String("error", err.Error())) - } else { - span.RecordError(err) - span.SetStatus(codes.Error, err.Error()) - // Use error level logging for all other errors - slog.Error("error encountered", slog.Any("error", err)) + if IsContextRelatedError(ctx, err) { + slog.Debug("A context-related error occurred", + slog.String("error", err.Error())) + return errors.New(base.ErrorCode_ERROR_CODE_CANCELLED.String()) } - // Return a new standardized error with the provided error code + // Check if the error is serialization-related + if IsSerializationRelatedError(err) { + slog.Debug("A serialization-related error occurred", + slog.String("error", err.Error())) + return errors.New(base.ErrorCode_ERROR_CODE_SERIALIZATION.String()) + } + + // For all other types of errors, log them at the error level and record them in the span + slog.Error("An operational error occurred", + slog.Any("error", err)) + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + + // Return a new error with the standard error code provided return errors.New(errorCode.String()) } diff --git a/pkg/database/postgres/postgres.go b/pkg/database/postgres/postgres.go index 0ef73fe04..a7c04566f 100644 --- a/pkg/database/postgres/postgres.go +++ b/pkg/database/postgres/postgres.go @@ -6,6 +6,8 @@ import ( "strings" "time" + "github.com/exaring/otelpgx" + "github.com/cenkalti/backoff/v4" "golang.org/x/exp/slog" @@ -88,6 +90,9 @@ func New(uri string, opts ...Option) (*Postgres, error) { writeConfig.MaxConnLifetimeJitter = time.Duration(0.2 * float64(pg.maxConnectionLifeTime)) readConfig.MaxConnLifetimeJitter = time.Duration(0.2 * float64(pg.maxConnectionLifeTime)) + writeConfig.ConnConfig.Tracer = otelpgx.NewTracer() + readConfig.ConnConfig.Tracer = otelpgx.NewTracer() + // Create connection pools for both writing and reading operations using the configured settings. pg.WritePool, pg.ReadPool, err = createPools( context.Background(), // Context used to control the lifecycle of the pools. diff --git a/pkg/pb/base/v1/errors.pb.go b/pkg/pb/base/v1/errors.pb.go index 54eb4f183..22b5ea520 100644 --- a/pkg/pb/base/v1/errors.pb.go +++ b/pkg/pb/base/v1/errors.pb.go @@ -97,6 +97,7 @@ const ( ErrorCode_ERROR_CODE_CANNOT_CONVERT_TO_ENTITY_STATEMENT ErrorCode = 5016 ErrorCode_ERROR_CODE_CANNOT_CONVERT_TO_RELATION_STATEMENT ErrorCode = 5017 ErrorCode_ERROR_CODE_CANNOT_CONVERT_TO_ATTRIBUTE_STATEMENT ErrorCode = 5018 + ErrorCode_ERROR_CODE_SERIALIZATION ErrorCode = 5019 ) // Enum value maps for ErrorCode. @@ -172,6 +173,7 @@ var ( 5016: "ERROR_CODE_CANNOT_CONVERT_TO_ENTITY_STATEMENT", 5017: "ERROR_CODE_CANNOT_CONVERT_TO_RELATION_STATEMENT", 5018: "ERROR_CODE_CANNOT_CONVERT_TO_ATTRIBUTE_STATEMENT", + 5019: "ERROR_CODE_SERIALIZATION", } ErrorCode_value = map[string]int32{ "ERROR_CODE_UNSPECIFIED": 0, @@ -244,6 +246,7 @@ var ( "ERROR_CODE_CANNOT_CONVERT_TO_ENTITY_STATEMENT": 5016, "ERROR_CODE_CANNOT_CONVERT_TO_RELATION_STATEMENT": 5017, "ERROR_CODE_CANNOT_CONVERT_TO_ATTRIBUTE_STATEMENT": 5018, + "ERROR_CODE_SERIALIZATION": 5019, } ) @@ -340,7 +343,7 @@ var file_base_v1_errors_proto_rawDesc = []byte{ 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x2a, 0xc1, 0x15, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, + 0x67, 0x65, 0x2a, 0xe0, 0x15, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1a, 0x0a, 0x16, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x24, 0x0a, 0x1f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x4d, 0x49, 0x53, 0x53, 0x49, @@ -512,16 +515,18 @@ var file_base_v1_errors_proto_rawDesc = []byte{ 0x35, 0x0a, 0x30, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x43, 0x41, 0x4e, 0x4e, 0x4f, 0x54, 0x5f, 0x43, 0x4f, 0x4e, 0x56, 0x45, 0x52, 0x54, 0x5f, 0x54, 0x4f, 0x5f, 0x41, 0x54, 0x54, 0x52, 0x49, 0x42, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x4d, - 0x45, 0x4e, 0x54, 0x10, 0x9a, 0x27, 0x42, 0x89, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x2e, 0x62, - 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x50, 0x72, - 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x50, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, 0x2f, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x66, - 0x79, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, 0x31, - 0x3b, 0x62, 0x61, 0x73, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x42, 0x58, 0x58, 0xaa, 0x02, 0x07, - 0x42, 0x61, 0x73, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x07, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x56, - 0x31, 0xe2, 0x02, 0x13, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x42, 0x61, 0x73, 0x65, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x45, 0x4e, 0x54, 0x10, 0x9a, 0x27, 0x12, 0x1d, 0x0a, 0x18, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x5f, + 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x53, 0x45, 0x52, 0x49, 0x41, 0x4c, 0x49, 0x5a, 0x41, 0x54, 0x49, + 0x4f, 0x4e, 0x10, 0x9b, 0x27, 0x42, 0x89, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x61, + 0x73, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x50, 0x72, 0x6f, + 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x50, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, 0x2f, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, + 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x3b, + 0x62, 0x61, 0x73, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x42, 0x58, 0x58, 0xaa, 0x02, 0x07, 0x42, + 0x61, 0x73, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x07, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x56, 0x31, + 0xe2, 0x02, 0x13, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x42, 0x61, 0x73, 0x65, 0x3a, 0x3a, 0x56, + 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pkg/pb/base/v1/openapi.pb.go b/pkg/pb/base/v1/openapi.pb.go index 41f492798..56cc4a81e 100644 --- a/pkg/pb/base/v1/openapi.pb.go +++ b/pkg/pb/base/v1/openapi.pb.go @@ -46,7 +46,7 @@ var file_base_v1_openapi_proto_rawDesc = []byte{ 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x50, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, 0x2f, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2f, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, - 0x32, 0x06, 0x76, 0x30, 0x2e, 0x38, 0x2e, 0x33, 0x2a, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, + 0x32, 0x06, 0x76, 0x30, 0x2e, 0x38, 0x2e, 0x34, 0x2a, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x3a, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x5a, 0x23, 0x0a, 0x21, 0x0a, 0x0a, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x41, 0x75, 0x74, 0x68, 0x12, diff --git a/proto/base/v1/errors.proto b/proto/base/v1/errors.proto index 017a1c588..f97875d92 100644 --- a/proto/base/v1/errors.proto +++ b/proto/base/v1/errors.proto @@ -82,6 +82,7 @@ enum ErrorCode { ERROR_CODE_CANNOT_CONVERT_TO_ENTITY_STATEMENT = 5016; ERROR_CODE_CANNOT_CONVERT_TO_RELATION_STATEMENT = 5017; ERROR_CODE_CANNOT_CONVERT_TO_ATTRIBUTE_STATEMENT = 5018; + ERROR_CODE_SERIALIZATION = 5019; } // ErrorResponse diff --git a/proto/base/v1/openapi.proto b/proto/base/v1/openapi.proto index 3bbaefe2b..65b014d0e 100644 --- a/proto/base/v1/openapi.proto +++ b/proto/base/v1/openapi.proto @@ -9,7 +9,7 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Permify API"; description: "Permify is an open source authorization service for creating fine-grained and scalable authorization systems."; - version: "v0.8.3"; + version: "v0.8.4"; contact: { name: "API Support"; url: "https://github.com/Permify/permify/issues";