-
-
Notifications
You must be signed in to change notification settings - Fork 512
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
feat(scylladb): add scylladb provider #2919
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
…rd-awareness port
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a PR @danielhe4rt, have done an initial review with some suggestions and questions for you.
shardAwarePort = "19042/tcp" | ||
) | ||
|
||
type Container struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Add a doc comment to describe.
modules/scylladb/scylladb.go
Outdated
cf := testcontainers.ContainerFile{ | ||
HostFilePath: configFile, | ||
ContainerFilePath: "/etc/scylla/scylla.yaml", | ||
FileMode: 0o755, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: no need for the file to be executable
modules/scylladb/scylladb.go
Outdated
// WithAlternator enables the Alternator (DynamoDB Compatible API) service in the ScyllaDB container. | ||
// It will set the "alternator-port" parameter to the specified port. | ||
// It will also set the "alternator-write-isolation" parameter to "always" as a command line argument to the container. | ||
func WithAlternator(alternatorPort int) testcontainers.CustomizeRequestOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: use the in type which matches a port definition
func WithAlternator(alternatorPort int) testcontainers.CustomizeRequestOption { | |
func WithAlternator(alternatorPort uint16) testcontainers.CustomizeRequestOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having WithAlternator()
would be enough, simplifying user setup. Regarding to alternator-write-isolation
, is always
recommended for testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depend on the application. for testing it's "slower" but you probably wont be doing stress testing in the cluster.
// ConnectionHost returns the host and port of the Scylladb container with the default port | ||
// and obtaining the host and exposed port from the container | ||
// Eg: "host:port" -> "localhost:9042" -> "localhost:19042" -> "localhost:8000" | ||
func (c Container) ConnectionHost(ctx context.Context, port int) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: use uint16 to match port requirement.
func (c Container) ConnectionHost(ctx context.Context, port int) (string, error) { | |
func (c Container) ConnectionHost(ctx context.Context, port uint16) (string, error) { |
modules/scylladb/scylladb_test.go
Outdated
testcontainers.CleanupContainer(t, ctr) | ||
require.NoError(t, err) | ||
|
||
t.Run("test without shard awareness", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: we're standardising on simple names without spaces to ensure they match the output
t.Run("test without shard awareness", func(t *testing.T) { | |
t.Run("without-shard-awareness", func(t *testing.T) { |
More below
|
||
ctr, err := scylladb.Run(ctx, | ||
"scylladb/scylla:6.2", | ||
scylladb.WithConfigFile(filepath.Join("testdata", "scylla.yaml")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: with the change to reader, you can leverage embed
//go:embed testdata/scylla.yaml
var testConfig []byte
scylladb.WithConfigFile(filepath.Join("testdata", "scylla.yaml")), | |
scylladb.WithConfig(bytes.NewReader(testConfig)), |
modules/scylladb/scylladb_test.go
Outdated
}) | ||
} | ||
|
||
func TestScyllaWithAlternator(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: These next two tests look like duplicates of the above, or could be combined?
return dynamodb.NewFromConfig(cfg, dynamodb.WithEndpointResolverV2(&scyllaAlternatorResolver{HostPort: hostPort})), errors.Join(errs...) | ||
} | ||
|
||
func createTable(client *dynamodb.Client) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: pass in t and require.NoError as thats the only use of this.
murmur3_partitioner_ignore_msb_bits: 12 | ||
strict_is_not_null_in_views: true | ||
maintenance_socket: ignore | ||
enable_tablets: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: add trailing newline.
@@ -0,0 +1,194 @@ | |||
package scylladb_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include a test using ssl? I think would be nice to have.
modules/scylladb/scylladb_test.go
Outdated
host, err := ctr.ConnectionHost(ctx, 19042) | ||
require.NoError(t, err) | ||
|
||
cluster := gocql.NewCluster(host) | ||
session, err := cluster.CreateSession() | ||
require.NoError(t, err) | ||
defer session.Close() | ||
|
||
var address string | ||
err = session.Query("SELECT address FROM system.clients").Scan(&address) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("test with shard awareness", func(t *testing.T) { | ||
host, err := ctr.ConnectionHost(ctx, 19042) | ||
require.NoError(t, err) | ||
|
||
cluster := gocql.NewCluster(host) | ||
session, err := cluster.CreateSession() | ||
require.NoError(t, err) | ||
defer session.Close() | ||
|
||
var address string | ||
err = session.Query("SELECT address FROM system.clients").Scan(&address) | ||
require.NoError(t, err) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see both tests are the same. should one of them use 9042 instead? Is it enough testing the connection?
} | ||
|
||
// WithShardAwareness enable shard-awareness in the ScyllaDB container so you can use the `19042` port. | ||
func WithShardAwareness() testcontainers.CustomizeRequestOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scylladb starts both ports 9042 and 19042 by default. IMO we should expose a fn to get the mapped port for 19042 and omit this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielhe4rt @eddumelendez I'm taking over the PR and adding the suggestions on top of the original PR.
I'd like to have this in the upcoming release.
Thanks all for your time here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, I noticed this PR is sent from the main
branch of the fork, so unfortunately I cannot contribute commits to it.
@danielhe4rt could you please address the above comments 🙏 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Sorry for the delay. Tomorrow I'll sync with @CodeLieutenant and finish it for good. Give us one more day @mdelapenya. We're also gonna stream it, so you can find us on twitch.tv/danielhe4rt.
Co-authored-by: Steven Hartland <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielhe4rt thanks for your time in this PR, I added a few comments/suggestions in the review.
Could you address them 🙏 ?
Thank you in advance
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
In the case you have a custom config file for ScyllaDB, it's possible to copy that file into the container before it's | ||
started, using the `WithConfigFile(cfgPath string)` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: let's use the WithConfig(io.Reader)
method here, as suggested in the review comments. It's also applied to the existing tests, so we should change the method call in there.
[With Config YAML](../../modules/scylladb/examples_test.go) inside_block:runScyllaDBContainerWithConfigFile | ||
<!--/codeinclude--> | ||
!!!warning | ||
You should provide a valid ScyllaDB configuration file when using the function, otherwise the container will fail to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: see above
You should provide a valid ScyllaDB configuration file when using the function, otherwise the container will fail to | |
You should provide a valid ScyllaDB configuration file as an `io.Reader` when using the function, otherwise the container will fail to |
!!! info | ||
By default, we add the `--developer-mode=1` flag to the ScyllaDB container to disable the various checks Scylla | ||
performs. | ||
Also In scenarios in which static partitioning is not desired - like mostly-idle cluster without hard latency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo
Also In scenarios in which static partitioning is not desired - like mostly-idle cluster without hard latency | |
Also in scenarios in which static partitioning is not desired - like mostly-idle cluster without hard latency |
modules/scylladb/examples_test.go
Outdated
|
||
fmt.Println(state.Running) | ||
|
||
connectionHost, err := scyllaContainer.ConnectionHost(ctx, 8080) // Alternator port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: in L61 we are setting the alternator port as 8000. Is this correct?
connectionHost, err := scyllaContainer.ConnectionHost(ctx, 8080) // Alternator port | |
connectionHost, err := scyllaContainer.ConnectionHost(ctx, 8000) // Alternator port |
// true | ||
} | ||
|
||
func ExampleRun_withConfigFile() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: as above, we probably want to use the WithConfig(io.Reader)
here
port = "9042/tcp" | ||
shardAwarePort = "19042/tcp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: should we expose these ports so that client code can generate URLs based on them? I see an example test using one of them. If not, we probably want a container method returning the connection string for the given port.
modules/scylladb/scylladb.go
Outdated
testcontainers.Container | ||
} | ||
|
||
// WithConfig sets the YAML config file to be used for the ScyllaDB container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// WithConfig sets the YAML config file to be used for the ScyllaDB container | |
// WithConfig sets the YAML config file as an [io.Reader] to be used for the ScyllaDB container |
}) | ||
} | ||
|
||
func TestScyllaWithConfigFile(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: as above
func TestScyllaWithConfigFile(t *testing.T) { | |
func TestScyllaWithConfig(t *testing.T) { |
err = session.Query("SELECT cluster_name FROM system.local").Scan(&cluster_name) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "Amazing ScyllaDB Test", cluster_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: add awareness about where this constant value comes from
require.Equal(t, "Amazing ScyllaDB Test", cluster_name) | |
// the "Amazing ScyllaDB Test" cluster name is set in the scylla.yaml file | |
require.Equal(t, "Amazing ScyllaDB Test", cluster_name) |
modules/scylladb/scylladb_test.go
Outdated
}, nil | ||
} | ||
|
||
func getDynamoAlternatorClient(t *testing.T, c *scylladb.Container, port int) (*dynamodb.Client, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: if the assertions in the calling tests are all the same (create a table using the client), you may want to merge them into this helper function, and name it assertCreateTable(t *testing.T)
. You could also merge the createTable
helper
What does this PR do?
Implements the Database ScyllaDB as a new provider.
Under the
ScyllaDBContainer
you will have the possibility of:Shard Awareness
port usingWithShardAwareness
;WithCommand
ConnectionHost
API Example
Why is it important?
ScyllaDB is a NoSQL Database that is being constantly used by big companies and acts as a Drop-in Replacement to
CassandraDB
andDynamoDB
.How to test this PR
Clone the repository and enter the
scylladb
module folder: