-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: Provider.WorkerCount and stats reprovide cmd
#10779
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
Changes from all commits
05d0bb3
4e8d223
0e37989
62d51d6
b33c4fa
b0ba27c
0662522
cc02022
5d148b8
617d5c8
c65608c
30bdc15
9a04312
06e6618
b0f3bbd
74cf6af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| package config | ||
|
|
||
| const ( | ||
| DefaultProviderWorkerCount = 64 | ||
| ) | ||
|
|
||
| // Provider configuration describes how NEW CIDs are announced the moment they are created. | ||
| // For periodical reprovide configuration, see Reprovider.* | ||
| type Provider struct { | ||
| Strategy string // Which keys to announce | ||
| Strategy *OptionalString `json:",omitempty"` // Unused, you are likely looking for Reprovider.Strategy instead | ||
| WorkerCount *OptionalInteger `json:",omitempty"` // Number of concurrent provides allowed, 0 means unlimited | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,28 +4,20 @@ import ( | |
| "fmt" | ||
| "io" | ||
| "text/tabwriter" | ||
| "time" | ||
|
|
||
| humanize "github.com/dustin/go-humanize" | ||
| "github.com/ipfs/boxo/provider" | ||
| cmds "github.com/ipfs/go-ipfs-cmds" | ||
| "github.com/ipfs/kubo/core/commands/cmdenv" | ||
| "github.com/libp2p/go-libp2p-kad-dht/fullrt" | ||
| "golang.org/x/exp/constraints" | ||
| ) | ||
|
|
||
| type reprovideStats struct { | ||
| provider.ReproviderStats | ||
| fullRT bool | ||
| } | ||
|
|
||
| var statProvideCmd = &cmds.Command{ | ||
| Status: cmds.Deprecated, | ||
| Helptext: cmds.HelpText{ | ||
| Tagline: "Returns statistics about the node's (re)provider system.", | ||
| Tagline: "Deprecated command, use 'ipfs stats reprovide' instead.", | ||
| ShortDescription: ` | ||
| Returns statistics about the content the node is advertising. | ||
|
|
||
| This interface is not stable and may change from release to release. | ||
| 'ipfs stats provide' is deprecated because provide and reprovide operations | ||
| are now distinct. This command may be replaced by provide only stats in the | ||
| future. | ||
| `, | ||
| }, | ||
| Arguments: []cmds.Argument{}, | ||
|
|
@@ -57,8 +49,8 @@ This interface is not stable and may change from release to release. | |
| wtr := tabwriter.NewWriter(w, 1, 2, 1, ' ', 0) | ||
| defer wtr.Flush() | ||
|
|
||
| fmt.Fprintf(wtr, "TotalReprovides:\t%s\n", humanNumber(s.TotalReprovides)) | ||
| fmt.Fprintf(wtr, "AvgReprovideDuration:\t%s\n", humanDuration(s.AvgReprovideDuration)) | ||
| fmt.Fprintf(wtr, "TotalProvides:\t%s\n", humanNumber(s.TotalReprovides)) | ||
| fmt.Fprintf(wtr, "AvgProvideDuration:\t%s\n", humanDuration(s.AvgReprovideDuration)) | ||
|
Comment on lines
+52
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the printed names correct? Seems like they should match the variable names, even if that causes a breaking change.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we would be making a breaking change – see #10779 (comment) Safer to keep We will remove / change |
||
| fmt.Fprintf(wtr, "LastReprovideDuration:\t%s\n", humanDuration(s.LastReprovideDuration)) | ||
| if !s.LastRun.IsZero() { | ||
| fmt.Fprintf(wtr, "LastRun:\t%s\n", humanTime(s.LastRun)) | ||
|
|
@@ -71,30 +63,3 @@ This interface is not stable and may change from release to release. | |
| }, | ||
| Type: reprovideStats{}, | ||
| } | ||
|
|
||
| func humanDuration(val time.Duration) string { | ||
| return val.Truncate(time.Microsecond).String() | ||
| } | ||
|
|
||
| func humanTime(val time.Time) string { | ||
| return val.Format("2006-01-02 15:04:05") | ||
| } | ||
|
|
||
| func humanNumber[T constraints.Float | constraints.Integer](n T) string { | ||
| nf := float64(n) | ||
| str := humanSI(nf, 0) | ||
| fullStr := humanFull(nf, 0) | ||
| if str != fullStr { | ||
| return fmt.Sprintf("%s\t(%s)", str, fullStr) | ||
| } | ||
| return str | ||
| } | ||
|
|
||
| func humanSI(val float64, decimals int) string { | ||
| v, unit := humanize.ComputeSI(val) | ||
| return fmt.Sprintf("%s%s", humanFull(v, decimals), unit) | ||
| } | ||
|
|
||
| func humanFull(val float64, decimals int) string { | ||
| return humanize.CommafWithDigits(val, decimals) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "text/tabwriter" | ||
| "time" | ||
|
|
||
| humanize "github.com/dustin/go-humanize" | ||
| "github.com/ipfs/boxo/provider" | ||
| cmds "github.com/ipfs/go-ipfs-cmds" | ||
| "github.com/ipfs/kubo/core/commands/cmdenv" | ||
| "github.com/libp2p/go-libp2p-kad-dht/fullrt" | ||
| "golang.org/x/exp/constraints" | ||
| ) | ||
|
|
||
| type reprovideStats struct { | ||
| provider.ReproviderStats | ||
| fullRT bool | ||
| } | ||
|
|
||
| var statReprovideCmd = &cmds.Command{ | ||
| Status: cmds.Experimental, | ||
| Helptext: cmds.HelpText{ | ||
| Tagline: "Returns statistics about the node's reprovider system.", | ||
| ShortDescription: ` | ||
| Returns statistics about the content the node is reproviding every | ||
| Reprovider.Interval according to Reprovider.Strategy: | ||
| https://github.com/ipfs/kubo/blob/master/docs/config.md#reprovider | ||
|
|
||
| This interface is not stable and may change from release to release. | ||
|
|
||
| `, | ||
| }, | ||
| Arguments: []cmds.Argument{}, | ||
| Options: []cmds.Option{}, | ||
| Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { | ||
| nd, err := cmdenv.GetNode(env) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !nd.IsOnline { | ||
| return ErrNotOnline | ||
| } | ||
|
|
||
| stats, err := nd.Provider.Stat() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, fullRT := nd.DHTClient.(*fullrt.FullRT) | ||
|
|
||
| if err := res.Emit(reprovideStats{stats, fullRT}); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| Encoders: cmds.EncoderMap{ | ||
| cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s reprovideStats) error { | ||
| wtr := tabwriter.NewWriter(w, 1, 2, 1, ' ', 0) | ||
| defer wtr.Flush() | ||
|
|
||
| fmt.Fprintf(wtr, "TotalReprovides:\t%s\n", humanNumber(s.TotalReprovides)) | ||
| fmt.Fprintf(wtr, "AvgReprovideDuration:\t%s\n", humanDuration(s.AvgReprovideDuration)) | ||
| fmt.Fprintf(wtr, "LastReprovideDuration:\t%s\n", humanDuration(s.LastReprovideDuration)) | ||
| if !s.LastRun.IsZero() { | ||
| fmt.Fprintf(wtr, "LastReprovide:\t%s\n", humanTime(s.LastRun)) | ||
| if s.fullRT { | ||
| fmt.Fprintf(wtr, "NextReprovide:\t%s\n", humanTime(s.LastRun.Add(s.ReprovideInterval))) | ||
| } | ||
| } | ||
| return nil | ||
| }), | ||
| }, | ||
| Type: reprovideStats{}, | ||
| } | ||
|
|
||
| func humanDuration(val time.Duration) string { | ||
| return val.Truncate(time.Microsecond).String() | ||
| } | ||
|
|
||
| func humanTime(val time.Time) string { | ||
| return val.Format("2006-01-02 15:04:05") | ||
| } | ||
|
|
||
| func humanNumber[T constraints.Float | constraints.Integer](n T) string { | ||
| nf := float64(n) | ||
| str := humanSI(nf, 0) | ||
| fullStr := humanFull(nf, 0) | ||
| if str != fullStr { | ||
| return fmt.Sprintf("%s\t(%s)", str, fullStr) | ||
| } | ||
| return str | ||
| } | ||
|
|
||
| func humanSI(val float64, decimals int) string { | ||
| v, unit := humanize.ComputeSI(val) | ||
| return fmt.Sprintf("%s%s", humanFull(v, decimals), unit) | ||
| } | ||
|
|
||
| func humanFull(val float64, decimals int) string { | ||
| return humanize.CommafWithDigits(val, decimals) | ||
| } |
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: renaming field names here is a breaking change to existing command.
It will break compatibility with older RPC clients, libraries, and will also break user's scripts and automations.
Mind adding a note about this to the Changelog?
Since we have two queues, and they behave differently, I wonder if we should have
ipfs stat provideandipfs stat reprovide? (e.g. if we make breaking change anyway, any reason to not rename currentprovidetoreprovide?)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 marked
ipfs stats provideas deprecated, and renamed it toipfs stats reprovide.ipfs stats provideshows the same stats asipfs stats reprovidebut with the old names (only information related to reprovides, because we don't track provides anymore), so it shouldn't break existing scripts.