Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace usages of golang.org/x/exp with stdlib #1828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ require (
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/sdk/metric v1.32.0
go.opentelemetry.io/otel/trace v1.32.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/net v0.31.0
golang.org/x/sync v0.9.0
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697
Expand Down Expand Up @@ -104,6 +103,7 @@ require (
github.com/shirou/gopsutil/v4 v4.24.10 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/api v0.203.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions internal/engines/subjectFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"
"sync"

"github.com/google/cel-go/cel"

"golang.org/x/exp/slices"

"github.com/Permify/permify/internal/schema"
"github.com/Permify/permify/internal/storage"
storageContext "github.com/Permify/permify/internal/storage/context"
Expand Down
3 changes: 1 addition & 2 deletions internal/engines/subjectPermission.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package engines
import (
"context"
"errors"
"slices"
"sync"

"golang.org/x/exp/slices"

"github.com/Permify/permify/internal/invoke"
"github.com/Permify/permify/internal/storage"
base "github.com/Permify/permify/pkg/pb/base/v1"
Expand Down
3 changes: 1 addition & 2 deletions internal/storage/context/attributes.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package context

import (
"slices"
"sort"

"golang.org/x/exp/slices"

"github.com/Permify/permify/internal/storage/context/utils"
"github.com/Permify/permify/pkg/database"
base "github.com/Permify/permify/pkg/pb/base/v1"
Expand Down
3 changes: 1 addition & 2 deletions internal/storage/context/tuples.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package context

import (
"slices"
"sort"

"golang.org/x/exp/slices"

"github.com/Permify/permify/internal/storage/context/utils"
"github.com/Permify/permify/pkg/database"
base "github.com/Permify/permify/pkg/pb/base/v1"
Expand Down
3 changes: 1 addition & 2 deletions internal/storage/context/tuples_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package context

import (
"slices"
"testing"

"golang.org/x/exp/slices"

"github.com/Permify/permify/pkg/database"
base "github.com/Permify/permify/pkg/pb/base/v1"
"github.com/Permify/permify/pkg/tuple"
Expand Down
3 changes: 1 addition & 2 deletions internal/storage/memory/dataReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package memory
import (
"context"
"errors"
"slices"
"sort"
"strconv"
"time"

"golang.org/x/exp/slices"

"github.com/hashicorp/go-memdb"

"github.com/Permify/permify/internal/storage/memory/constants"
Expand Down
3 changes: 2 additions & 1 deletion internal/storage/memory/utils/filter.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package utils

import (
"slices"

"github.com/hashicorp/go-memdb"
"golang.org/x/exp/slices"

"github.com/Permify/permify/internal/storage"
base "github.com/Permify/permify/pkg/pb/base/v1"
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/postgres/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"
"log/slog"
"math"
"math/rand/v2"
"strings"
"time"

"go.opentelemetry.io/otel/codes"
"golang.org/x/exp/rand"

"go.opentelemetry.io/otel/trace"

Expand Down
3 changes: 1 addition & 2 deletions pkg/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package postgres
import (
"context"
"fmt"
"log/slog"
Copy link

@coderabbitai coderabbitai bot Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct the usage of logging methods in log/slog.

The standard library log/slog package does not have slog.Warn and slog.Info methods directly. Instead, logging at different levels should use a slog.Logger instance or slog.Log with the appropriate slog.Level.

Apply this diff to fix the logging statements:

 func setDefaultQueryExecMode(config *pgx.ConnConfig) {
     // Default mode if no specific mode is found in the connection string
     defaultMode := "cache_statement"

     // Iterate through the map keys to check if any are mentioned in the connection string
     for key := range queryExecModes {
         if strings.Contains(config.ConnString(), "default_query_exec_mode="+key) {
             config.DefaultQueryExecMode = queryExecModes[key]
-            slog.Info("setDefaultQueryExecMode", slog.String("mode", key))
+            slog.Log(context.Background(), slog.LevelInfo, "setDefaultQueryExecMode", slog.String("mode", key))
             return
         }
     }

     // Set to default mode if no matching mode is found
     config.DefaultQueryExecMode = queryExecModes[defaultMode]
-    slog.Warn("setDefaultQueryExecMode", slog.String("mode", defaultMode))
+    slog.Log(context.Background(), slog.LevelWarn, "setDefaultQueryExecMode", slog.String("mode", defaultMode))
 }

 func setPlanCacheMode(config *pgx.ConnConfig) {
     // Default plan cache mode
     const defaultMode = "auto"

     // Extract connection string
     connStr := config.ConnString()
     planCacheMode := defaultMode

     // Check for specific plan cache modes in the connection string
     for key, value := range planCacheModes {
         if strings.Contains(connStr, "plan_cache_mode="+key) {
             if key == "disable" {
                 delete(config.Config.RuntimeParams, "plan_cache_mode")
-                slog.Info("setPlanCacheMode", slog.String("mode", "disabled"))
+                slog.Log(context.Background(), slog.LevelInfo, "setPlanCacheMode", slog.String("mode", "disabled"))
                 return
             }
             planCacheMode = value
-            slog.Info("setPlanCacheMode", slog.String("mode", key))
+            slog.Log(context.Background(), slog.LevelInfo, "setPlanCacheMode", slog.String("mode", key))
             break
         }
     }

     // Set the plan cache mode
     config.Config.RuntimeParams["plan_cache_mode"] = planCacheMode
     if planCacheMode == defaultMode {
-        slog.Warn("setPlanCacheMode", slog.String("mode", defaultMode))
+        slog.Log(context.Background(), slog.LevelWarn, "setPlanCacheMode", slog.String("mode", defaultMode))
     }
 }

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log/slog package does have slog.Warn and slog.Info.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Juneezee, thank you for the correction. You are absolutely right; the log/slog package does have slog.Warn and slog.Info methods. I apologize for the confusion.


✏️ Learnings added
Learnt from: Juneezee
PR: Permify/permify#1828
File: pkg/database/postgres/postgres.go:6-6
Timestamp: 2024-12-06T17:47:06.068Z
Learning: The standard library `log/slog` package provides the `slog.Warn` and `slog.Info` methods.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

"strings"
"time"

"github.com/cenkalti/backoff/v4"

"github.com/exaring/otelpgx"

"golang.org/x/exp/slog"

"github.com/jackc/pgx/v5"

"github.com/jackc/pgx/v5/pgxpool"
Expand Down
3 changes: 1 addition & 2 deletions pkg/development/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package coverage

import (
"fmt"

"golang.org/x/exp/slices"
"slices"

"github.com/Permify/permify/pkg/attribute"
"github.com/Permify/permify/pkg/development/file"
Expand Down
3 changes: 1 addition & 2 deletions pkg/tuple/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package tuple
import (
"errors"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"

base "github.com/Permify/permify/pkg/pb/base/v1"
)

Expand Down
Loading