From 2c48c36c0f88bceddbebcdf599760ccce2be36f5 Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Mon, 15 Jan 2024 18:02:00 +0300 Subject: [PATCH 1/4] refactor: update logging level and message format --- internal/storage/postgres/bundleReader.go | 6 +-- internal/storage/postgres/bundleWriter.go | 10 ++--- internal/storage/postgres/dataReader.go | 47 +++++++++++--------- internal/storage/postgres/dataWriter.go | 38 ++++++++--------- internal/storage/postgres/schemaReader.go | 29 +++++++------ internal/storage/postgres/schemaWriter.go | 6 +-- internal/storage/postgres/tenantReader.go | 10 ++--- internal/storage/postgres/tenantWriter.go | 8 ++-- internal/storage/postgres/utils/common.go | 4 +- internal/storage/postgres/watch.go | 52 +++++++++++------------ 10 files changed, 107 insertions(+), 103 deletions(-) diff --git a/internal/storage/postgres/bundleReader.go b/internal/storage/postgres/bundleReader.go index 0689bc3e8..e26c83560 100644 --- a/internal/storage/postgres/bundleReader.go +++ b/internal/storage/postgres/bundleReader.go @@ -32,7 +32,7 @@ func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle ctx, span := tracer.Start(ctx, "bundle-reader.read-bundle") defer span.End() - slog.Info("Reading bundle: ", slog.Any("tenant_id", tenantID), slog.Any("name", name)) + slog.Debug("reading bundle", slog.Any("tenant_id", tenantID), slog.Any("name", name)) builder := b.database.Builder.Select("payload").From(BundlesTable).Where(squirrel.Eq{"name": name, "tenant_id": tenantID}) @@ -44,7 +44,7 @@ func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args)) var row *sql.Row row = b.database.DB.QueryRowContext(ctx, query, args...) @@ -65,7 +65,7 @@ func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle span.RecordError(err) span.SetStatus(codes.Error, err.Error()) - slog.Error("Failed to convert the value to bundle: ", slog.Any("error", err)) + slog.Error("failed to convert the value to bundle", slog.Any("error", err)) return nil, errors.New(base.ErrorCode_ERROR_CODE_INVALID_ARGUMENT.String()) } diff --git a/internal/storage/postgres/bundleWriter.go b/internal/storage/postgres/bundleWriter.go index 8eb85e552..e0758418c 100644 --- a/internal/storage/postgres/bundleWriter.go +++ b/internal/storage/postgres/bundleWriter.go @@ -31,7 +31,7 @@ func (b *BundleWriter) Write(ctx context.Context, bundles []storage.Bundle) (nam ctx, span := tracer.Start(ctx, "bundle-writer.write-bundle") defer span.End() - slog.Info("Writing bundles to the database", slog.Any("number_of_bundles", len(bundles))) + slog.Debug("writing bundles to the database", slog.Any("number_of_bundles", len(bundles))) insertBuilder := b.database.Builder.Insert(BundlesTable). Columns("name, payload, tenant_id"). @@ -58,14 +58,14 @@ func (b *BundleWriter) Write(ctx context.Context, bundles []storage.Bundle) (nam return names, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL insert query: ", slog.Any("query", query), slog.Any("arguments", args)) + 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) } - slog.Info("Successfully wrote bundles to the database. ", slog.Any("number_of_bundles", len(bundles))) + slog.Debug("successfully wrote bundles to the database", slog.Any("number_of_bundles", len(bundles))) return } @@ -74,7 +74,7 @@ func (b *BundleWriter) Delete(ctx context.Context, tenantID, name string) (err e ctx, span := tracer.Start(ctx, "bundle-writer.delete-bundle") defer span.End() - slog.Info("Deleting bundle: ", slog.Any("bundle", name)) + slog.Debug("deleting bundle", slog.Any("bundle", name)) deleteBuilder := b.database.Builder.Delete(BundlesTable).Where(squirrel.Eq{"name": name, "tenant_id": tenantID}) @@ -91,7 +91,7 @@ func (b *BundleWriter) Delete(ctx context.Context, tenantID, name string) (err e return utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully deleted Bundle") + slog.Debug("bundle successfully deleted") return nil } diff --git a/internal/storage/postgres/dataReader.go b/internal/storage/postgres/dataReader.go index fc5960345..d15277f04 100644 --- a/internal/storage/postgres/dataReader.go +++ b/internal/storage/postgres/dataReader.go @@ -45,7 +45,7 @@ func (r *DataReader) QueryRelationships(ctx context.Context, tenantID string, fi ctx, span := tracer.Start(ctx, "data-reader.query-relationships") defer span.End() - slog.Info("Querying relationships for tenantID: ", slog.String("tenant_id", tenantID)) + slog.Debug("querying relationships for tenant_id", slog.String("tenant_id", tenantID)) // Decode the snapshot value. var st token.SnapToken @@ -78,7 +78,7 @@ func (r *DataReader) QueryRelationships(ctx context.Context, tenantID string, fi return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Generated SQL query: ", slog.String("query", query), "with args", slog.Any("arguments", args)) + slog.Debug("generated sql query", slog.String("query", query), "with args", slog.Any("arguments", args)) // Execute the SQL query and retrieve the result rows. var rows *sql.Rows @@ -108,7 +108,7 @@ func (r *DataReader) QueryRelationships(ctx context.Context, tenantID string, fi return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully retrieved relation tuples from the database.") + slog.Debug("successfully retrieved relation tuples from the database") // Return a TupleIterator created from the TupleCollection. return collection.CreateTupleIterator(), nil @@ -120,7 +120,7 @@ func (r *DataReader) ReadRelationships(ctx context.Context, tenantID string, fil ctx, span := tracer.Start(ctx, "data-reader.read-relationships") defer span.End() - slog.Info("Reading relationships for tenantID: ", slog.String("tenant_id", tenantID)) + slog.Debug("reading relationships for tenant_id", slog.String("tenant_id", tenantID)) // Decode the snapshot value. var st token.SnapToken @@ -170,7 +170,7 @@ func (r *DataReader) ReadRelationships(ctx context.Context, tenantID string, fil return nil, database.NewNoopContinuousToken().Encode(), utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Generated SQL query: ", slog.String("query", query), "with args", slog.Any("arguments", args)) + slog.Debug("generated sql query", slog.String("query", query), "with args", slog.Any("arguments", args)) // Execute the query and retrieve the rows. var rows *sql.Rows @@ -204,7 +204,7 @@ func (r *DataReader) ReadRelationships(ctx context.Context, tenantID string, fil return nil, nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully read relation tuples from database.") + slog.Debug("successfully read relation tuples from database") // Return the results and encoded continuous token for pagination. if len(tuples) > int(pagination.PageSize()) { @@ -219,7 +219,8 @@ func (r *DataReader) QuerySingleAttribute(ctx context.Context, tenantID string, // Start a new trace span and end it when the function exits. ctx, span := tracer.Start(ctx, "data-reader.query-single-attribute") defer span.End() - slog.Info("Querying single attribute for tenantID: ", slog.String("tenant_id", tenantID)) + + slog.Debug("querying single attribute for tenant_id", slog.String("tenant_id", tenantID)) // Decode the snapshot value. var st token.SnapToken @@ -252,7 +253,7 @@ func (r *DataReader) QuerySingleAttribute(ctx context.Context, tenantID string, return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Generated SQL query: ", slog.String("query", query), "with args", slog.Any("arguments", args)) + slog.Debug("generated sql query", slog.String("query", query), "with args", slog.Any("arguments", args)) row := tx.QueryRowContext(ctx, query, args...) @@ -285,7 +286,7 @@ func (r *DataReader) QuerySingleAttribute(ctx context.Context, tenantID string, return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully retrieved Single attribute from the database.") + slog.Debug("successfully retrieved Single attribute from the database") return rt.ToAttribute(), nil } @@ -296,7 +297,7 @@ func (r *DataReader) QueryAttributes(ctx context.Context, tenantID string, filte ctx, span := tracer.Start(ctx, "data-reader.query-attributes") defer span.End() - slog.Info("Querying Attributes for tenantID: ", slog.String("tenant_id", tenantID)) + slog.Debug("querying Attributes for tenant_id", slog.String("tenant_id", tenantID)) // Decode the snapshot value. var st token.SnapToken @@ -329,7 +330,7 @@ func (r *DataReader) QueryAttributes(ctx context.Context, tenantID string, filte return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Generated SQL query: ", slog.String("query", query), "with args", slog.Any("arguments", args)) + slog.Debug("generated sql query", slog.String("query", query), "with args", slog.Any("arguments", args)) // Execute the SQL query and retrieve the result rows. var rows *sql.Rows @@ -373,7 +374,7 @@ func (r *DataReader) QueryAttributes(ctx context.Context, tenantID string, filte return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully retrieved attributes tuples from the database.") + slog.Debug("successfully retrieved attributes tuples from the database") // Return a TupleIterator created from the TupleCollection. return collection.CreateAttributeIterator(), nil @@ -385,7 +386,7 @@ func (r *DataReader) ReadAttributes(ctx context.Context, tenantID string, filter ctx, span := tracer.Start(ctx, "data-reader.read-attributes") defer span.End() - slog.Info("Reading attributes for tenantID: ", slog.String("tenant_id", tenantID)) + slog.Debug("reading attributes for tenant_id", slog.String("tenant_id", tenantID)) // Decode the snapshot value. var st token.SnapToken @@ -435,7 +436,7 @@ func (r *DataReader) ReadAttributes(ctx context.Context, tenantID string, filter return nil, database.NewNoopContinuousToken().Encode(), utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Generated SQL query: ", slog.String("query", query), "with args", slog.Any("arguments", args)) + slog.Debug("generated sql query", slog.String("query", query), "with args", slog.Any("arguments", args)) // Execute the query and retrieve the rows. var rows *sql.Rows @@ -483,7 +484,7 @@ func (r *DataReader) ReadAttributes(ctx context.Context, tenantID string, filter return nil, nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully read attributes from the database.") + slog.Debug("successfully read attributes from the database") // Return the results and encoded continuous token for pagination. if len(attributes) > int(pagination.PageSize()) { @@ -499,6 +500,8 @@ func (r *DataReader) QueryUniqueEntities(ctx context.Context, tenantID, name, sn ctx, span := tracer.Start(ctx, "data-reader.query-unique-entities") defer span.End() + slog.Debug("querying unique entities for tenant_id", slog.String("tenant_id", tenantID)) + // Decode the snapshot value. var st token.SnapToken st, err = snapshot.EncodedToken{Value: snap}.Decode() @@ -538,6 +541,8 @@ func (r *DataReader) QueryUniqueEntities(ctx context.Context, tenantID, name, sn // Append ORDER BY and LIMIT clauses. query = fmt.Sprintf("%s ORDER BY id LIMIT %d", query, pagination.PageSize()+1) + slog.Debug("generated sql query", slog.String("query", query)) + // Execute the query and retrieve the rows. var rows *sql.Rows rows, err = tx.QueryContext(ctx, query) @@ -571,6 +576,8 @@ func (r *DataReader) QueryUniqueEntities(ctx context.Context, tenantID, name, sn return nil, nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } + slog.Debug("successfully retrieved unique entities from the database") + // Return the results and encoded continuous token for pagination. if len(entityIDs) > int(pagination.PageSize()) { return entityIDs[:pagination.PageSize()], utils.NewContinuousToken(strconv.FormatUint(lastID, 10)).Encode(), nil @@ -585,7 +592,7 @@ func (r *DataReader) QueryUniqueSubjectReferences(ctx context.Context, tenantID ctx, span := tracer.Start(ctx, "data-reader.query-unique-subject-reference") defer span.End() - slog.Info("Querying unique subject references for tenantID: ", slog.String("tenant_id", tenantID)) + slog.Debug("querying unique subject references for tenant_id", slog.String("tenant_id", tenantID)) // Decode the snapshot value. var st token.SnapToken @@ -639,7 +646,7 @@ func (r *DataReader) QueryUniqueSubjectReferences(ctx context.Context, tenantID return nil, database.NewNoopContinuousToken().Encode(), utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Generated SQL query: ", slog.String("query", query), "with args", slog.Any("arguments", args)) + slog.Debug("generated sql query", slog.String("query", query), "with args", slog.Any("arguments", args)) // Execute the query and retrieve the rows. var rows *sql.Rows @@ -672,7 +679,7 @@ func (r *DataReader) QueryUniqueSubjectReferences(ctx context.Context, tenantID return nil, nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully retrieved unique subject references from the database.") + slog.Debug("successfully retrieved unique subject references from the database") // Return the results and encoded continuous token for pagination. if len(subjectIDs) > int(pagination.PageSize()) { @@ -688,7 +695,7 @@ func (r *DataReader) HeadSnapshot(ctx context.Context, tenantID string) (token.S ctx, span := tracer.Start(ctx, "data-reader.head-snapshot") defer span.End() - slog.Info("Getting head snapshot for tenantID: ", slog.String("tenant_id", tenantID)) + slog.Debug("getting head snapshot for tenant_id", slog.String("tenant_id", tenantID)) var xid types.XID8 @@ -709,7 +716,7 @@ func (r *DataReader) HeadSnapshot(ctx context.Context, tenantID string) (token.S return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SCAN) } - slog.Info("Successfully retrieved latest snapshot token") + slog.Debug("successfully retrieved latest snapshot token") // Return the latest snapshot token associated with the tenant. return snapshot.Token{Value: xid}, nil diff --git a/internal/storage/postgres/dataWriter.go b/internal/storage/postgres/dataWriter.go index c591b6037..e36e2c53e 100644 --- a/internal/storage/postgres/dataWriter.go +++ b/internal/storage/postgres/dataWriter.go @@ -54,7 +54,7 @@ func (w *DataWriter) Write( defer span.End() // Ensure that the span is ended when the function returns. // Log the start of a data write operation. - slog.Info("Writing data to the database. TenantID: ", slog.String("tenant_id", tenantID), "Max Retries: ", slog.Any("max_retries", w.maxRetries)) + slog.Debug("writing data for tenant_id", slog.String("tenant_id", tenantID), "max retries", slog.Any("max_retries", w.maxRetries)) // Check if the total number of tuples and attributes exceeds the maximum allowed per write. if len(tupleCollection.GetTuples())+len(attributeCollection.GetAttributes()) > w.maxDataPerWrite { @@ -68,18 +68,18 @@ func (w *DataWriter) Write( if err != nil { // Check if the error is due to serialization, and if so, retry. if strings.Contains(err.Error(), "could not serialize") { - slog.Warn("Serialization error occurred. Retrying...", slog.String("tenant_id", tenantID), slog.Int("retry", i)) + slog.Warn("serialization error occurred", slog.String("tenant_id", tenantID), slog.Int("retry", i)) continue // Retry the operation. } // If the error is not serialization-related, handle it and return. return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_DATASTORE) } - // If the write is successful, return the token. + // If to write is successful, return the token. return tkn, err } // Log an error if the operation failed after reaching the maximum number of retries. - slog.Error("Failed to write data to the database. Max retries reached. Aborting operation. ", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) + slog.Error("max retries reached", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) // Return an error indicating that the maximum number of retries has been reached. return nil, errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()) @@ -98,7 +98,7 @@ func (w *DataWriter) Delete( defer span.End() // Ensure that the span is ended when the function returns. // Log the start of a data deletion operation. - slog.Info("Deleting data from the database. TenantID: ", slog.String("tenant_id", tenantID), "Max Retries: ", slog.Any("max_retries", w.maxRetries)) + slog.Debug("deleting data for tenant_id", slog.String("tenant_id", tenantID), "max retries", slog.Any("max_retries", w.maxRetries)) // Retry loop for handling transient errors like serialization issues. for i := 0; i <= w.maxRetries; i++ { @@ -107,7 +107,7 @@ func (w *DataWriter) Delete( if err != nil { // Check if the error is due to serialization, and if so, retry. if strings.Contains(err.Error(), "could not serialize") { - slog.Warn("Serialization error occurred. Retrying...", slog.String("tenant_id", tenantID), slog.Int("retry", i)) + slog.Warn("serialization error occurred", slog.String("tenant_id", tenantID), slog.Int("retry", i)) continue // Retry the operation. } // If the error is not serialization-related, handle it and return. @@ -118,7 +118,7 @@ func (w *DataWriter) Delete( } // Log an error if the operation failed after reaching the maximum number of retries. - slog.Error("Failed to delete data from the database. Max retries reached. Aborting operation. ", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) + slog.Debug("max retries reached", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) // Return an error indicating that the maximum number of retries has been reached. return nil, errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()) @@ -137,7 +137,7 @@ func (w *DataWriter) RunBundle( defer span.End() // Ensure that the span is ended when the function returns. // Log the start of running a bundle operation. - slog.Info("Running bundle from the database. TenantID: ", slog.String("tenant_id", tenantID), "Max Retries: ", slog.Any("max_retries", w.maxRetries)) + slog.Debug("running bundle for tenant_id", slog.String("tenant_id", tenantID), "max retries", slog.Any("max_retries", w.maxRetries)) // Retry loop for handling transient errors like serialization issues. for i := 0; i <= w.maxRetries; i++ { @@ -146,7 +146,7 @@ func (w *DataWriter) RunBundle( if err != nil { // Check if the error is due to serialization, and if so, retry. if strings.Contains(err.Error(), "could not serialize") { - slog.Warn("Serialization error occurred. Retrying...", slog.String("tenant_id", tenantID), slog.Int("retry", i)) + slog.Warn("Serialization error occurred", slog.String("tenant_id", tenantID), slog.Int("retry", i)) continue // Retry the operation. } // If the error is not serialization-related, handle it and return. @@ -157,7 +157,7 @@ func (w *DataWriter) RunBundle( } // Log an error if the operation failed after reaching the maximum number of retries. - slog.Error("Failed to run bundle from the database. Max retries reached. Aborting operation. ", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) + slog.Error("max retries reached", slog.Any("error", errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()))) // Return an error indicating that the maximum number of retries has been reached. return nil, errors.New(base.ErrorCode_ERROR_CODE_ERROR_MAX_RETRIES.String()) @@ -195,9 +195,9 @@ func (w *DataWriter) write( return nil, err } - slog.Debug("Retrieved transaction: ", slog.Any("transaction", transaction), "for tenant: ", slog.Any("tenant_id", tenantID)) + slog.Debug("retrieved transaction", slog.Any("transaction", transaction), "for tenant", slog.Any("tenant_id", tenantID)) - slog.Debug("Processing tuples and executing insert query. ") + slog.Debug("processing tuples and executing insert query") if len(tupleCollection.GetTuples()) > 0 { @@ -326,7 +326,7 @@ func (w *DataWriter) write( return nil, err } - slog.Info("Data successfully written to the database.") + slog.Debug("data successfully written to the database") return snapshot.NewToken(xid).Encode(), nil } @@ -363,9 +363,9 @@ func (w *DataWriter) delete( return nil, err } - slog.Debug("Retrieved transaction: ", slog.Any("transaction", transaction), "for tenant: ", slog.Any("tenant_id", tenantID)) + slog.Debug("retrieved transaction", slog.Any("transaction", transaction), "for tenant", slog.Any("tenant_id", tenantID)) - slog.Debug("Processing tuple and executing update query. ") + slog.Debug("processing tuple and executing update query") if !validation.IsTupleFilterEmpty(tupleFilter) { tbuilder := w.database.Builder.Update(RelationTuplesTable).Set("expired_tx_id", xid).Where(squirrel.Eq{"expired_tx_id": "0", "tenant_id": tenantID}) @@ -385,7 +385,7 @@ func (w *DataWriter) delete( } } - slog.Debug("Processing attribute and executing update query.") + slog.Debug("processing attribute and executing update query") if !validation.IsAttributeFilterEmpty(attributeFilter) { abuilder := w.database.Builder.Update(AttributesTable).Set("expired_tx_id", xid).Where(squirrel.Eq{"expired_tx_id": "0", "tenant_id": tenantID}) @@ -409,7 +409,7 @@ func (w *DataWriter) delete( return nil, err } - slog.Info("Data successfully deleted from the database.") + slog.Debug("data successfully deleted from the database") return snapshot.NewToken(xid).Encode(), nil } @@ -446,7 +446,7 @@ func (w *DataWriter) runBundle( return nil, err } - slog.Debug("Retrieved transaction: ", slog.Any("transaction", transaction), "for tenant: ", slog.Any("tenant_id", tenantID)) + slog.Debug("retrieved transaction", slog.Any("transaction", transaction), "for tenant", slog.Any("tenant_id", tenantID)) for _, op := range b.GetOperations() { tb, ab, err := bundle.Operation(arguments, op) @@ -476,7 +476,7 @@ func (w *DataWriter) runOperation( tb database.TupleBundle, ab database.AttributeBundle, ) (err error) { - slog.Debug("Processing bundles queries. ") + slog.Debug("processing bundles queries") if len(tb.Write.GetTuples()) > 0 { diff --git a/internal/storage/postgres/schemaReader.go b/internal/storage/postgres/schemaReader.go index 4a754c7c0..44c8c25c5 100644 --- a/internal/storage/postgres/schemaReader.go +++ b/internal/storage/postgres/schemaReader.go @@ -35,7 +35,7 @@ func (r *SchemaReader) ReadSchema(ctx context.Context, tenantID, version string) ctx, span := tracer.Start(ctx, "schema-reader.read-schema") defer span.End() - slog.Info("Reading schema: ", slog.Any("tenant_id", tenantID), slog.Any("version", version)) + slog.Debug("reading schema", slog.Any("tenant_id", tenantID), slog.Any("version", version)) builder := r.database.Builder.Select("name, serialized_definition, version").From(SchemaDefinitionTable).Where(squirrel.Eq{"version": version, "tenant_id": tenantID}) @@ -47,7 +47,7 @@ func (r *SchemaReader) ReadSchema(ctx context.Context, tenantID, version string) return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args)) var rows *sql.Rows rows, err = r.database.DB.QueryContext(ctx, query, args...) @@ -69,14 +69,14 @@ func (r *SchemaReader) ReadSchema(ctx context.Context, tenantID, version string) return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SCAN) } - slog.Info("Successfully retrieved", slog.Any("schema definitions", len(definitions))) + slog.Debug("successfully retrieved", slog.Any("schema definitions", len(definitions))) sch, err = schema.NewSchemaFromStringDefinitions(false, definitions...) if err != nil { return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_INTERNAL) } - slog.Info("Successfully created schema.") + slog.Debug("successfully created schema") return sch, err } @@ -86,7 +86,7 @@ func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, ctx, span := tracer.Start(ctx, "schema-reader.read-entity-definition") defer span.End() - slog.Info("Reading entity definition: ", slog.Any("tenant_id", tenantID), slog.Any("version", version)) + slog.Debug("reading entity definition", slog.Any("tenant_id", tenantID), slog.Any("version", version)) builder := r.database.Builder.Select("name, serialized_definition, version").Where(squirrel.Eq{"name": name, "version": version, "tenant_id": tenantID}).From(SchemaDefinitionTable).Limit(1) @@ -98,7 +98,7 @@ func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, return nil, "", utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args)) var def storage.SchemaDefinition row := r.database.DB.QueryRowContext(ctx, query, args...) @@ -121,7 +121,7 @@ func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, definition, err = schema.GetEntityByName(sch, name) - slog.Info("Successfully retrieved", slog.Any("schema definition", definition)) + slog.Debug("successfully retrieved", slog.Any("schema definition", definition)) return definition, def.Version, err } @@ -131,7 +131,7 @@ func (r *SchemaReader) ReadRuleDefinition(ctx context.Context, tenantID, name, v ctx, span := tracer.Start(ctx, "schema-reader.read-rule-definition") defer span.End() - slog.Info("Reading rule definition: ", slog.Any("tenant_id", tenantID), slog.Any("name", name), slog.Any("version", version)) + slog.Debug("reading rule definition", slog.Any("tenant_id", tenantID), slog.Any("name", name), slog.Any("version", version)) builder := r.database.Builder.Select("name, serialized_definition, version").Where(squirrel.Eq{"name": name, "version": version, "tenant_id": tenantID}).From(SchemaDefinitionTable).Limit(1) @@ -143,7 +143,7 @@ func (r *SchemaReader) ReadRuleDefinition(ctx context.Context, tenantID, name, v return nil, "", utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args)) var def storage.SchemaDefinition row := r.database.DB.QueryRowContext(ctx, query, args...) @@ -158,7 +158,7 @@ func (r *SchemaReader) ReadRuleDefinition(ctx context.Context, tenantID, name, v return nil, "", utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SCAN) } - slog.Info("Successfully retrieved rule definition for: ", slog.Any("name", name)) + slog.Debug("successfully retrieved rule definition for", slog.Any("name", name)) var sch *base.SchemaDefinition sch, err = schema.NewSchemaFromStringDefinitions(false, def.Serialized()) @@ -167,7 +167,8 @@ func (r *SchemaReader) ReadRuleDefinition(ctx context.Context, tenantID, name, v } definition, err = schema.GetRuleByName(sch, name) - slog.Info("Successfully created rule definition") + + slog.Debug("successfully created rule definition") return definition, def.Version, err } @@ -177,7 +178,7 @@ func (r *SchemaReader) HeadVersion(ctx context.Context, tenantID string) (versio ctx, span := tracer.Start(ctx, "schema-reader.head-version") defer span.End() - slog.Info("Finding the latest version fo the schema for: ", slog.String("tenant_id", tenantID)) + slog.Debug("finding the latest version fo the schema for", slog.String("tenant_id", tenantID)) var query string var args []interface{} @@ -188,7 +189,7 @@ func (r *SchemaReader) HeadVersion(ctx context.Context, tenantID string) (versio return "", utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args)) row := r.database.DB.QueryRowContext(ctx, query, args...) err = row.Scan(&version) @@ -199,7 +200,7 @@ func (r *SchemaReader) HeadVersion(ctx context.Context, tenantID string) (versio return "", utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SCAN) } - slog.Info("Successfully found the latest schema version: ", slog.Any("version", version)) + slog.Debug("successfully found the latest schema version", slog.Any("version", version)) return version, nil } diff --git a/internal/storage/postgres/schemaWriter.go b/internal/storage/postgres/schemaWriter.go index 866b53fc4..58bf25b26 100644 --- a/internal/storage/postgres/schemaWriter.go +++ b/internal/storage/postgres/schemaWriter.go @@ -31,7 +31,7 @@ func (w *SchemaWriter) WriteSchema(ctx context.Context, schemas []storage.Schema ctx, span := tracer.Start(ctx, "schema-writer.write-schema") defer span.End() - slog.Info("Writing schemas to the database", slog.Any("number_of_schemas", len(schemas))) + slog.Debug("writing schemas to the database", slog.Any("number_of_schemas", len(schemas))) insertBuilder := w.database.Builder.Insert(SchemaDefinitionTable).Columns("name, serialized_definition, version, tenant_id") @@ -47,14 +47,14 @@ func (w *SchemaWriter) WriteSchema(ctx context.Context, schemas []storage.Schema return utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL insert query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql insert query", slog.Any("query", query), slog.Any("arguments", args)) _, err = w.database.DB.ExecContext(ctx, query, args...) if err != nil { return utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully wrote schemas to the database. ", slog.Any("number_of_schemas", len(schemas))) + slog.Debug("successfully wrote schemas to the database", slog.Any("number_of_schemas", len(schemas))) return nil } diff --git a/internal/storage/postgres/tenantReader.go b/internal/storage/postgres/tenantReader.go index a97d4cdfd..9b190d0f9 100644 --- a/internal/storage/postgres/tenantReader.go +++ b/internal/storage/postgres/tenantReader.go @@ -33,7 +33,7 @@ func (r *TenantReader) ListTenants(ctx context.Context, pagination database.Pagi ctx, span := tracer.Start(ctx, "tenant-reader.list-tenants") defer span.End() - slog.Info("Listing tenants with pagination: ", slog.Any("pagination", pagination)) + slog.Debug("listing tenants with pagination", slog.Any("pagination", pagination)) builder := r.database.Builder.Select("id, name, created_at").From(TenantsTable) if pagination.Token() != "" { @@ -55,7 +55,7 @@ func (r *TenantReader) ListTenants(ctx context.Context, pagination database.Pagi return nil, nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) } - slog.Debug("Executing SQL query: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing sql query", slog.Any("query", query), slog.Any("arguments", args)) var rows *sql.Rows rows, err = r.database.DB.QueryContext(ctx, query, args...) @@ -79,15 +79,11 @@ func (r *TenantReader) ListTenants(ctx context.Context, pagination database.Pagi return nil, nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_INTERNAL) } - slog.Info("Successfully listed tenants. ", slog.Any("number_of_tenants", len(tenants))) + slog.Debug("successfully listed tenants", slog.Any("number_of_tenants", len(tenants))) if len(tenants) > int(pagination.PageSize()) { - - slog.Info("Returning tenants with a continuous token. ", slog.Any("page_size", pagination.PageSize())) return tenants[:pagination.PageSize()], utils.NewContinuousToken(lastID).Encode(), nil } - slog.Info("Returning all tenants with no continuous token.") - return tenants, database.NewNoopContinuousToken().Encode(), nil } diff --git a/internal/storage/postgres/tenantWriter.go b/internal/storage/postgres/tenantWriter.go index c56f96740..b76fa7a54 100644 --- a/internal/storage/postgres/tenantWriter.go +++ b/internal/storage/postgres/tenantWriter.go @@ -35,7 +35,7 @@ func (w *TenantWriter) CreateTenant(ctx context.Context, id, name string) (resul ctx, span := tracer.Start(ctx, "tenant-writer.create-tenant") defer span.End() - slog.Info("Creating new Tenant: ", slog.Any("id", id), slog.Any("name", name)) + slog.Debug("creating new tenant", slog.Any("id", id), slog.Any("name", name)) var createdAt time.Time @@ -49,7 +49,7 @@ func (w *TenantWriter) CreateTenant(ctx context.Context, id, name string) (resul return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully created Tenant", slog.Any("id", id), slog.Any("name", name), slog.Any("createdAt", createdAt)) + slog.Debug("successfully created Tenant", slog.Any("id", id), slog.Any("name", name), slog.Any("createdAt", createdAt)) return &base.Tenant{ Id: id, @@ -63,7 +63,7 @@ func (w *TenantWriter) DeleteTenant(ctx context.Context, tenantID string) (resul ctx, span := tracer.Start(ctx, "tenant-writer.delete-tenant") defer span.End() - slog.Info("Deleting Tenant: ", slog.Any("tenant_id", tenantID)) + slog.Debug("deleting tenant", slog.Any("tenant_id", tenantID)) var name string var createdAt time.Time @@ -74,7 +74,7 @@ func (w *TenantWriter) DeleteTenant(ctx context.Context, tenantID string) (resul return nil, utils.HandleError(span, err, base.ErrorCode_ERROR_CODE_EXECUTION) } - slog.Info("Successfully deleted Tenant") + slog.Debug("successfully deleted tenant") return &base.Tenant{ Id: tenantID, diff --git a/internal/storage/postgres/utils/common.go b/internal/storage/postgres/utils/common.go index 37d5ea351..ba704f6ba 100644 --- a/internal/storage/postgres/utils/common.go +++ b/internal/storage/postgres/utils/common.go @@ -128,10 +128,10 @@ func HandleError(span trace.Span, err error, errorCode base.ErrorCode) error { // Check if the error is context-related if IsContextRelatedError(err) { // Use debug level logging for context-related errors - slog.Debug("Context-related error encountered", slog.Any("error", err), slog.Any("errorCode", errorCode)) + slog.Debug("context-related error encountered", slog.Any("error", err), slog.Any("errorCode", errorCode)) } else { // Use error level logging for all other errors - slog.Error("Error encountered", slog.Any("error", err), slog.Any("errorCode", errorCode)) + slog.Error("error encountered", slog.Any("error", err), slog.Any("errorCode", errorCode)) } // Return a new standardized error with the provided error code diff --git a/internal/storage/postgres/watch.go b/internal/storage/postgres/watch.go index c7cea77f5..0759c6151 100644 --- a/internal/storage/postgres/watch.go +++ b/internal/storage/postgres/watch.go @@ -52,7 +52,7 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. changes := make(chan *base.DataChanges, w.bufferSize) errs := make(chan error, 1) - slog.Info("Watching for changes in the database. ", slog.Any("tenant_id", tenantID), slog.Any("snapshot", snap)) + slog.Debug("watching for changes in the database", slog.Any("tenant_id", tenantID), slog.Any("snapshot", snap)) // Decode the snapshot value. // The snapshot value represents a point in the history of the database. @@ -61,7 +61,7 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. // If there is an error in decoding the snapshot, send the error and return. errs <- err - slog.Error("Failed to decode snapshot.", slog.Any("error", err)) + slog.Error("failed to decode snapshot", slog.Any("error", err)) return changes, errs } @@ -82,7 +82,7 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. if err != nil { // If there is an error in getting recent transaction IDs, send the error and return. - slog.Error("Error getting recent transaction. ", slog.Any("error", err)) + slog.Error("error getting recent transaction", slog.Any("error", err)) errs <- err return @@ -95,7 +95,7 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. if err != nil { // If there is an error in getting the changes, send the error and return. - slog.Error("Failed to get changes for transaction. ", slog.Any("id", id), slog.Any("error", err)) + slog.Error("failed to get changes for transaction", slog.Any("id", id), slog.Any("error", err)) errs <- err return @@ -104,9 +104,9 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. // Send the changes, but respect the context cancellation. select { case changes <- updates: // Send updates to the changes channel. - slog.Info("Sent updates to the changes channel for transaction. ", slog.Any("id", id)) + slog.Debug("sent updates to the changes channel for transaction", slog.Any("id", id)) case <-ctx.Done(): // If the context is done, send an error and return. - slog.Error("Context canceled, stopping watch.") + slog.Error("context canceled, stopping watch") errs <- errors.New(base.ErrorCode_ERROR_CODE_CANCELLED.String()) return } @@ -121,9 +121,9 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. select { case <-sleep.C: // If the timer is done, continue the loop. - slog.Info("No recent transaction IDs, waiting for changes...") + slog.Debug("no recent transaction IDs, waiting for changes") case <-ctx.Done(): // If the context is done, send an error and return. - slog.Error("Context canceled, stopping watch.") + slog.Error("context canceled, stopping watch") errs <- errors.New(base.ErrorCode_ERROR_CODE_CANCELLED.String()) return } @@ -131,7 +131,7 @@ func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base. } }() - slog.Info("Watch started successfully.") + slog.Debug("watch started successfully") // Return the channels that the caller will listen to for changes and errors. return changes, errs @@ -167,18 +167,18 @@ func (w *Watch) getRecentXIDs(ctx context.Context, value uint64, tenantID string query, args, err := builder.ToSql() if err != nil { - slog.Error("Error while building SQL query. ", slog.Any("error", err)) + slog.Error("error while building sql query", slog.Any("error", err)) return nil, err } - slog.Debug("Executing SQL query to get recent transaction: ", slog.Any("query", query), slog.Any("arguments", args)) + slog.Debug("executing SQL query to get recent transaction", slog.Any("query", query), slog.Any("arguments", args)) // Execute the SQL query. rows, err := w.database.DB.QueryContext(ctx, query, args...) if err != nil { - slog.Error("Failed to execute SQL query. ", slog.Any("error", err)) + slog.Error("failed to execute sql query", slog.Any("error", err)) return nil, err } @@ -191,7 +191,7 @@ func (w *Watch) getRecentXIDs(ctx context.Context, value uint64, tenantID string err := rows.Scan(&xid) if err != nil { - slog.Error("Error while scanning row. ", slog.Any("error", err)) + slog.Error("error while scanning row", slog.Any("error", err)) return nil, err } @@ -202,12 +202,12 @@ func (w *Watch) getRecentXIDs(ctx context.Context, value uint64, tenantID string err = rows.Err() if err != nil { - slog.Error("Failed to iterate over rows. ", slog.Any("error", err)) + slog.Error("failed to iterate over rows", slog.Any("error", err)) return nil, err } - slog.Info("Successfully retrieved recent transaction. ", slog.Any("ids", xids)) + slog.Debug("successfully retrieved recent transaction", slog.Any("ids", xids)) return xids, nil } @@ -223,7 +223,7 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin // Initialize a new TupleChanges instance. changes := &base.DataChanges{} - slog.Info("Retrieving changes for transaction. ", slog.Any("id", value), slog.Any("tenant_id", tenantID)) + slog.Debug("retrieving changes for transaction", slog.Any("id", value), slog.Any("tenant_id", tenantID)) // Construct the SQL SELECT statement for retrieving the changes from the RelationTuplesTable. tbuilder := w.database.Builder.Select("entity_type, entity_id, relation, subject_type, subject_id, subject_relation, expired_tx_id"). @@ -236,17 +236,17 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin // Generate the SQL query and arguments. tquery, targs, err := tbuilder.ToSql() if err != nil { - slog.Error("Error while building SQL query for relation tuples", slog.Any("error", err)) + slog.Error("error while building sql query for relation tuples", slog.Any("error", err)) return nil, err } - slog.Debug("Executing SQL query for relation tuples. ", slog.Any("query", tquery), slog.Any("arguments", targs)) + slog.Debug("executing sql query for relation tuples", slog.Any("query", tquery), slog.Any("arguments", targs)) // Execute the SQL query and retrieve the result rows. var trows *sql.Rows trows, err = w.database.DB.QueryContext(ctx, tquery, targs...) if err != nil { - slog.Error("Failed to execute SQL query for relation tuples. ", slog.Any("error", err)) + slog.Error("failed to execute sql query for relation tuples", slog.Any("error", err)) return nil, errors.New(base.ErrorCode_ERROR_CODE_EXECUTION.String()) } // Ensure the rows are closed after processing. @@ -261,16 +261,16 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin aquery, aargs, err := abuilder.ToSql() if err != nil { - slog.Error("Error while building SQL query for attributes. ", slog.Any("error", err)) + slog.Error("error while building SQL query for attributes", slog.Any("error", err)) return nil, err } - slog.Debug("Executing SQL query for attributes. ", slog.Any("query", aquery), slog.Any("arguments", aargs)) + slog.Debug("executing sql query for attributes", slog.Any("query", aquery), slog.Any("arguments", aargs)) var arows *sql.Rows arows, err = w.database.DB.QueryContext(ctx, aquery, aargs...) if err != nil { - slog.Error("Error while executing SQL query for attributes. ", slog.Any("error", err)) + slog.Error("error while executing SQL query for attributes", slog.Any("error", err)) return nil, errors.New(base.ErrorCode_ERROR_CODE_EXECUTION.String()) } // Ensure the rows are closed after processing. @@ -287,7 +287,7 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin // Scan the result row into a RelationTuple instance. err = trows.Scan(&rt.EntityType, &rt.EntityID, &rt.Relation, &rt.SubjectType, &rt.SubjectID, &rt.SubjectRelation, &expiredXID) if err != nil { - slog.Error("Error while scanning row for relation tuples. ", slog.Any("error", err)) + slog.Error("error while scanning row for relation tuples", slog.Any("error", err)) return nil, err } @@ -317,7 +317,7 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin // Scan the result row into a RelationTuple instance. err = arows.Scan(&rt.EntityType, &rt.EntityID, &rt.Attribute, &valueStr, &expiredXID) if err != nil { - slog.Error("Error while scanning row for attributes", slog.Any("error", err)) + slog.Error("error while scanning row for attributes", slog.Any("error", err)) return nil, err } @@ -326,7 +326,7 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin unmarshaler := &jsonpb.Unmarshaler{} err = unmarshaler.Unmarshal(strings.NewReader(valueStr), rt.Value) if err != nil { - slog.Error("Failed to unmarshal attribute value", slog.Any("error", err)) + slog.Error("failed to unmarshal attribute value", slog.Any("error", err)) return nil, err } @@ -345,7 +345,7 @@ func (w *Watch) getChanges(ctx context.Context, value types.XID8, tenantID strin }) } - slog.Info("Successfully retrieved changes for transaction. ", slog.Any("id", value)) + slog.Debug("successfully retrieved changes for transaction", slog.Any("id", value)) // Return the changes and no error. return changes, nil From 2ed2d6438067a1740cdac6cc2f92f34ebbe893ab Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Mon, 15 Jan 2024 18:02:25 +0300 Subject: [PATCH 2/4] build: version info update --- docs/apidocs.swagger.json | 2 +- internal/info.go | 2 +- pkg/pb/base/v1/openapi.pb.go | 2 +- proto/base/v1/openapi.proto | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/apidocs.swagger.json b/docs/apidocs.swagger.json index 5a63aefc3..de57ef2d9 100644 --- a/docs/apidocs.swagger.json +++ b/docs/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.6.9", + "version": "v0.7.0", "contact": { "name": "API Support", "url": "https://github.com/Permify/permify/issues", diff --git a/internal/info.go b/internal/info.go index 0f7d82c64..a08ebde35 100644 --- a/internal/info.go +++ b/internal/info.go @@ -16,7 +16,7 @@ var Identifier = "" */ const ( // Version is the last release of the Permify (e.g. v0.1.0) - Version = "v0.6.9" + Version = "v0.7.0" // Banner is the view for terminal. Banner = ` diff --git a/pkg/pb/base/v1/openapi.pb.go b/pkg/pb/base/v1/openapi.pb.go index 1a7d10e54..59fae14a7 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, 0x36, 0x2e, 0x39, 0x2a, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, + 0x32, 0x06, 0x76, 0x30, 0x2e, 0x37, 0x2e, 0x30, 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/openapi.proto b/proto/base/v1/openapi.proto index d9d8fad30..ed45a6d5e 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.6.9"; + version: "v0.7.0"; contact: { name: "API Support"; url: "https://github.com/Permify/permify/issues"; From eff5d4236f81d2d64963139405281e00ba91f52a Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Mon, 15 Jan 2024 18:09:57 +0300 Subject: [PATCH 3/4] refactor: extend NotFound error handling for code ranges 3999-4999 --- internal/servers/error.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/servers/error.go b/internal/servers/error.go index 99f97ec63..bc9baa5d4 100644 --- a/internal/servers/error.go +++ b/internal/servers/error.go @@ -25,9 +25,9 @@ func GetStatus(err error) codes.Code { return codes.Unauthenticated case code > 1999 && code < 2999: return codes.InvalidArgument - case code > 2999 && code < 3999: - return codes.NotFound case code > 3999 && code < 4999: + return codes.NotFound + case code > 4999 && code < 5999: return codes.Internal default: return codes.Internal From 83c3a0ae643c08d93dc89487c46a0f5b8212d4c9 Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Mon, 15 Jan 2024 18:11:38 +0300 Subject: [PATCH 4/4] feat: add unary and stream server interceptors to logging configuration --- internal/servers/server.go | 16 ++++++++++++++++ pkg/cmd/serve.go | 1 + 2 files changed, 17 insertions(+) diff --git a/internal/servers/server.go b/internal/servers/server.go index 4f40854a9..b01982ea8 100644 --- a/internal/servers/server.go +++ b/internal/servers/server.go @@ -10,6 +10,8 @@ import ( "net/http/pprof" "time" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit" grpcAuth "github.com/grpc-ecosystem/go-grpc-middleware/auth" @@ -100,6 +102,7 @@ func NewContainer( func (s *Container) Run( ctx context.Context, srv *config.Server, + logger *slog.Logger, dst *config.Distributed, authentication *config.Authn, profiler *config.Profiler, @@ -109,16 +112,22 @@ func (s *Container) Run( limiter := middleware.NewRateLimiter(srv.RateLimit) // for example 1000 req/sec + lopts := []logging.Option{ + logging.WithLogOnEvents(logging.StartCall, logging.FinishCall), + } + unaryInterceptors := []grpc.UnaryServerInterceptor{ grpcValidator.UnaryServerInterceptor(), grpcRecovery.UnaryServerInterceptor(), ratelimit.UnaryServerInterceptor(limiter), + logging.UnaryServerInterceptor(InterceptorLogger(logger), lopts...), } streamingInterceptors := []grpc.StreamServerInterceptor{ grpcValidator.StreamServerInterceptor(), grpcRecovery.StreamServerInterceptor(), ratelimit.StreamServerInterceptor(limiter), + logging.StreamServerInterceptor(InterceptorLogger(logger), lopts...), } // Configure authentication based on the provided method ("preshared" or "oidc"). @@ -364,3 +373,10 @@ func (s *Container) Run( return nil } + +// InterceptorLogger adapts slog logger to interceptor logger. +func InterceptorLogger(l *slog.Logger) logging.Logger { + return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) { + l.Log(ctx, slog.Level(lvl), msg, fields...) + }) +} diff --git a/pkg/cmd/serve.go b/pkg/cmd/serve.go index eec157bbb..462b506b5 100644 --- a/pkg/cmd/serve.go +++ b/pkg/cmd/serve.go @@ -374,6 +374,7 @@ func serve() func(cmd *cobra.Command, args []string) error { return container.Run( ctx, &cfg.Server, + logger, &cfg.Distributed, &cfg.Authn, &cfg.Profiler,