Skip to content

Commit

Permalink
chore: cleanup grpc init and add redis name
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldziher committed Nov 27, 2023
1 parent 59ca7b4 commit 8ed295c
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 37 deletions.
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Expand Down
16 changes: 0 additions & 16 deletions services/api-gateway/internal/connectors/connectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/basemind-ai/monorepo/shared/go/db/models"
"github.com/basemind-ai/monorepo/shared/go/testutils"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"testing"
)

Expand All @@ -19,24 +17,11 @@ func TestGetOpenAIConnectorClientPanicsWithoutAddress(t *testing.T) {
assert.Panics(t, func() { connectors.GetProviderConnector(models.ModelVendorOPENAI) })
})

t.Run("panics when transport security is not set", func(t *testing.T) {
t.Setenv("OPENAI_CONNECTOR_ADDRESS", "localhost:50051")

assert.Panics(t, func() {
connectors.Init(
context.TODO(),
)

connectors.GetProviderConnector(models.ModelVendorOPENAI)
})
})

t.Run("does not panic when initialized", func(t *testing.T) {
t.Setenv("OPENAI_CONNECTOR_ADDRESS", "localhost:50051")

connectors.Init(
context.TODO(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
assert.NotPanics(
t,
Expand All @@ -49,7 +34,6 @@ func TestGetOpenAIConnectorClientPanicsWithoutAddress(t *testing.T) {

connectors.Init(
context.TODO(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)

assert.Panics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/basemind-ai/monorepo/services/api-gateway/internal/connectors/openai"
"github.com/basemind-ai/monorepo/shared/go/testutils"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net"
"testing"
)
Expand All @@ -27,7 +26,6 @@ func CreateClientAndService(t *testing.T) (*openai.Client, *testutils.MockOpenAI
)
client := openai.New(
"",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(
func(context.Context, string) (net.Conn, error) {
return listener.Dial()
Expand Down
2 changes: 0 additions & 2 deletions services/api-gateway/internal/services/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/go-redis/redismock/v9"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"io"
"net"
Expand Down Expand Up @@ -47,7 +46,6 @@ func createOpenAIService(t *testing.T) *testutils.MockOpenAIService {
t.Setenv("OPENAI_CONNECTOR_ADDRESS", "")

connectors.Init(context.TODO(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(
func(context.Context, string) (net.Conn, error) {
return listener.Dial()
Expand Down
3 changes: 1 addition & 2 deletions services/api-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/rs/zerolog/log"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net"
"os"
"os/signal"
Expand All @@ -38,7 +37,7 @@ func main() {
logging.Configure(cfg.Environment != "production")

// FIXME: this is a temporary work-around for testing
connectors.Init(ctx, grpc.WithTransportCredentials(insecure.NewCredentials()))
connectors.Init(ctx)

rediscache.New(cfg.RedisURL)

Expand Down
2 changes: 0 additions & 2 deletions services/dashboard-backend/internal/api/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -91,7 +90,6 @@ func createMockGRPCServer(
)
client := ptestingclient.New(
"",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(
func(context.Context, string) (net.Conn, error) {
return listener.Dial()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net"
"testing"
)
Expand All @@ -37,7 +36,6 @@ func createClientAndService(
)
client := ptestingclient.New(
"",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(
func(context.Context, string) (net.Conn, error) {
return listener.Dial()
Expand Down Expand Up @@ -92,7 +90,6 @@ func TestPromptTestingGRPCClient(t *testing.T) {
t.Run("dials and returns client", func(t *testing.T) {
client := ptestingclient.New(
"localhost:50051",
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
assert.NotNil(t, client)
})
Expand All @@ -104,7 +101,6 @@ func TestPromptTestingGRPCClient(t *testing.T) {
func() {
ptestingclient.Init(
context.Background(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
},
)
Expand All @@ -115,7 +111,6 @@ func TestPromptTestingGRPCClient(t *testing.T) {
func() {
ptestingclient.Init(
context.Background(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
},
)
Expand All @@ -127,7 +122,6 @@ func TestPromptTestingGRPCClient(t *testing.T) {
t.Setenv("API_GATEWAY_ADDRESS", "localhost:50051")
ptestingclient.Init(
context.Background(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
assert.NotPanics(t, func() {
ptestingclient.GetClient()
Expand Down
6 changes: 0 additions & 6 deletions services/dashboard-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import (
"fmt"
"github.com/basemind-ai/monorepo/services/dashboard-backend/internal/api"
"github.com/basemind-ai/monorepo/services/dashboard-backend/internal/middleware"
"github.com/basemind-ai/monorepo/services/dashboard-backend/internal/ptestingclient"
"github.com/basemind-ai/monorepo/shared/go/config"
"github.com/basemind-ai/monorepo/shared/go/db"
"github.com/basemind-ai/monorepo/shared/go/logging"
"github.com/basemind-ai/monorepo/shared/go/rediscache"
"github.com/basemind-ai/monorepo/shared/go/router"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -40,9 +37,6 @@ func main() {

logging.Configure(cfg.Environment != "production")

// FIXME: this is a temporary work-around for testing
ptestingclient.Init(ctx, grpc.WithTransportCredentials(insecure.NewCredentials()))

rediscache.New(cfg.RedisURL)

conn, connErr := db.CreateConnection(ctx, cfg.DatabaseURL)
Expand Down
3 changes: 3 additions & 0 deletions shared/go/rediscache/rediscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/basemind-ai/monorepo/shared/go/exc"
"github.com/go-redis/cache/v9"
"github.com/redis/go-redis/v9"
"os"
"sync"
"time"
)
Expand All @@ -25,6 +26,8 @@ func SetClient(c *cache.Cache) {
func New(redisURL string) *cache.Cache {
once.Do(func() {
opt := exc.MustResult(redis.ParseURL(redisURL))

opt.ClientName = os.Getenv("SERVICE_NAME")
SetClient(cache.New(&cache.Options{
Redis: redis.NewClient(opt),
LocalCache: cache.NewTinyLFU(1000, time.Minute),
Expand Down

0 comments on commit 8ed295c

Please sign in to comment.