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

Implement Redis client configuration logic #104

Merged
merged 30 commits into from
Feb 29, 2024

Conversation

aaron-congo
Copy link

No description provided.

@aaron-congo aaron-congo changed the title Implement Redis client configuration logic [WIP] Implement Redis client configuration logic Feb 20, 2024
go/api/config.go Outdated Show resolved Hide resolved
go/Makefile Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/go.sum Outdated Show resolved Hide resolved

Choose a reason for hiding this comment

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

consider using linter for makefile too (later)

@@ -65,7 +65,13 @@ jobs:
with:
redis-version: ${{ matrix.redis }}

- name: Install client dependencies
- name: Install tools for Go 1.18
Copy link
Author

Choose a reason for hiding this comment

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

Having one set of CI tool versions was not working for me because go 1.18 and go 1.21 require different versions of CI tools. Old tools did not work on go 1.21 and new tools did not work on go 1.18. I've looked around and have not been able to find recommendations on how to handle this scenario. The solution I've landed on so far is to have different make targets for installing tools on go 1.18 vs go 1.20


import "github.com/aws/glide-for-redis/go/glide/protobuf"

// NodeAddress represents the host address and port of a node in the cluster.
Copy link
Author

Choose a reason for hiding this comment

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

Apparently go doc comments are supposed to include the name of the type/func in the first sentence, so the docs are slightly different than the other clients to accommodate that. I've tried to keep them as close possible still though

Choose a reason for hiding this comment

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

@Yury-Fridlyand present tense will be forced for Go it seems ;)

go/api/config.go Show resolved Hide resolved
)

type baseClientConfiguration struct {
addresses []NodeAddress
Copy link
Author

Choose a reason for hiding this comment

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

I've made these fields private (indicated by the lower-case first letter) so that the user has to use the With* builder methods instead of accessing them directly

Copy link
Author

Choose a reason for hiding this comment

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

Instead of putting docs for these private fields here, I've put the docs above the associated With* builder methods below

go/api/config.go Show resolved Hide resolved
go/api/config_test.go Outdated Show resolved Hide resolved
@@ -0,0 +1,160 @@
/**
Copy link
Author

@aaron-congo aaron-congo Feb 22, 2024

Choose a reason for hiding this comment

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

Note: I had to get rid of the tests folder and put this test file beside the implementation file. Unfortunately this seems to be the way to do things in Go. If the test file resides in a separate tests directory, it is not in the same package as the implementation, which means tests do not have access to any of the internal (private) symbols in the implementation. Looking at other Go projects they also have their test files beside their implementation files

@aaron-congo aaron-congo changed the title [WIP] Implement Redis client configuration logic Implement Redis client configuration logic Feb 22, 2024
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
go/api/config.go Show resolved Hide resolved
go/api/config.go Show resolved Hide resolved
.editorconfig Outdated Show resolved Hide resolved
go/api/config.go Outdated Show resolved Hide resolved
}

// NewRedisCredentials returns a new RedisCredentials struct with the given username and password.
func NewRedisCredentials(username string, password string) *RedisCredentials {
Copy link
Author

Choose a reason for hiding this comment

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

since the zero-values for the struct are all suitable for defaults, if we wanted we could get rid of the whole builder and just have the user use the struct directly. But that solution may be slightly more awkward in some ways, eg forming the address list

.editorconfig Outdated Show resolved Hide resolved
.editorconfig Outdated Show resolved Hide resolved
.editorconfig Outdated Show resolved Hide resolved
.github/workflows/go.yml Outdated Show resolved Hide resolved
.github/workflows/go.yml Show resolved Hide resolved
go/DEVELOPER.md Show resolved Hide resolved
go/DEVELOPER.md Show resolved Hide resolved
go/DEVELOPER.md Outdated Show resolved Hide resolved
go/api/config_test.go Show resolved Hide resolved
go/api/config_test.go Show resolved Hide resolved
Copy link

@jonathanl-bq jonathanl-bq left a comment

Choose a reason for hiding this comment

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

One minor comment about iota, but otherwise looks pretty good. We should make sure we confirm with the rest of the team that we want to remove the builder, as per our discussion. Also, we need someone who hasn't already installed prerequisites for working on this wrapper to test the DEVELOPER.md steps.

go/api/config.go Outdated Show resolved Hide resolved
go/DEVELOPER.md Outdated Show resolved Hide resolved
go/DEVELOPER.md Outdated Show resolved Hide resolved
go/DEVELOPER.md Show resolved Hide resolved
go/DEVELOPER.md Show resolved Hide resolved
go/DEVELOPER.md Show resolved Hide resolved
go/DEVELOPER.md Show resolved Hide resolved

import "github.com/aws/glide-for-redis/go/glide/protobuf"

// NodeAddress represents the host address and port of a node in the cluster.

Choose a reason for hiding this comment

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

@Yury-Fridlyand present tense will be forced for Go it seems ;)


// NodeAddress represents the host address and port of a node in the cluster.
type NodeAddress struct {
Host string // Optional: if not supplied, "localhost" will be used.

Choose a reason for hiding this comment

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

move the Optional comment above the field, rather than inline

Copy link
Author

@aaron-congo aaron-congo Feb 28, 2024

Choose a reason for hiding this comment

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

The Go docs have examples with both inline and above, but if we prefer them above then I can change this

//
// Once the maximum value is reached, that will remain the time between retry attempts until a reconnect attempt is successful.
// The client will attempt to reconnect indefinitely.
type BackoffStrategy struct {

Choose a reason for hiding this comment

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

@aaron-congo can you confirm that the formatting for these comments is preserved when generating documentation?

Copy link
Author

Choose a reason for hiding this comment

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

The line length is not preserved, but blank lines and indents are. So docs for the above look like this (you can get them by running go doc -all github.com/aws/glide-for-redis/go/glide/api

    BackoffStrategy represents the strategy used to determine how and when to
    reconnect, in case of connection failures. The time between attempts grows
    exponentially, to the formula:

        rand(0 ... factor * (exponentBase ^ N))

    where N is the number of failed attempts.

    Once the maximum value is reached, that will remain the time between retry
    attempts until a reconnect attempt is successful. The client will attempt to
    reconnect indefinitely.

Choose a reason for hiding this comment

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

What about font for the coded section and "N". Can we use backticks (like Python) or add html tags (like <code> and <pre>)?

Copy link
Author

@aaron-congo aaron-congo Feb 29, 2024

Choose a reason for hiding this comment

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

With Go docs you create code blocks by indenting the relevant code, like I've done here. There is no inline code highlighting like you would get with backticks. When you upload the package the site will automatically render the Go docs into html, which includes rendering the indented code blocks as <pre> blocks

go/api/config.go Show resolved Hide resolved
@aaron-congo aaron-congo merged commit 3e0e9dd into go/integ_acongo_config Feb 29, 2024
10 checks passed
@aaron-congo aaron-congo deleted the go/dev_acongo_config branch February 29, 2024 20:23
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.

4 participants