From a6abc32a4b84e9c2f7d8a0ed5d1c73ec4c949967 Mon Sep 17 00:00:00 2001 From: Ufuk Date: Thu, 31 Oct 2024 15:46:42 +0300 Subject: [PATCH 1/2] feat: new global tracer and meter --- internal/engines/cache/check.go | 13 +++------ internal/invoke/invoke.go | 35 ++++++++++------------- internal/monitoring.go | 4 +-- internal/servers/bundleServer.go | 7 +++-- internal/servers/dataServer.go | 29 ++++++++++--------- internal/servers/permissionServer.go | 13 +++++---- internal/servers/schemaServer.go | 15 +++++----- internal/servers/server.go | 6 ---- internal/servers/tenancyServer.go | 7 +++-- internal/servers/watchServer.go | 3 +- internal/storage/memory/tracer.go | 7 ----- internal/storage/postgres/bundleReader.go | 3 +- internal/storage/postgres/bundleWriter.go | 5 ++-- internal/storage/postgres/dataReader.go | 15 +++++----- internal/storage/postgres/dataWriter.go | 7 +++-- internal/storage/postgres/schemaReader.go | 13 +++++---- internal/storage/postgres/schemaWriter.go | 3 +- internal/storage/postgres/tenantReader.go | 3 +- internal/storage/postgres/tenantWriter.go | 5 ++-- internal/storage/postgres/tracer.go | 7 ----- 20 files changed, 92 insertions(+), 108 deletions(-) delete mode 100644 internal/storage/memory/tracer.go delete mode 100644 internal/storage/postgres/tracer.go diff --git a/internal/engines/cache/check.go b/internal/engines/cache/check.go index c8e74f7f7..98b96f66b 100644 --- a/internal/engines/cache/check.go +++ b/internal/engines/cache/check.go @@ -5,11 +5,11 @@ import ( "encoding/hex" "time" - "go.opentelemetry.io/otel" api "go.opentelemetry.io/otel/metric" "github.com/cespare/xxhash/v2" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/engines" "github.com/Permify/permify/internal/invoke" "github.com/Permify/permify/internal/storage" @@ -18,11 +18,6 @@ import ( "github.com/Permify/permify/pkg/telemetry" ) -var ( - tracer = otel.Tracer("check-cache") - meter = otel.Meter("check-cache") -) - // CheckEngineWithCache is a struct that holds an instance of a cache.Cache for managing engine cache. type CheckEngineWithCache struct { // schemaReader is responsible for reading schema information @@ -46,8 +41,8 @@ func NewCheckEngineWithCache( schemaReader: schemaReader, checker: checker, cache: cache, - cacheCounter: telemetry.NewCounter(meter, "cache_check_count", "Number of permission cached checks performed"), - cacheHitDurationHistogram: telemetry.NewHistogram(meter, "cache_hit_duration", "microseconds", "Duration of cache hits in microseconds"), + cacheCounter: telemetry.NewCounter(internal.Meter, "cache_check_count", "Number of permission cached checks performed"), + cacheHitDurationHistogram: telemetry.NewHistogram(internal.Meter, "cache_hit_duration", "microseconds", "Duration of cache hits in microseconds"), } } @@ -72,7 +67,7 @@ func (c *CheckEngineWithCache) Check(ctx context.Context, request *base.Permissi // If a cached result is found, handle exclusion and return the result. if found { - ctx, span := tracer.Start(ctx, "hit") + ctx, span := internal.Tracer.Start(ctx, "hit") defer span.End() start := time.Now() diff --git a/internal/invoke/invoke.go b/internal/invoke/invoke.go index f16164a8f..37bc72de5 100644 --- a/internal/invoke/invoke.go +++ b/internal/invoke/invoke.go @@ -5,12 +5,12 @@ import ( "sync/atomic" "time" - "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" otelCodes "go.opentelemetry.io/otel/codes" api "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" base "github.com/Permify/permify/pkg/pb/base/v1" "github.com/Permify/permify/pkg/telemetry" @@ -18,11 +18,6 @@ import ( "github.com/Permify/permify/pkg/tuple" ) -var ( - tracer = otel.Tracer("invoke") - meter = otel.Meter("invoke") -) - // Invoker is an interface that groups multiple permission-related interfaces. // It is used to define a common contract for invoking various permission operations. type Invoker interface { @@ -103,14 +98,14 @@ func NewDirectInvoker( ec: ec, lo: lo, sp: sp, - checkCounter: telemetry.NewCounter(meter, "check_count", "Number of permission checks performed"), - lookupEntityCounter: telemetry.NewCounter(meter, "lookup_entity_count", "Number of permission lookup entity performed"), - lookupSubjectCounter: telemetry.NewCounter(meter, "lookup_subject_count", "Number of permission lookup subject performed"), - subjectPermissionCounter: telemetry.NewCounter(meter, "subject_permission_count", "Number of subject permission performed"), - checkDurationHistogram: telemetry.NewHistogram(meter, "check_duration", "microseconds", "Duration of checks in microseconds"), - lookupEntityDurationHistogram: telemetry.NewHistogram(meter, "lookup_entity_duration", "microseconds", "Duration of lookup entity duration in microseconds"), - lookupSubjectDurationHistogram: telemetry.NewHistogram(meter, "lookup_subject_duration", "microseconds", "Duration of lookup subject duration in microseconds"), - subjectPermissionDurationHistogram: telemetry.NewHistogram(meter, "subject_permission_duration", "microseconds", "Duration of subject permission duration in microseconds"), + checkCounter: telemetry.NewCounter(internal.Meter, "check_count", "Number of permission checks performed"), + lookupEntityCounter: telemetry.NewCounter(internal.Meter, "lookup_entity_count", "Number of permission lookup entity performed"), + lookupSubjectCounter: telemetry.NewCounter(internal.Meter, "lookup_subject_count", "Number of permission lookup subject performed"), + subjectPermissionCounter: telemetry.NewCounter(internal.Meter, "subject_permission_count", "Number of subject permission performed"), + checkDurationHistogram: telemetry.NewHistogram(internal.Meter, "check_duration", "microseconds", "Duration of checks in microseconds"), + lookupEntityDurationHistogram: telemetry.NewHistogram(internal.Meter, "lookup_entity_duration", "microseconds", "Duration of lookup entity duration in microseconds"), + lookupSubjectDurationHistogram: telemetry.NewHistogram(internal.Meter, "lookup_subject_duration", "microseconds", "Duration of lookup subject duration in microseconds"), + subjectPermissionDurationHistogram: telemetry.NewHistogram(internal.Meter, "subject_permission_duration", "microseconds", "Duration of subject permission duration in microseconds"), } } @@ -118,7 +113,7 @@ func NewDirectInvoker( // It calls the Run method of the CheckEngine with the provided context and PermissionCheckRequest, // and returns a PermissionCheckResponse and an error if any. func (invoker *DirectInvoker) Check(ctx context.Context, request *base.PermissionCheckRequest) (response *base.PermissionCheckResponse, err error) { - ctx, span := tracer.Start(ctx, "check", trace.WithAttributes( + ctx, span := internal.Tracer.Start(ctx, "check", trace.WithAttributes( attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())}, attribute.KeyValue{Key: "entity", Value: attribute.StringValue(tuple.EntityToString(request.GetEntity()))}, attribute.KeyValue{Key: "permission", Value: attribute.StringValue(request.GetPermission())}, @@ -208,7 +203,7 @@ func (invoker *DirectInvoker) Check(ctx context.Context, request *base.Permissio // It calls the Run method of the ExpandEngine with the provided context and PermissionExpandRequest, // and returns a PermissionExpandResponse and an error if any. func (invoker *DirectInvoker) Expand(ctx context.Context, request *base.PermissionExpandRequest) (response *base.PermissionExpandResponse, err error) { - ctx, span := tracer.Start(ctx, "expand", trace.WithAttributes( + ctx, span := internal.Tracer.Start(ctx, "expand", trace.WithAttributes( attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())}, attribute.KeyValue{Key: "entity", Value: attribute.StringValue(tuple.EntityToString(request.GetEntity()))}, attribute.KeyValue{Key: "permission", Value: attribute.StringValue(request.GetPermission())}, @@ -242,7 +237,7 @@ func (invoker *DirectInvoker) Expand(ctx context.Context, request *base.Permissi // It calls the Run method of the LookupEntityEngine with the provided context and PermissionLookupEntityRequest, // and returns a PermissionLookupEntityResponse and an error if any. func (invoker *DirectInvoker) LookupEntity(ctx context.Context, request *base.PermissionLookupEntityRequest) (response *base.PermissionLookupEntityResponse, err error) { - ctx, span := tracer.Start(ctx, "lookup-entity", trace.WithAttributes( + ctx, span := internal.Tracer.Start(ctx, "lookup-entity", trace.WithAttributes( attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())}, attribute.KeyValue{Key: "entity_type", Value: attribute.StringValue(request.GetEntityType())}, attribute.KeyValue{Key: "permission", Value: attribute.StringValue(request.GetPermission())}, @@ -289,7 +284,7 @@ func (invoker *DirectInvoker) LookupEntity(ctx context.Context, request *base.Pe // It calls the Stream method of the LookupEntityEngine with the provided context, PermissionLookupEntityRequest, and Permission_LookupEntityStreamServer, // and returns an error if any. func (invoker *DirectInvoker) LookupEntityStream(ctx context.Context, request *base.PermissionLookupEntityRequest, server base.Permission_LookupEntityStreamServer) (err error) { - ctx, span := tracer.Start(ctx, "lookup-entity-stream", trace.WithAttributes( + ctx, span := internal.Tracer.Start(ctx, "lookup-entity-stream", trace.WithAttributes( attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())}, attribute.KeyValue{Key: "entity_type", Value: attribute.StringValue(request.GetEntityType())}, attribute.KeyValue{Key: "permission", Value: attribute.StringValue(request.GetPermission())}, @@ -335,7 +330,7 @@ func (invoker *DirectInvoker) LookupEntityStream(ctx context.Context, request *b // LookupSubject is a method of the DirectInvoker structure. It handles the task of looking up subjects // and returning the results in a response. func (invoker *DirectInvoker) LookupSubject(ctx context.Context, request *base.PermissionLookupSubjectRequest) (response *base.PermissionLookupSubjectResponse, err error) { - ctx, span := tracer.Start(ctx, "lookup-subject", trace.WithAttributes( + ctx, span := internal.Tracer.Start(ctx, "lookup-subject", trace.WithAttributes( attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())}, attribute.KeyValue{Key: "entity", Value: attribute.StringValue(tuple.EntityToString(request.GetEntity()))}, attribute.KeyValue{Key: "permission", Value: attribute.StringValue(request.GetPermission())}, @@ -389,7 +384,7 @@ func (invoker *DirectInvoker) LookupSubject(ctx context.Context, request *base.P // SubjectPermission is a method of the DirectInvoker structure. It handles the task of subject's permissions // and returning the results in a response. func (invoker *DirectInvoker) SubjectPermission(ctx context.Context, request *base.PermissionSubjectPermissionRequest) (response *base.PermissionSubjectPermissionResponse, err error) { - ctx, span := tracer.Start(ctx, "subject-permission", trace.WithAttributes( + ctx, span := internal.Tracer.Start(ctx, "subject-permission", trace.WithAttributes( attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())}, attribute.KeyValue{Key: "entity", Value: attribute.StringValue(tuple.EntityToString(request.GetEntity()))}, attribute.KeyValue{Key: "subject", Value: attribute.StringValue(tuple.SubjectToString(request.GetSubject()))}, diff --git a/internal/monitoring.go b/internal/monitoring.go index 70f395cb7..63ba55b28 100644 --- a/internal/monitoring.go +++ b/internal/monitoring.go @@ -3,6 +3,6 @@ package internal import "go.opentelemetry.io/otel" var ( - tracer = otel.Tracer("permify") - meter = otel.Meter("permify") + Tracer = otel.Tracer("permify") + Meter = otel.Meter("permify") ) diff --git a/internal/servers/bundleServer.go b/internal/servers/bundleServer.go index 75ce1c694..7f6669f88 100644 --- a/internal/servers/bundleServer.go +++ b/internal/servers/bundleServer.go @@ -7,6 +7,7 @@ import ( otelCodes "go.opentelemetry.io/otel/codes" "google.golang.org/grpc/status" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/validation" v1 "github.com/Permify/permify/pkg/pb/base/v1" @@ -32,7 +33,7 @@ func NewBundleServer( // Write handles the writing of bundles. func (r *BundleServer) Write(ctx context.Context, request *v1.BundleWriteRequest) (*v1.BundleWriteResponse, error) { - ctx, span := tracer.Start(ctx, "bundle.write") + ctx, span := internal.Tracer.Start(ctx, "bundle.write") defer span.End() v := request.Validate() @@ -73,7 +74,7 @@ func (r *BundleServer) Write(ctx context.Context, request *v1.BundleWriteRequest // Read handles the reading of bundles. func (r *BundleServer) Read(ctx context.Context, request *v1.BundleReadRequest) (*v1.BundleReadResponse, error) { - ctx, span := tracer.Start(ctx, "bundle.read") + ctx, span := internal.Tracer.Start(ctx, "bundle.read") defer span.End() v := request.Validate() @@ -96,7 +97,7 @@ func (r *BundleServer) Read(ctx context.Context, request *v1.BundleReadRequest) // Delete handles the deletion of bundles. func (r *BundleServer) Delete(ctx context.Context, request *v1.BundleDeleteRequest) (*v1.BundleDeleteResponse, error) { - ctx, span := tracer.Start(ctx, "bundle.delete") + ctx, span := internal.Tracer.Start(ctx, "bundle.delete") defer span.End() v := request.Validate() diff --git a/internal/servers/dataServer.go b/internal/servers/dataServer.go index 71858e4f1..d1ee0b164 100644 --- a/internal/servers/dataServer.go +++ b/internal/servers/dataServer.go @@ -9,6 +9,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/status" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/validation" "github.com/Permify/permify/pkg/attribute" @@ -47,19 +48,19 @@ func NewDataServer( dw: dw, br: br, sr: sr, - writeDataHistogram: telemetry.NewHistogram(meter, "write_data", "microseconds", "Duration of writing data in microseconds"), - deleteDataHistogram: telemetry.NewHistogram(meter, "delete_data", "microseconds", "Duration of deleting data in microseconds"), - readAttributesHistogram: telemetry.NewHistogram(meter, "read_attributes", "microseconds", "Duration of reading attributes in microseconds"), - readRelationshipsHistogram: telemetry.NewHistogram(meter, "read_relationships", "microseconds", "Duration of reading relationships in microseconds"), - writeRelationshipsHistogram: telemetry.NewHistogram(meter, "write_relationships", "microseconds", "Duration of writing relationships in microseconds"), - deleteRelationshipsHistogram: telemetry.NewHistogram(meter, "delete_relationships", "microseconds", "Duration of deleting relationships in microseconds"), - runBundleHistogram: telemetry.NewHistogram(meter, "delete_relationships", "run_bundle", "Duration of running bunble in microseconds"), + writeDataHistogram: telemetry.NewHistogram(internal.Meter, "write_data", "microseconds", "Duration of writing data in microseconds"), + deleteDataHistogram: telemetry.NewHistogram(internal.Meter, "delete_data", "microseconds", "Duration of deleting data in microseconds"), + readAttributesHistogram: telemetry.NewHistogram(internal.Meter, "read_attributes", "microseconds", "Duration of reading attributes in microseconds"), + readRelationshipsHistogram: telemetry.NewHistogram(internal.Meter, "read_relationships", "microseconds", "Duration of reading relationships in microseconds"), + writeRelationshipsHistogram: telemetry.NewHistogram(internal.Meter, "write_relationships", "microseconds", "Duration of writing relationships in microseconds"), + deleteRelationshipsHistogram: telemetry.NewHistogram(internal.Meter, "delete_relationships", "microseconds", "Duration of deleting relationships in microseconds"), + runBundleHistogram: telemetry.NewHistogram(internal.Meter, "delete_relationships", "run_bundle", "Duration of running bunble in microseconds"), } } // ReadRelationships - Allows directly querying the stored engines data to display and filter stored relational tuples func (r *DataServer) ReadRelationships(ctx context.Context, request *v1.RelationshipReadRequest) (*v1.RelationshipReadResponse, error) { - ctx, span := tracer.Start(ctx, "data.read.relationships") + ctx, span := internal.Tracer.Start(ctx, "data.read.relationships") defer span.End() start := time.Now() @@ -110,7 +111,7 @@ func (r *DataServer) ReadRelationships(ctx context.Context, request *v1.Relation // ReadAttributes - Allows directly querying the stored engines data to display and filter stored attribute tuples func (r *DataServer) ReadAttributes(ctx context.Context, request *v1.AttributeReadRequest) (*v1.AttributeReadResponse, error) { - ctx, span := tracer.Start(ctx, "data.read.attributes") + ctx, span := internal.Tracer.Start(ctx, "data.read.attributes") defer span.End() start := time.Now() @@ -161,7 +162,7 @@ func (r *DataServer) ReadAttributes(ctx context.Context, request *v1.AttributeRe // Write - Write relationships and attributes to writeDB func (r *DataServer) Write(ctx context.Context, request *v1.DataWriteRequest) (*v1.DataWriteResponse, error) { - ctx, span := tracer.Start(ctx, "data.write") + ctx, span := internal.Tracer.Start(ctx, "data.write") defer span.End() start := time.Now() @@ -260,7 +261,7 @@ func (r *DataServer) Write(ctx context.Context, request *v1.DataWriteRequest) (* // WriteRelationships - Write relation tuples to writeDB func (r *DataServer) WriteRelationships(ctx context.Context, request *v1.RelationshipWriteRequest) (*v1.RelationshipWriteResponse, error) { - ctx, span := tracer.Start(ctx, "relationships.write") + ctx, span := internal.Tracer.Start(ctx, "relationships.write") defer span.End() start := time.Now() @@ -329,7 +330,7 @@ func (r *DataServer) WriteRelationships(ctx context.Context, request *v1.Relatio // Delete - Delete relationships and attributes from writeDB func (r *DataServer) Delete(ctx context.Context, request *v1.DataDeleteRequest) (*v1.DataDeleteResponse, error) { - ctx, span := tracer.Start(ctx, "data.delete") + ctx, span := internal.Tracer.Start(ctx, "data.delete") defer span.End() start := time.Now() @@ -361,7 +362,7 @@ func (r *DataServer) Delete(ctx context.Context, request *v1.DataDeleteRequest) // DeleteRelationships - Delete relationships from writeDB func (r *DataServer) DeleteRelationships(ctx context.Context, request *v1.RelationshipDeleteRequest) (*v1.RelationshipDeleteResponse, error) { - ctx, span := tracer.Start(ctx, "relationships.delete") + ctx, span := internal.Tracer.Start(ctx, "relationships.delete") defer span.End() start := time.Now() @@ -393,7 +394,7 @@ func (r *DataServer) DeleteRelationships(ctx context.Context, request *v1.Relati // RunBundle executes a bundle and returns its snapshot token. func (r *DataServer) RunBundle(ctx context.Context, request *v1.BundleRunRequest) (*v1.BundleRunResponse, error) { - ctx, span := tracer.Start(ctx, "bundle.run") + ctx, span := internal.Tracer.Start(ctx, "bundle.run") defer span.End() start := time.Now() diff --git a/internal/servers/permissionServer.go b/internal/servers/permissionServer.go index dd41fac2d..a8df8a697 100644 --- a/internal/servers/permissionServer.go +++ b/internal/servers/permissionServer.go @@ -7,6 +7,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/status" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/invoke" v1 "github.com/Permify/permify/pkg/pb/base/v1" ) @@ -27,7 +28,7 @@ func NewPermissionServer(i invoke.Invoker) *PermissionServer { // Check - Performs Authorization Check func (r *PermissionServer) Check(ctx context.Context, request *v1.PermissionCheckRequest) (*v1.PermissionCheckResponse, error) { - ctx, span := tracer.Start(ctx, "permissions.check") + ctx, span := internal.Tracer.Start(ctx, "permissions.check") defer span.End() v := request.Validate() @@ -48,7 +49,7 @@ func (r *PermissionServer) Check(ctx context.Context, request *v1.PermissionChec // Expand - Get schema actions in a tree structure func (r *PermissionServer) Expand(ctx context.Context, request *v1.PermissionExpandRequest) (*v1.PermissionExpandResponse, error) { - ctx, span := tracer.Start(ctx, "permissions.expand") + ctx, span := internal.Tracer.Start(ctx, "permissions.expand") defer span.End() v := request.Validate() @@ -69,7 +70,7 @@ func (r *PermissionServer) Expand(ctx context.Context, request *v1.PermissionExp // LookupEntity - func (r *PermissionServer) LookupEntity(ctx context.Context, request *v1.PermissionLookupEntityRequest) (*v1.PermissionLookupEntityResponse, error) { - ctx, span := tracer.Start(ctx, "permissions.lookup-entity") + ctx, span := internal.Tracer.Start(ctx, "permissions.lookup-entity") defer span.End() v := request.Validate() @@ -90,7 +91,7 @@ func (r *PermissionServer) LookupEntity(ctx context.Context, request *v1.Permiss // LookupEntityStream - func (r *PermissionServer) LookupEntityStream(request *v1.PermissionLookupEntityRequest, server v1.Permission_LookupEntityStreamServer) error { - ctx, span := tracer.Start(server.Context(), "permissions.lookup-entity-stream") + ctx, span := internal.Tracer.Start(server.Context(), "permissions.lookup-entity-stream") defer span.End() v := request.Validate() @@ -111,7 +112,7 @@ func (r *PermissionServer) LookupEntityStream(request *v1.PermissionLookupEntity // LookupSubject - func (r *PermissionServer) LookupSubject(ctx context.Context, request *v1.PermissionLookupSubjectRequest) (*v1.PermissionLookupSubjectResponse, error) { - ctx, span := tracer.Start(ctx, "permissions.lookup-subject") + ctx, span := internal.Tracer.Start(ctx, "permissions.lookup-subject") defer span.End() v := request.Validate() @@ -132,7 +133,7 @@ func (r *PermissionServer) LookupSubject(ctx context.Context, request *v1.Permis // SubjectPermission - func (r *PermissionServer) SubjectPermission(ctx context.Context, request *v1.PermissionSubjectPermissionRequest) (*v1.PermissionSubjectPermissionResponse, error) { - ctx, span := tracer.Start(ctx, "permissions.subject-permission") + ctx, span := internal.Tracer.Start(ctx, "permissions.subject-permission") defer span.End() v := request.Validate() diff --git a/internal/servers/schemaServer.go b/internal/servers/schemaServer.go index a40a6d728..46a512965 100644 --- a/internal/servers/schemaServer.go +++ b/internal/servers/schemaServer.go @@ -12,6 +12,7 @@ import ( otelCodes "go.opentelemetry.io/otel/codes" "golang.org/x/net/context" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/pkg/database" "github.com/Permify/permify/pkg/dsl/compiler" @@ -36,15 +37,15 @@ func NewSchemaServer(sw storage.SchemaWriter, sr storage.SchemaReader) *SchemaSe return &SchemaServer{ sw: sw, sr: sr, - writeSchemaHistogram: telemetry.NewHistogram(meter, "write_schema", "microseconds", "Duration of writing schema in microseconds"), - readSchemaHistogram: telemetry.NewHistogram(meter, "read_schema", "microseconds", "Duration of reading schema in microseconds"), - listSchemaHistogram: telemetry.NewHistogram(meter, "list_schema", "microseconds", "Duration of listing schema in microseconds"), + writeSchemaHistogram: telemetry.NewHistogram(internal.Meter, "write_schema", "microseconds", "Duration of writing schema in microseconds"), + readSchemaHistogram: telemetry.NewHistogram(internal.Meter, "read_schema", "microseconds", "Duration of reading schema in microseconds"), + listSchemaHistogram: telemetry.NewHistogram(internal.Meter, "list_schema", "microseconds", "Duration of listing schema in microseconds"), } } // Write - Configure new Permify Schema to Permify func (r *SchemaServer) Write(ctx context.Context, request *v1.SchemaWriteRequest) (*v1.SchemaWriteResponse, error) { - ctx, span := tracer.Start(ctx, "schemas.write") + ctx, span := internal.Tracer.Start(ctx, "schemas.write") defer span.End() start := time.Now() @@ -93,7 +94,7 @@ func (r *SchemaServer) Write(ctx context.Context, request *v1.SchemaWriteRequest // PartialWrite applies incremental updates to the schema of a specific tenant based on the provided request. func (r *SchemaServer) PartialWrite(ctx context.Context, request *v1.SchemaPartialWriteRequest) (*v1.SchemaPartialWriteResponse, error) { // Start a new tracing span for monitoring and observability. - ctx, span := tracer.Start(ctx, "schemas.partial-write") + ctx, span := internal.Tracer.Start(ctx, "schemas.partial-write") defer span.End() // Ensure the span is closed at the end of the function. // Retrieve or default the schema version from the request. @@ -203,7 +204,7 @@ func (r *SchemaServer) PartialWrite(ctx context.Context, request *v1.SchemaParti // Read - Read created Schema func (r *SchemaServer) Read(ctx context.Context, request *v1.SchemaReadRequest) (*v1.SchemaReadResponse, error) { - ctx, span := tracer.Start(ctx, "schemas.read") + ctx, span := internal.Tracer.Start(ctx, "schemas.read") defer span.End() start := time.Now() @@ -234,7 +235,7 @@ func (r *SchemaServer) Read(ctx context.Context, request *v1.SchemaReadRequest) // List - List Schemas func (r *SchemaServer) List(ctx context.Context, request *v1.SchemaListRequest) (*v1.SchemaListResponse, error) { - ctx, span := tracer.Start(ctx, "schemas.list") + ctx, span := internal.Tracer.Start(ctx, "schemas.list") defer span.End() start := time.Now() diff --git a/internal/servers/server.go b/internal/servers/server.go index 5f84626d0..51ddc91ac 100644 --- a/internal/servers/server.go +++ b/internal/servers/server.go @@ -21,7 +21,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/rs/cors" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" - "go.opentelemetry.io/otel" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" @@ -38,11 +37,6 @@ import ( health "google.golang.org/grpc/health/grpc_health_v1" ) -var ( - tracer = otel.Tracer("servers") - meter = otel.Meter("servers") -) - // Container is a struct that holds the invoker and various storage // for permission-related operations. It serves as a central point of access // for interacting with the underlying data and services. diff --git a/internal/servers/tenancyServer.go b/internal/servers/tenancyServer.go index 4277df824..48deaaab5 100644 --- a/internal/servers/tenancyServer.go +++ b/internal/servers/tenancyServer.go @@ -7,6 +7,7 @@ import ( otelCodes "go.opentelemetry.io/otel/codes" "google.golang.org/grpc/status" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/pkg/database" v1 "github.com/Permify/permify/pkg/pb/base/v1" @@ -30,7 +31,7 @@ func NewTenancyServer(tr storage.TenantReader, tw storage.TenantWriter) *Tenancy // Create - Create new Tenant func (t *TenancyServer) Create(ctx context.Context, request *v1.TenantCreateRequest) (*v1.TenantCreateResponse, error) { - ctx, span := tracer.Start(ctx, "tenant.create") + ctx, span := internal.Tracer.Start(ctx, "tenant.create") defer span.End() tenant, err := t.tw.CreateTenant(ctx, request.GetId(), request.GetName()) @@ -48,7 +49,7 @@ func (t *TenancyServer) Create(ctx context.Context, request *v1.TenantCreateRequ // Delete - Delete a Tenant func (t *TenancyServer) Delete(ctx context.Context, request *v1.TenantDeleteRequest) (*v1.TenantDeleteResponse, error) { - ctx, span := tracer.Start(ctx, "tenant.delete") + ctx, span := internal.Tracer.Start(ctx, "tenant.delete") defer span.End() tenant, err := t.tw.DeleteTenant(ctx, request.GetId()) @@ -66,7 +67,7 @@ func (t *TenancyServer) Delete(ctx context.Context, request *v1.TenantDeleteRequ // List - List Tenants func (t *TenancyServer) List(ctx context.Context, request *v1.TenantListRequest) (*v1.TenantListResponse, error) { - ctx, span := tracer.Start(ctx, "tenant.list") + ctx, span := internal.Tracer.Start(ctx, "tenant.list") defer span.End() tenants, ct, err := t.tr.ListTenants(ctx, database.NewPagination(database.Size(request.GetPageSize()), database.Token(request.GetContinuousToken()))) diff --git a/internal/servers/watchServer.go b/internal/servers/watchServer.go index cbe373bb8..9766cd015 100644 --- a/internal/servers/watchServer.go +++ b/internal/servers/watchServer.go @@ -3,6 +3,7 @@ package servers import ( "google.golang.org/grpc/status" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" v1 "github.com/Permify/permify/pkg/pb/base/v1" ) @@ -27,7 +28,7 @@ func NewWatchServer( // Watch function sets up a stream for the client to receive changes. func (r *WatchServer) Watch(request *v1.WatchRequest, server v1.Watch_WatchServer) error { // Start a new context and span for tracing. - ctx, span := tracer.Start(server.Context(), "watch.watch") + ctx, span := internal.Tracer.Start(server.Context(), "watch.watch") defer span.End() // Ensure the span ends when the function returns. // Validate the incoming request. diff --git a/internal/storage/memory/tracer.go b/internal/storage/memory/tracer.go deleted file mode 100644 index 4b18881ad..000000000 --- a/internal/storage/memory/tracer.go +++ /dev/null @@ -1,7 +0,0 @@ -package memory - -import ( - "go.opentelemetry.io/otel" -) - -var tracer = otel.Tracer("storage.memory") diff --git a/internal/storage/postgres/bundleReader.go b/internal/storage/postgres/bundleReader.go index 2b98f68eb..7ab38d142 100644 --- a/internal/storage/postgres/bundleReader.go +++ b/internal/storage/postgres/bundleReader.go @@ -12,6 +12,7 @@ import ( "github.com/golang/protobuf/jsonpb" "go.opentelemetry.io/otel/codes" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage/postgres/utils" db "github.com/Permify/permify/pkg/database/postgres" base "github.com/Permify/permify/pkg/pb/base/v1" @@ -30,7 +31,7 @@ func NewBundleReader(database *db.Postgres) *BundleReader { } func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle *base.DataBundle, err error) { - ctx, span := tracer.Start(ctx, "bundle-reader.read-bundle") + ctx, span := internal.Tracer.Start(ctx, "bundle-reader.read-bundle") defer span.End() slog.DebugContext(ctx, "reading bundle", slog.Any("tenant_id", tenantID), slog.Any("name", name)) diff --git a/internal/storage/postgres/bundleWriter.go b/internal/storage/postgres/bundleWriter.go index 997ac749c..908c31975 100644 --- a/internal/storage/postgres/bundleWriter.go +++ b/internal/storage/postgres/bundleWriter.go @@ -9,6 +9,7 @@ import ( "github.com/Masterminds/squirrel" "github.com/golang/protobuf/jsonpb" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/storage/postgres/utils" db "github.com/Permify/permify/pkg/database/postgres" @@ -29,7 +30,7 @@ func NewBundleWriter(database *db.Postgres) *BundleWriter { } func (b *BundleWriter) Write(ctx context.Context, bundles []storage.Bundle) (names []string, err error) { - ctx, span := tracer.Start(ctx, "bundle-writer.write-bundle") + ctx, span := internal.Tracer.Start(ctx, "bundle-writer.write-bundle") defer span.End() slog.DebugContext(ctx, "writing bundles to the database", slog.Any("number_of_bundles", len(bundles))) @@ -72,7 +73,7 @@ func (b *BundleWriter) Write(ctx context.Context, bundles []storage.Bundle) (nam } func (b *BundleWriter) Delete(ctx context.Context, tenantID, name string) (err error) { - ctx, span := tracer.Start(ctx, "bundle-writer.delete-bundle") + ctx, span := internal.Tracer.Start(ctx, "bundle-writer.delete-bundle") defer span.End() slog.DebugContext(ctx, "deleting bundle", slog.Any("bundle", name)) diff --git a/internal/storage/postgres/dataReader.go b/internal/storage/postgres/dataReader.go index 0425d3dad..c7e83f98f 100644 --- a/internal/storage/postgres/dataReader.go +++ b/internal/storage/postgres/dataReader.go @@ -13,6 +13,7 @@ import ( "github.com/golang/protobuf/jsonpb" "google.golang.org/protobuf/types/known/anypb" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/storage/postgres/snapshot" "github.com/Permify/permify/internal/storage/postgres/types" @@ -42,7 +43,7 @@ func NewDataReader(database *db.Postgres) *DataReader { // QueryRelationships reads relation tuples from the storage based on the given filter. func (r *DataReader) QueryRelationships(ctx context.Context, tenantID string, filter *base.TupleFilter, snap string, pagination database.CursorPagination) (it *database.TupleIterator, err error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.query-relationships") + ctx, span := internal.Tracer.Start(ctx, "data-reader.query-relationships") defer span.End() slog.DebugContext(ctx, "querying relationships for tenant_id", slog.String("tenant_id", tenantID)) @@ -113,7 +114,7 @@ func (r *DataReader) QueryRelationships(ctx context.Context, tenantID string, fi // ReadRelationships reads relation tuples from the storage based on the given filter and pagination. func (r *DataReader) ReadRelationships(ctx context.Context, tenantID string, filter *base.TupleFilter, snap string, pagination database.Pagination) (collection *database.TupleCollection, ct database.EncodedContinuousToken, err error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.read-relationships") + ctx, span := internal.Tracer.Start(ctx, "data-reader.read-relationships") defer span.End() slog.DebugContext(ctx, "reading relationships for tenant_id", slog.String("tenant_id", tenantID)) @@ -200,7 +201,7 @@ func (r *DataReader) ReadRelationships(ctx context.Context, tenantID string, fil // QuerySingleAttribute retrieves a single attribute from the storage based on the given filter. func (r *DataReader) QuerySingleAttribute(ctx context.Context, tenantID string, filter *base.AttributeFilter, snap string) (attribute *base.Attribute, err error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.query-single-attribute") + ctx, span := internal.Tracer.Start(ctx, "data-reader.query-single-attribute") defer span.End() slog.DebugContext(ctx, "querying single attribute for tenant_id", slog.String("tenant_id", tenantID)) @@ -260,7 +261,7 @@ func (r *DataReader) QuerySingleAttribute(ctx context.Context, tenantID string, // QueryAttributes reads multiple attributes from the storage based on the given filter. func (r *DataReader) QueryAttributes(ctx context.Context, tenantID string, filter *base.AttributeFilter, snap string, pagination database.CursorPagination) (it *database.AttributeIterator, err error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.query-attributes") + ctx, span := internal.Tracer.Start(ctx, "data-reader.query-attributes") defer span.End() slog.DebugContext(ctx, "querying Attributes for tenant_id", slog.String("tenant_id", tenantID)) @@ -345,7 +346,7 @@ func (r *DataReader) QueryAttributes(ctx context.Context, tenantID string, filte // ReadAttributes reads multiple attributes from the storage based on the given filter and pagination. func (r *DataReader) ReadAttributes(ctx context.Context, tenantID string, filter *base.AttributeFilter, snap string, pagination database.Pagination) (collection *database.AttributeCollection, ct database.EncodedContinuousToken, err error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.read-attributes") + ctx, span := internal.Tracer.Start(ctx, "data-reader.read-attributes") defer span.End() slog.DebugContext(ctx, "reading attributes for tenant_id", slog.String("tenant_id", tenantID)) @@ -446,7 +447,7 @@ func (r *DataReader) ReadAttributes(ctx context.Context, tenantID string, filter // QueryUniqueSubjectReferences reads unique subject references from the storage based on the given filter and pagination. func (r *DataReader) QueryUniqueSubjectReferences(ctx context.Context, tenantID string, subjectReference *base.RelationReference, excluded []string, snap string, pagination database.Pagination) (ids []string, ct database.EncodedContinuousToken, err error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.query-unique-subject-reference") + ctx, span := internal.Tracer.Start(ctx, "data-reader.query-unique-subject-reference") defer span.End() slog.DebugContext(ctx, "querying unique subject references for tenant_id", slog.String("tenant_id", tenantID)) @@ -547,7 +548,7 @@ func (r *DataReader) QueryUniqueSubjectReferences(ctx context.Context, tenantID // HeadSnapshot retrieves the latest snapshot token associated with the tenant. func (r *DataReader) HeadSnapshot(ctx context.Context, tenantID string) (token.SnapToken, error) { // Start a new trace span and end it when the function exits. - ctx, span := tracer.Start(ctx, "data-reader.head-snapshot") + ctx, span := internal.Tracer.Start(ctx, "data-reader.head-snapshot") defer span.End() slog.DebugContext(ctx, "getting head snapshot for tenant_id", slog.String("tenant_id", tenantID)) diff --git a/internal/storage/postgres/dataWriter.go b/internal/storage/postgres/dataWriter.go index 2f32ac5e6..f8503ec6a 100644 --- a/internal/storage/postgres/dataWriter.go +++ b/internal/storage/postgres/dataWriter.go @@ -11,6 +11,7 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/jackc/pgx/v5/pgconn" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage/postgres/snapshot" "github.com/Permify/permify/internal/storage/postgres/types" "github.com/Permify/permify/internal/storage/postgres/utils" @@ -46,7 +47,7 @@ func (w *DataWriter) Write( attributeCollection *database.AttributeCollection, ) (token token.EncodedSnapToken, err error) { // Start a new tracing span for this operation. - ctx, span := tracer.Start(ctx, "data-writer.write") + ctx, span := internal.Tracer.Start(ctx, "data-writer.write") defer span.End() // Ensure that the span is ended when the function returns. // Log the start of a data write operation. @@ -91,7 +92,7 @@ func (w *DataWriter) Delete( attributeFilter *base.AttributeFilter, ) (token.EncodedSnapToken, error) { // Start a new tracing span for this delete operation. - ctx, span := tracer.Start(ctx, "data-writer.delete") + ctx, span := internal.Tracer.Start(ctx, "data-writer.delete") defer span.End() // Ensure that the span is ended when the function returns. // Log the start of a data deletion operation. @@ -131,7 +132,7 @@ func (w *DataWriter) RunBundle( b *base.DataBundle, ) (token.EncodedSnapToken, error) { // Start a new tracing span for this operation. - ctx, span := tracer.Start(ctx, "data-writer.run-bundle") + ctx, span := internal.Tracer.Start(ctx, "data-writer.run-bundle") defer span.End() // Ensure that the span is ended when the function returns. // Log the start of running a bundle operation. diff --git a/internal/storage/postgres/schemaReader.go b/internal/storage/postgres/schemaReader.go index cdcca4ca1..53452d09e 100644 --- a/internal/storage/postgres/schemaReader.go +++ b/internal/storage/postgres/schemaReader.go @@ -10,6 +10,7 @@ import ( "github.com/Masterminds/squirrel" "github.com/rs/xid" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/schema" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/storage/postgres/utils" @@ -35,7 +36,7 @@ func NewSchemaReader(database *db.Postgres) *SchemaReader { // ReadSchema returns the schema definition for a specific tenant and version as a structured object. func (r *SchemaReader) ReadSchema(ctx context.Context, tenantID, version string) (sch *base.SchemaDefinition, err error) { - ctx, span := tracer.Start(ctx, "schema-reader.read-schema") + ctx, span := internal.Tracer.Start(ctx, "schema-reader.read-schema") defer span.End() slog.DebugContext(ctx, "reading schema", slog.Any("tenant_id", tenantID), slog.Any("version", version)) @@ -84,7 +85,7 @@ func (r *SchemaReader) ReadSchema(ctx context.Context, tenantID, version string) // ReadSchemaString returns the schema definition for a specific tenant and version as a string. func (r *SchemaReader) ReadSchemaString(ctx context.Context, tenantID, version string) (definitions []string, err error) { - ctx, span := tracer.Start(ctx, "schema-reader.read-schema-string") + ctx, span := internal.Tracer.Start(ctx, "schema-reader.read-schema-string") defer span.End() slog.DebugContext(ctx, "reading schema", slog.Any("tenant_id", tenantID), slog.Any("version", version)) @@ -127,7 +128,7 @@ func (r *SchemaReader) ReadSchemaString(ctx context.Context, tenantID, version s // ReadEntityDefinition - Reads entity config from the repository. func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, version string) (definition *base.EntityDefinition, v string, err error) { - ctx, span := tracer.Start(ctx, "schema-reader.read-entity-definition") + ctx, span := internal.Tracer.Start(ctx, "schema-reader.read-entity-definition") defer span.End() slog.DebugContext(ctx, "reading entity definition", slog.Any("tenant_id", tenantID), slog.Any("version", version)) @@ -168,7 +169,7 @@ func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, // ReadRuleDefinition - Reads rule config from the repository. func (r *SchemaReader) ReadRuleDefinition(ctx context.Context, tenantID, name, version string) (definition *base.RuleDefinition, v string, err error) { - ctx, span := tracer.Start(ctx, "schema-reader.read-rule-definition") + ctx, span := internal.Tracer.Start(ctx, "schema-reader.read-rule-definition") defer span.End() slog.DebugContext(ctx, "reading rule definition", slog.Any("tenant_id", tenantID), slog.Any("name", name), slog.Any("version", version)) @@ -211,7 +212,7 @@ func (r *SchemaReader) ReadRuleDefinition(ctx context.Context, tenantID, name, v // HeadVersion - Finds the latest version of the schema. func (r *SchemaReader) HeadVersion(ctx context.Context, tenantID string) (version string, err error) { - ctx, span := tracer.Start(ctx, "schema-reader.head-version") + ctx, span := internal.Tracer.Start(ctx, "schema-reader.head-version") defer span.End() slog.DebugContext(ctx, "finding the latest version fo the schema for", slog.String("tenant_id", tenantID)) @@ -243,7 +244,7 @@ func (r *SchemaReader) HeadVersion(ctx context.Context, tenantID string) (versio // ListSchemas - List all Schemas func (r *SchemaReader) ListSchemas(ctx context.Context, tenantID string, pagination database.Pagination) (schemas []*base.SchemaList, ct database.EncodedContinuousToken, err error) { - ctx, span := tracer.Start(ctx, "tenant-reader.list-tenants") + ctx, span := internal.Tracer.Start(ctx, "tenant-reader.list-tenants") defer span.End() slog.DebugContext(ctx, "listing schemas with pagination", slog.Any("pagination", pagination)) diff --git a/internal/storage/postgres/schemaWriter.go b/internal/storage/postgres/schemaWriter.go index 97ea0c94f..1e0e0c26a 100644 --- a/internal/storage/postgres/schemaWriter.go +++ b/internal/storage/postgres/schemaWriter.go @@ -6,6 +6,7 @@ import ( "github.com/jackc/pgx/v5" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/storage/postgres/utils" db "github.com/Permify/permify/pkg/database/postgres" @@ -29,7 +30,7 @@ func NewSchemaWriter(database *db.Postgres) *SchemaWriter { // WriteSchema writes a schema to the database func (w *SchemaWriter) WriteSchema(ctx context.Context, schemas []storage.SchemaDefinition) (err error) { - ctx, span := tracer.Start(ctx, "schema-writer.write-schema") + ctx, span := internal.Tracer.Start(ctx, "schema-writer.write-schema") defer span.End() slog.DebugContext(ctx, "writing schemas to the database", slog.Any("number_of_schemas", len(schemas))) diff --git a/internal/storage/postgres/tenantReader.go b/internal/storage/postgres/tenantReader.go index 07739da59..12b7644ef 100644 --- a/internal/storage/postgres/tenantReader.go +++ b/internal/storage/postgres/tenantReader.go @@ -8,6 +8,7 @@ import ( "github.com/Masterminds/squirrel" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage" "github.com/Permify/permify/internal/storage/postgres/utils" "github.com/Permify/permify/pkg/database" @@ -31,7 +32,7 @@ func NewTenantReader(database *db.Postgres) *TenantReader { // ListTenants - Lists all Tenants func (r *TenantReader) ListTenants(ctx context.Context, pagination database.Pagination) (tenants []*base.Tenant, ct database.EncodedContinuousToken, err error) { - ctx, span := tracer.Start(ctx, "tenant-reader.list-tenants") + ctx, span := internal.Tracer.Start(ctx, "tenant-reader.list-tenants") defer span.End() slog.DebugContext(ctx, "listing tenants with pagination", slog.Any("pagination", pagination)) diff --git a/internal/storage/postgres/tenantWriter.go b/internal/storage/postgres/tenantWriter.go index 777785ef6..1dbf9093d 100644 --- a/internal/storage/postgres/tenantWriter.go +++ b/internal/storage/postgres/tenantWriter.go @@ -14,6 +14,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" + "github.com/Permify/permify/internal" "github.com/Permify/permify/internal/storage/postgres/utils" db "github.com/Permify/permify/pkg/database/postgres" base "github.com/Permify/permify/pkg/pb/base/v1" @@ -36,7 +37,7 @@ func NewTenantWriter(database *db.Postgres) *TenantWriter { // CreateTenant - Creates a new Tenant func (w *TenantWriter) CreateTenant(ctx context.Context, id, name string) (result *base.Tenant, err error) { - ctx, span := tracer.Start(ctx, "tenant-writer.create-tenant") + ctx, span := internal.Tracer.Start(ctx, "tenant-writer.create-tenant") defer span.End() slog.DebugContext(ctx, "creating new tenant", slog.Any("id", id), slog.Any("name", name)) @@ -64,7 +65,7 @@ func (w *TenantWriter) CreateTenant(ctx context.Context, id, name string) (resul // DeleteTenant - Deletes a Tenant func (w *TenantWriter) DeleteTenant(ctx context.Context, tenantID string) (result *base.Tenant, err error) { - ctx, span := tracer.Start(ctx, "tenant-writer.delete-tenant") + ctx, span := internal.Tracer.Start(ctx, "tenant-writer.delete-tenant") defer span.End() slog.DebugContext(ctx, "deleting tenant", slog.Any("tenant_id", tenantID)) diff --git a/internal/storage/postgres/tracer.go b/internal/storage/postgres/tracer.go deleted file mode 100644 index dc37f00ca..000000000 --- a/internal/storage/postgres/tracer.go +++ /dev/null @@ -1,7 +0,0 @@ -package postgres - -import ( - "go.opentelemetry.io/otel" -) - -var tracer = otel.Tracer("storage.postgres") From f011909bb7176b488e6dfb08658de0e83fa86875 Mon Sep 17 00:00:00 2001 From: Ufuk Date: Thu, 31 Oct 2024 17:14:45 +0300 Subject: [PATCH 2/2] chore: format --- internal/engines/check.go | 2 -- internal/engines/expand.go | 1 - internal/engines/subjectFilter.go | 1 - internal/storage/postgres/tenantWriter.go | 1 - pkg/cmd/serve.go | 1 - pkg/database/postgres/postgres.go | 1 - 6 files changed, 7 deletions(-) diff --git a/internal/engines/check.go b/internal/engines/check.go index c0ef88295..39e514843 100644 --- a/internal/engines/check.go +++ b/internal/engines/check.go @@ -276,7 +276,6 @@ func (engine *CheckEngine) checkDirectRelation(request *base.PermissionCheckRequ // TupleFilter helps in filtering out the relationships for a specific entity and a permission. var rit *database.TupleIterator rit, err = engine.dataReader.QueryRelationships(ctx, request.GetTenantId(), filter, request.GetMetadata().GetSnapToken(), database.NewCursorPagination()) - // If there's an error in querying, return a denied permission response along with the error. if err != nil { return denied(emptyResponseMetadata()), err @@ -466,7 +465,6 @@ func (engine *CheckEngine) checkDirectAttribute( // storageContext.NewContextualAttributes creates a new instance of ContextualAttributes based on the attributes // retrieved from the request context. val, err = storageContext.NewContextualAttributes(request.GetContext().GetAttributes()...).QuerySingleAttribute(filter) - // An error occurred while querying the single attribute, so we return a denied response with empty metadata // and the error. if err != nil { diff --git a/internal/engines/expand.go b/internal/engines/expand.go index ac85791ea..e68c4a7b7 100644 --- a/internal/engines/expand.go +++ b/internal/engines/expand.go @@ -487,7 +487,6 @@ func (engine *ExpandEngine) expandDirectAttribute( // Attempt to get the attribute using the defined filter. val, err = storageContext.NewContextualAttributes(request.GetContext().GetAttributes()...).QuerySingleAttribute(filter) - // If there's an error in getting the attribute, send a failure response through the channel and return from the function. if err != nil { expandChan <- expandFailResponse(err) diff --git a/internal/engines/subjectFilter.go b/internal/engines/subjectFilter.go index 16ebef2cb..e814807b6 100644 --- a/internal/engines/subjectFilter.go +++ b/internal/engines/subjectFilter.go @@ -248,7 +248,6 @@ func (engine *SubjectFilter) subjectFilterDirectAttribute( // storageContext.NewContextualAttributes creates a new instance of ContextualAttributes based on the attributes // retrieved from the request context. val, err = storageContext.NewContextualAttributes(request.GetContext().GetAttributes()...).QuerySingleAttribute(filter) - // An error occurred while querying the single attribute, so we return a denied response with empty metadata // and the error. if err != nil { diff --git a/internal/storage/postgres/tenantWriter.go b/internal/storage/postgres/tenantWriter.go index 1dbf9093d..4c82c4032 100644 --- a/internal/storage/postgres/tenantWriter.go +++ b/internal/storage/postgres/tenantWriter.go @@ -110,7 +110,6 @@ func (w *TenantWriter) DeleteTenant(ctx context.Context, tenantID string) (resul var name string var createdAt time.Time err = br.QueryRow().Scan(&name, &createdAt) - if err != nil { if totalDeleted > 0 { name = fmt.Sprintf("Affected rows: %d", totalDeleted) diff --git a/pkg/cmd/serve.go b/pkg/cmd/serve.go index e1513e509..7b6fc3da6 100644 --- a/pkg/cmd/serve.go +++ b/pkg/cmd/serve.go @@ -349,7 +349,6 @@ func serve() func(cmd *cobra.Command, args []string) error { headers, cfg.Meter.Protocol, ) - if err != nil { slog.Error(err.Error()) } diff --git a/pkg/database/postgres/postgres.go b/pkg/database/postgres/postgres.go index 7df0a0ec8..7cd4ff53d 100644 --- a/pkg/database/postgres/postgres.go +++ b/pkg/database/postgres/postgres.go @@ -248,7 +248,6 @@ func createPools(ctx context.Context, wConfig, rConfig *pgxpool.Config) (*pgxpoo } return nil }, retryPolicy) - // Handle errors from pinging if err != nil { writePool.Close()