morph: Iterate over endpoints when create ws client in constructor #307

Merged
fyrchik merged 1 commit from acid-ant/frostfs-node:bugfix/304-morph-client into master 2023-05-05 07:29:47 +00:00
Member

Close #304

Signed-off-by: Anton Nikiforov an.nikiforov@yadro.com

Close #304 Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
acid-ant requested review from storage-core-committers 2023-05-03 13:05:32 +00:00
acid-ant requested review from storage-core-developers 2023-05-03 13:05:39 +00:00
fyrchik approved these changes 2023-05-03 13:10:49 +00:00
@ -141,2 +140,2 @@
if err != nil {
return nil, fmt.Errorf("could not create RPC client: %w", err)
for cli.endpoints.curr = range cli.endpoints.list {
cli.client, act, err = cli.newCli(ctx, cli.endpoints.list[cli.endpoints.curr].Address)
Owner

Can we log errors here? And then print which endpoint was chosen (IMO in INFO level).

Can we log errors here? And then print which endpoint was chosen (IMO in INFO level).
Author
Member

Please review, in previous version also forgot to exit from loop on success.

Please review, in previous version also forgot to exit from loop on success.
fyrchik marked this conversation as resolved
acid-ant changed title from morph: Iterate over endpoints when create ws client in constructor to WIP: morph: Iterate over endpoints when create ws client in constructor 2023-05-03 14:10:00 +00:00
acid-ant force-pushed bugfix/304-morph-client from 1282c0101d to 5557b4f39d 2023-05-03 14:13:05 +00:00 Compare
acid-ant changed title from WIP: morph: Iterate over endpoints when create ws client in constructor to morph: Iterate over endpoints when create ws client in constructor 2023-05-03 14:13:49 +00:00
acid-ant requested review from fyrchik 2023-05-03 14:13:51 +00:00
fyrchik reviewed 2023-05-03 16:13:58 +00:00
@ -143,0 +142,4 @@
cli.client, act, err = cli.newCli(ctx, endpoint.Address)
if err != nil {
err = fmt.Errorf("could not create RPC client for endpoint %s: %w", endpoint.Address, err)
cli.logger.Debug(err.Error())
Owner

We usually log the message and use zap.Error, why have you decided to Debug(err.Error())

We usually log the message and use `zap.Error`, why have you decided to `Debug(err.Error())`
Author
Member

Because in this case, error already contains context. Also, to avoid duplication, cause in the worth case we need to return error.

Because in this case, error already contains context. Also, to avoid duplication, cause in the worth case we need to return error.
Author
Member

Updated, please review.

Updated, please review.
fyrchik marked this conversation as resolved
@ -143,0 +143,4 @@
if err != nil {
err = fmt.Errorf("could not create RPC client for endpoint %s: %w", endpoint.Address, err)
cli.logger.Debug(err.Error())
if cli.endpoints.curr == len(cli.endpoints.list)-1 {
Owner

Can we move this line out of the loop?
The error could be defined separately -- it is not the last, but e.g. ErrNoHealthyEndpoint

var cli *Client
for { ... }
if cli == nil {
  return nil, ErrNoHealthyEndpoint
}
Can we move this line out of the loop? The error could be defined separately -- it is not the last, but e.g. `ErrNoHealthyEndpoint` ``` var cli *Client for { ... } if cli == nil { return nil, ErrNoHealthyEndpoint } ```
Author
Member

Nice suggestion, will implement it.

Nice suggestion, will implement it.
Author
Member

Updated, please review.

Updated, please review.
fyrchik marked this conversation as resolved
@ -143,0 +147,4 @@
return nil, err
}
} else {
cli.logger.Info(fmt.Sprintf("created RPC client for endpoint %s", endpoint.Address))
Owner

Again, what about zap.String("endpoint", endpoint.Address)?

Again, what about `zap.String("endpoint", endpoint.Address)`?
Author
Member

Sorry, flashbacks from java :)

Sorry, flashbacks from java :)
Author
Member

Updated, please review.

Updated, please review.
fyrchik marked this conversation as resolved
acid-ant force-pushed bugfix/304-morph-client from 5557b4f39d to 06112d683f 2023-05-04 07:15:46 +00:00 Compare
fyrchik approved these changes 2023-05-04 13:59:27 +00:00
@ -53,2 +53,4 @@
)
var (
ErrNoHealthyEndpoint = errors.New("no healthy endpoint")
Owner

Does linter say nothing here?
Maybe add some comment to public errors.

Does linter say nothing here? Maybe add some comment to public errors.
Author
Member

Nothing, didn't disable anything related to pre-commit check.

Nothing, didn't disable anything related to pre-commit check.
Author
Member

Add more info about ErrNoHealthyEndpoint in help for New(...)

Add more info about ErrNoHealthyEndpoint in help for New(...)
fyrchik reviewed 2023-05-04 14:04:03 +00:00
@ -143,0 +145,4 @@
for cli.endpoints.curr, endpoint = range cli.endpoints.list {
cli.client, act, err = cli.newCli(ctx, endpoint.Address)
if err != nil {
cli.logger.Debug("could not create RPC client for endpoint",
Owner

Use constant from internal/logs?

Use constant from `internal/logs`?
Author
Member

Done

Done
fyrchik marked this conversation as resolved
acid-ant force-pushed bugfix/304-morph-client from 06112d683f to 53abcf25e2 2023-05-04 14:14:15 +00:00 Compare
acid-ant force-pushed bugfix/304-morph-client from 53abcf25e2 to d2f99c4caa 2023-05-04 14:14:43 +00:00 Compare
acid-ant force-pushed bugfix/304-morph-client from d2f99c4caa to 2633bbe13e 2023-05-04 14:28:01 +00:00 Compare
dstepanov-yadro reviewed 2023-05-04 14:38:18 +00:00
@ -143,0 +148,4 @@
for cli.endpoints.curr, endpoint = range cli.endpoints.list {
cli.client, act, err = cli.newCli(ctx, endpoint.Address)
if err != nil {
cli.logger.Debug(logs.FrostFSIRCouldntCreateRPCClientForEndpoint,

Maybe Warn, not Debug?

Maybe Warn, not Debug?
Author
Member

Why not, updated.

Why not, updated.
dstepanov-yadro approved these changes 2023-05-04 14:38:34 +00:00
acid-ant force-pushed bugfix/304-morph-client from 2633bbe13e to 160bf151e5 2023-05-04 14:57:01 +00:00 Compare
acid-ant scheduled this pull request to auto merge when all checks succeed 2023-05-04 15:02:37 +00:00
fyrchik approved these changes 2023-05-05 07:06:59 +00:00
Owner

Please, resolve conflicts

Please, resolve conflicts
acid-ant force-pushed bugfix/304-morph-client from 160bf151e5 to cedd07bbc8 2023-05-05 07:07:41 +00:00 Compare
fyrchik merged commit cedd07bbc8 into master 2023-05-05 07:29:47 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#307
No description provided.