adm: Allow to download contracts from Gitea #958

Merged
fyrchik merged 1 commit from okonstantinova/frostfs-node:feature/466-download_contracts_from_gitea into master 2024-02-09 07:50:35 +00:00
Contributor

Close #466

For the morph init command the contract command line parameter has become optional and the contract-url parameter has been introduced. The contract-url parameter allows to specify an HTTP link to download a contract archive from. If neither of the parameters is used then the default behavior is to take the latest release from the frostfs-contract repository.

Signed-off-by: Olga Konstantinova kola43843@gmail.com

Close #466 For the `morph init` command the `contract` command line parameter has become optional and the `contract-url` parameter has been introduced. The `contract-url` parameter allows to specify an HTTP link to download a contract archive from. If neither of the parameters is used then the default behavior is to take the latest release from the `frostfs-contract` repository. Signed-off-by: Olga Konstantinova <kola43843@gmail.com>
acid-ant changed title from [#466] Allow to download contracts from Gitea to adm: Allow to download contracts from Gitea 2024-02-05 06:19:26 +00:00
acid-ant requested review from storage-core-committers 2024-02-05 06:20:37 +00:00
acid-ant requested review from storage-core-developers 2024-02-05 06:20:38 +00:00
Member

Could you please reword commit message a bit:
[#466] Allow to download... --> [#466] adm: Allow to download...

Could you please reword commit message a bit: `[#466] Allow to download...` --> `[#466] adm: Allow to download...`
acid-ant requested changes 2024-02-05 06:56:25 +00:00
@ -242,0 +252,4 @@
}
ctrURL, err := cmd.Flags().GetString(contractsURLFlag)
if err != nil {
Member

It is ok to skip check for the error here, the function is redundant at all.

It is ok to skip check for the error here, the function is redundant at all.
Author
Contributor

Thanks, fixed

Thanks, fixed
fyrchik marked this conversation as resolved
@ -372,3 +373,2 @@
updateContractsCmd.Flags().StringP(endpointFlag, endpointFlagShort, "", endpointFlagDesc)
updateContractsCmd.Flags().String(contractsInitFlag, "", "Path to archive with compiled FrostFS contracts")
_ = updateContractsCmd.MarkFlagRequired(contractsInitFlag)
updateContractsCmd.Flags().String(contractsInitFlag, "", "Path to archive with compiled FrostFS contracts (the default is to fetch the latest release from the official repository)")
Member

How about to mark flags contracts and contracts-url as mutually exclusive?

updateContractsCmd.MarkFlagsMutuallyExclusive(contractsInitFlag, contractsURLFlag)
How about to mark flags `contracts` and `contracts-url` as mutually exclusive? ``` updateContractsCmd.MarkFlagsMutuallyExclusive(contractsInitFlag, contractsURLFlag) ```
Author
Contributor

Thanks, done.

Thanks, done.
acid-ant marked this conversation as resolved
aarifullin reviewed 2024-02-05 08:50:53 +00:00
@ -0,0 +14,4 @@
func downloadContracts(cmd *cobra.Command, url string) (io.ReadCloser, error) {
cmd.Printf("Downloading contracts archive from '%s'\n", url)
resp, err := http.Get(url)
Member

Using bare http.Get is fine if you use it within a core of well-designed client.
But in this case:

  1. We cannot cancel request performing, if cmd.Context() is cancelled. It means the command may hang up until Get is finished and we, as users, are obliged to wait for its finishing
  2. We do not attempt to retry request, if url is unvailable for some reason
  3. We do not configure timeouts

So, I would like to suggest to import resty client. Because we have not been using it, you need to go get it

go get github.com/go-resty/resty/v2

Then

import (
   resty "github.com/go-resty/resty/v2"
)

/*...*/
        const defaultRetryCount = 3 // can use just as a constant, no flag introducing is needed

        client := resty.New()
	    client.SetRetryCount(defaultRetryCount).R().SetContext(cmd.Context()).Get(url)
        // also it needs to set timeout etc.
/*...*/
Using _bare_ `http.Get` is fine if you use it within a core of well-designed client. But in this case: 1. We cannot cancel request performing, if `cmd.Context()` is cancelled. It means the command may _hang up_ until `Get` is finished and we, as users, are obliged to wait for its finishing 2. We do not attempt to retry request, if `url` is unvailable for some reason 3. We do not configure timeouts So, I would like to suggest to import resty client. Because we have not been using it, you need to `go get` it ``` go get github.com/go-resty/resty/v2 ``` Then ```go import ( resty "github.com/go-resty/resty/v2" ) /*...*/ const defaultRetryCount = 3 // can use just as a constant, no flag introducing is needed client := resty.New() client.SetRetryCount(defaultRetryCount).R().SetContext(cmd.Context()).Get(url) // also it needs to set timeout etc. /*...*/ ```
Owner

This is quite a simple task, could we avoid importing a whole new dependency for the sake of rarely to be used command?
It would be nice if we could use just the stdlib there.

This is quite a simple task, could we avoid importing a whole new dependency for the sake of rarely to be used command? It would be nice if we could use just the stdlib there.
Member

Alright, I don't mind

Alright, I don't mind
Owner

Well, we still could try using context: an example https://gist.github.com/superbrothers/dae0030c151d1f3c24311df77405169b

Well, we still could try using context: an example https://gist.github.com/superbrothers/dae0030c151d1f3c24311df77405169b
Author
Contributor

I have changed the implementation, now it sends an HTTP request with connect timeout and uses a context with timeout. Thank you!

I have changed the implementation, now it sends an HTTP request with connect timeout and uses a context with timeout. Thank you!
fyrchik marked this conversation as resolved
okonstantinova force-pushed feature/466-download_contracts_from_gitea from 9cffb1918d to 82dfcf9a3e 2024-02-06 22:44:54 +00:00 Compare
okonstantinova force-pushed feature/466-download_contracts_from_gitea from 82dfcf9a3e to 9736f8f696 2024-02-06 22:51:14 +00:00 Compare
okonstantinova force-pushed feature/466-download_contracts_from_gitea from 9736f8f696 to 1034e30114 2024-02-06 23:02:31 +00:00 Compare
okonstantinova changed title from adm: Allow to download contracts from Gitea to WIP: adm: Allow to download contracts from Gitea 2024-02-06 23:07:48 +00:00
okonstantinova changed title from WIP: adm: Allow to download contracts from Gitea to adm: Allow to download contracts from Gitea 2024-02-06 23:07:58 +00:00
acid-ant requested changes 2024-02-07 06:48:18 +00:00
@ -152,6 +153,11 @@ func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContex
return nil, err
}
ctrURL, err := getContractsURL(cmd, needContracts)
Member

How about this:

	var ctrURL string
	if needContracts {
		ctrURL, _ = cmd.Flags().GetString(contractsURLFlag)
	}

It is ok to skip check for the error here, the function getContractsURL is redundant at all.

How about this: ``` var ctrURL string if needContracts { ctrURL, _ = cmd.Flags().GetString(contractsURLFlag) } ``` It is ok to skip check for the error here, the function `getContractsURL` is redundant at all.
Author
Contributor

Done as recommended, thanks

Done as recommended, thanks
acid-ant marked this conversation as resolved
@ -372,3 +373,2 @@
updateContractsCmd.Flags().StringP(endpointFlag, endpointFlagShort, "", endpointFlagDesc)
updateContractsCmd.Flags().String(contractsInitFlag, "", "Path to archive with compiled FrostFS contracts")
_ = updateContractsCmd.MarkFlagRequired(contractsInitFlag)
updateContractsCmd.Flags().String(contractsInitFlag, "", "Path to archive with compiled FrostFS contracts (the default is to fetch the latest release from the official repository)")
Member

Please move description to the constant contractsInitFlagDesc and reuse it for initCmd.

Please move description to the constant `contractsInitFlagDesc` and reuse it for `initCmd`.
Author
Contributor

Thanks, done

Thanks, done
acid-ant marked this conversation as resolved
@ -373,2 +374,2 @@
updateContractsCmd.Flags().String(contractsInitFlag, "", "Path to archive with compiled FrostFS contracts")
_ = updateContractsCmd.MarkFlagRequired(contractsInitFlag)
updateContractsCmd.Flags().String(contractsInitFlag, "", "Path to archive with compiled FrostFS contracts (the default is to fetch the latest release from the official repository)")
updateContractsCmd.Flags().String(contractsURLFlag, "", "URL to archive with compiled FrostFS contracts")
Member

Please move description to the constant contractsURLFlagDesc and reuse it for initCmd.

Please move description to the constant `contractsURLFlagDesc` and reuse it for `initCmd`.
Author
Contributor

Thanks, done

Thanks, done
acid-ant marked this conversation as resolved
Member

Please squash commits.

Please squash commits.
aarifullin reviewed 2024-02-07 09:45:28 +00:00
@ -0,0 +26,4 @@
},
}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
Member

Good :) But instead context.Background() we need to use cmd.Context()

Good :) But instead `context.Background()` we need to use `cmd.Context()`
Author
Contributor

I suspected that something like this would be needed, but was not sure. Thank you for help!

I suspected that something like this would be needed, but was not sure. Thank you for help!
aarifullin marked this conversation as resolved
okonstantinova force-pushed feature/466-download_contracts_from_gitea from 1034e30114 to bb45fdf01a 2024-02-07 19:39:18 +00:00 Compare
acid-ant approved these changes 2024-02-08 06:35:36 +00:00
aarifullin approved these changes 2024-02-08 08:15:49 +00:00
dstepanov-yadro approved these changes 2024-02-08 08:49:15 +00:00
achuprov approved these changes 2024-02-08 13:24:41 +00:00
okonstantinova force-pushed feature/466-download_contracts_from_gitea from bb45fdf01a to 80b581d499 2024-02-08 21:07:58 +00:00 Compare
fyrchik merged commit 80b581d499 into master 2024-02-09 07:50:35 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
6 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#958
No description provided.