diff --git a/go.mod b/go.mod index a863c1e9..c47cba2b 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/rudderlabs/rudder-go-kit go 1.22.5 +replace github.com/gocql/gocql => github.com/scylladb/gocql v1.14.2 + require ( cloud.google.com/go/storage v1.43.0 github.com/Azure/azure-storage-blob-go v0.15.0 @@ -11,6 +13,7 @@ require ( github.com/fsnotify/fsnotify v1.7.0 github.com/go-chi/chi/v5 v5.0.12 github.com/go-redis/redis/v8 v8.11.5 + github.com/gocql/gocql v1.14.2 github.com/gofrs/uuid v4.4.0+incompatible github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 @@ -101,6 +104,7 @@ require ( github.com/gorilla/handlers v1.5.2 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/heetch/avro v0.4.4 // indirect @@ -163,6 +167,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect google.golang.org/grpc v1.64.1 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 946c8f7a..9868afe6 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,10 @@ github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8= github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY= @@ -220,6 +224,7 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws= @@ -264,6 +269,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaW github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= @@ -457,6 +464,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= +github.com/scylladb/gocql v1.14.2 h1:IBPtfJFcRDzifCjXYMtrZ14oQ7OqpqQjwITQCwtGZsc= +github.com/scylladb/gocql v1.14.2/go.mod h1:ZLEJ0EVE5JhmtxIW2stgHq/v1P4fWap0qyyXSKyV8K0= github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE= github.com/secure-systems-lab/go-securesystemslib v0.4.0/go.mod h1:FGBZgq2tXWICsxWQW1msNf49F0Pf2Op5Htayx335Qbs= github.com/segmentio/kafka-go v0.4.47 h1:IqziR4pA3vrZq7YdRxaT3w1/5fvIH5qpCwstUanQQB0= @@ -641,6 +650,7 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= diff --git a/testhelper/docker/resource/scylla/config.go b/testhelper/docker/resource/scylla/config.go index 0a655135..1e9834d6 100644 --- a/testhelper/docker/resource/scylla/config.go +++ b/testhelper/docker/resource/scylla/config.go @@ -8,6 +8,13 @@ func WithTag(tag string) Option { } } +func WithKeyspace(keyspace string) Option { + return func(c *config) { + c.keyspace = keyspace + } +} + type config struct { - tag string + tag string + keyspace string } diff --git a/testhelper/docker/resource/scylla/scylla.go b/testhelper/docker/resource/scylla/scylla.go index 8644d1cf..b22f8f16 100644 --- a/testhelper/docker/resource/scylla/scylla.go +++ b/testhelper/docker/resource/scylla/scylla.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + "github.com/gocql/gocql" "github.com/ory/dockertest/v3" "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource" @@ -38,7 +39,7 @@ func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...Option) (*Resource } }) - url := fmt.Sprintf("http://localhost:%s", container.GetPort("9042/tcp")) + url := fmt.Sprintf("localhost:%s", container.GetPort("9042/tcp")) if err := pool.Retry(func() (err error) { var w bytes.Buffer @@ -52,13 +53,46 @@ func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...Option) (*Resource return err } if code != 0 { - return fmt.Errorf("pulsar healthcheck failed") + return fmt.Errorf("scylla healthcheck failed") } return nil }); err != nil { return nil, err } + if err := pool.Retry(func() (err error) { + var w bytes.Buffer + code, err := container.Exec( + []string{ + "sh", "-c", "cqlsh || exit 1", + }, + dockertest.ExecOptions{StdOut: &w, StdErr: &w}, + ) + if err != nil { + return err + } + if code != 0 { + return fmt.Errorf("scylla cql check failed") + } + return nil + }); err != nil { + return nil, err + } + + if c.keyspace != "" { + cluster := gocql.NewCluster(url) + cluster.Consistency = gocql.Quorum + session, err := cluster.CreateSession() + if err != nil { + return nil, err + } + defer session.Close() + err = session.Query(fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", c.keyspace)).Exec() + if err != nil { + return nil, err + } + } + return &Resource{ URL: url, Port: container.GetPort("9042/tcp"), diff --git a/testhelper/docker/resource/scylla/scylla_test.go b/testhelper/docker/resource/scylla/scylla_test.go index 59e80d50..818f233d 100644 --- a/testhelper/docker/resource/scylla/scylla_test.go +++ b/testhelper/docker/resource/scylla/scylla_test.go @@ -3,6 +3,7 @@ package scylla import ( "testing" + "github.com/gocql/gocql" "github.com/ory/dockertest/v3" "github.com/stretchr/testify/require" ) @@ -14,4 +15,11 @@ func TestScylla(t *testing.T) { scyllaContainer, err := Setup(pool, t) require.NoError(t, err) require.NotNil(t, scyllaContainer) + + cluster := gocql.NewCluster(scyllaContainer.URL) + cluster.Consistency = gocql.Quorum + session, err := cluster.CreateSession() + require.NoError(t, err) + require.NotNil(t, session) + session.Close() }