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(cockroachdb): to use request driven options #2883

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

stevenh
Copy link
Collaborator

@stevenh stevenh commented Nov 8, 2024

Refactor cockroachdb module to to use request driven options simplifying the flow.

Clean up tests eliminating the use of suite which significantly speeds up test runs.

Copy link

netlify bot commented Nov 8, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 83a7838
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6740cfcb162998000802f123
😎 Deploy Preview https://deploy-preview-2883--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@stevenh
Copy link
Collaborator Author

stevenh commented Nov 8, 2024

This should be split out into components if we want to go down this route.

@stevenh stevenh marked this pull request as ready for review November 22, 2024 15:54
@stevenh stevenh requested a review from a team as a code owner November 22, 2024 15:54
@stevenh stevenh marked this pull request as draft November 22, 2024 15:54
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

I did an initial pass and the overall feedback is positive. I detected the following possible chunks of separate PRs, please tell me what you think:

  1. wait.walk for traversing multi strategies
  2. wait for TLS
  3. cockroachdb refactor

I think it would be much clearer for the review, but also for the release notes, as consumers would discover the new wait strategies as part of it.

@@ -0,0 +1,8 @@
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
Copy link
Member

Choose a reason for hiding this comment

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

question: are these settings the same for different cockroachdb versions? If we always set them, no matter the chosen version, then it could lead to misconfiguring the container.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like there is one change since this advice was introduced in v21.2.17 (a setting was removed in v21.2.22), so looks like we're good. If this was needed we could look to introduce version conditionals.

o.StoreSize = size
// WithInitScripts adds the given scripts to those automatically run when the container starts.
// These will be ignored if data exists in the `/cockroach/cockroach-data` directory within the container.
func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption {
Copy link
Member

Choose a reason for hiding this comment

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

question: should we use paths or readers, to allow users fetch the files from wherever they want?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Readers provides more flexibility so switching to that would be a good idea. Users that want to read from a file can easily use embed + bytes.NewReader to achieve that.

var _ Strategy = (*TLSStrategy)(nil)

// TLSStrategy is a strategy for handling TLS.
type TLSStrategy struct {
Copy link
Member

Choose a reason for hiding this comment

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

docs: we need to add a page for this in the docs (see mkdocs.yml in the root dir, and the wait folder under ./docs/features)

)

var (
//go:embed testdata/cert.crt
Copy link
Member

Choose a reason for hiding this comment

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

question: Have you considered using https://github.com/mdelapenya/tlscert instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I saw that, but it was hiding errors e.g. SelfSignedFromRequest returns nil on error, so followed the pattern in the standard library. If that got cleaned up we could change later.

)

func TestWalk(t *testing.T) {
req := testcontainers.ContainerRequest{
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I think we do not need the req, just the WaitingFor field

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're correct, but I wanted the test to act as an example of its use as well, hence using request.

Comment on lines +46 to +55
if err := visit(*root); err != nil {
if errors.Is(err, VisitRemove) {
*root = nil
}

return err
}

if s, ok := (*root).(*MultiStrategy); ok {
Copy link
Member

Choose a reason for hiding this comment

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

question: shouldn't we check first if the root is a multi-strategy, to iterate through the child elements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to allow the caller to customise the behaviour. This way round they could return an error or VisitRemove to remove the element without having to traverse it first. Added a comment to this effect.

return nil
})
require.NoError(t, err)
require.Equal(t, 5, count)
Copy link
Member

Choose a reason for hiding this comment

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

question: because the root has no logic, apart from being a "container" for the children strategies, should we count 4 here, therefore affecting the processing? I think this is related to my previous question about the root node being a multi.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As we visit the root first to allow it to be customised, the root is also counted.

wait/walk_test.go Show resolved Hide resolved
wait/walk_test.go Show resolved Hide resolved
@stevenh
Copy link
Collaborator Author

stevenh commented Nov 22, 2024

I did an initial pass and the overall feedback is positive. I detected the following possible chunks of separate PRs, please tell me what you think:

  1. wait.walk for traversing multi strategies
  2. wait for TLS
  3. cockroachdb refactor

I think it would be much clearer for the review, but also for the release notes, as consumers would discover the new wait strategies as part of it.

That's pretty much my thought's too, which is why I've left in draft.

martskins and others added 16 commits November 22, 2024 18:38
Co-authored-by: Steven Hartland <stevenmhartland@gmail.com>
Co-authored-by: Steven Hartland <stevenmhartland@gmail.com>
Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
Simplify the connection handling in cockroachdb so that ConnectionString
can be used without the user doing extra work to handle TLS if enabled.

Deprecate TLSConfig which is no longer needed separately.

BREAKING_CHANGE: This now returns a registered connection string so is
no longer compatible with pgx.ParseConfig, use ConnectionConfig for this
use case instead.
Refactor cockroachdb module to to use request driven options,
simplifying the flow.
Various fixes and remove the ability to configure certs using the
default generated ones instead.
Add the missing data file and remove unused constants.
Extract TLS certificate wait strategy into a dedicated wait type so it
can be reused.

Implement walk method which can be used to identify wait strategies in
a request chain.

Use embed to simplify wait test loading of certs.
Remove the now unused customizer.
Fix lint style issue for blank line.
Improve test coverage as per review feedback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants