Skip to content

Commit 5d148b8

Browse files
address review
1 parent cc02022 commit 5d148b8

File tree

6 files changed

+138
-53
lines changed

6 files changed

+138
-53
lines changed

config/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const (
55
)
66

77
type Provider struct {
8-
Strategy string // Which keys to announce
9-
WorkerCount OptionalInteger // Number of concurrent provides allowed, 0 means unlimited
8+
Strategy string // Which keys to announce
9+
WorkerCount *OptionalInteger `json:",omitempty"` // Number of concurrent provides allowed, 0 means unlimited
1010
}

core/commands/stat.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ for your IPFS node.`,
2727
},
2828

2929
Subcommands: map[string]*cmds.Command{
30-
"bw": statBwCmd,
31-
"repo": repoStatCmd,
32-
"bitswap": bitswapStatCmd,
33-
"dht": statDhtCmd,
34-
"provide": statProvideCmd,
30+
"bw": statBwCmd,
31+
"repo": repoStatCmd,
32+
"bitswap": bitswapStatCmd,
33+
"dht": statDhtCmd,
34+
"provide": statProvideCmd,
35+
"reprovide": statReprovideCmd,
3536
},
3637
}
3738

core/commands/stat_provide.go

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@ import (
44
"fmt"
55
"io"
66
"text/tabwriter"
7-
"time"
87

9-
humanize "github.com/dustin/go-humanize"
10-
"github.com/ipfs/boxo/provider"
118
cmds "github.com/ipfs/go-ipfs-cmds"
129
"github.com/ipfs/kubo/core/commands/cmdenv"
1310
"github.com/libp2p/go-libp2p-kad-dht/fullrt"
14-
"golang.org/x/exp/constraints"
1511
)
1612

17-
type reprovideStats struct {
18-
provider.ReproviderStats
19-
fullRT bool
20-
}
21-
2213
var statProvideCmd = &cmds.Command{
14+
Status: cmds.Deprecated,
2315
Helptext: cmds.HelpText{
24-
Tagline: "Returns statistics about the node's (re)provider system.",
16+
Tagline: "Deprecated command to get provider+reprovider statistics. Use 'ipfs stats reprovide' instead.",
2517
ShortDescription: `
26-
Returns statistics about the content the node is advertising.
27-
28-
This interface is not stable and may change from release to release.
18+
'ipfs stats provide' is depreacted because provide and reprovide operations are now distinct.
19+
This command may be replaced by provide only stats in the future.
2920
`,
3021
},
3122
Arguments: []cmds.Argument{},
@@ -57,44 +48,17 @@ This interface is not stable and may change from release to release.
5748
wtr := tabwriter.NewWriter(w, 1, 2, 1, ' ', 0)
5849
defer wtr.Flush()
5950

60-
fmt.Fprintf(wtr, "TotalReprovides:\t%s\n", humanNumber(s.TotalReprovides))
61-
fmt.Fprintf(wtr, "AvgReprovideDuration:\t%s\n", humanDuration(s.AvgReprovideDuration))
51+
fmt.Fprintf(wtr, "TotalProvides:\t%s\n", humanNumber(s.TotalReprovides))
52+
fmt.Fprintf(wtr, "AvgProvideDuration:\t%s\n", humanDuration(s.AvgReprovideDuration))
6253
fmt.Fprintf(wtr, "LastReprovideDuration:\t%s\n", humanDuration(s.LastReprovideDuration))
6354
if !s.LastRun.IsZero() {
64-
fmt.Fprintf(wtr, "LastReprovide:\t%s\n", humanTime(s.LastRun))
55+
fmt.Fprintf(wtr, "LastRun:\t%s\n", humanTime(s.LastRun))
6556
if s.fullRT {
66-
fmt.Fprintf(wtr, "NextReprovide:\t%s\n", humanTime(s.LastRun.Add(s.ReprovideInterval)))
57+
fmt.Fprintf(wtr, "NextRun:\t%s\n", humanTime(s.LastRun.Add(s.ReprovideInterval)))
6758
}
6859
}
6960
return nil
7061
}),
7162
},
7263
Type: reprovideStats{},
7364
}
74-
75-
func humanDuration(val time.Duration) string {
76-
return val.Truncate(time.Microsecond).String()
77-
}
78-
79-
func humanTime(val time.Time) string {
80-
return val.Format("2006-01-02 15:04:05")
81-
}
82-
83-
func humanNumber[T constraints.Float | constraints.Integer](n T) string {
84-
nf := float64(n)
85-
str := humanSI(nf, 0)
86-
fullStr := humanFull(nf, 0)
87-
if str != fullStr {
88-
return fmt.Sprintf("%s\t(%s)", str, fullStr)
89-
}
90-
return str
91-
}
92-
93-
func humanSI(val float64, decimals int) string {
94-
v, unit := humanize.ComputeSI(val)
95-
return fmt.Sprintf("%s%s", humanFull(v, decimals), unit)
96-
}
97-
98-
func humanFull(val float64, decimals int) string {
99-
return humanize.CommafWithDigits(val, decimals)
100-
}

core/commands/stat_reprovide.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"text/tabwriter"
7+
"time"
8+
9+
humanize "github.com/dustin/go-humanize"
10+
"github.com/ipfs/boxo/provider"
11+
cmds "github.com/ipfs/go-ipfs-cmds"
12+
"github.com/ipfs/kubo/core/commands/cmdenv"
13+
"github.com/libp2p/go-libp2p-kad-dht/fullrt"
14+
"golang.org/x/exp/constraints"
15+
)
16+
17+
type reprovideStats struct {
18+
provider.ReproviderStats
19+
fullRT bool
20+
}
21+
22+
var statReprovideCmd = &cmds.Command{
23+
Helptext: cmds.HelpText{
24+
Tagline: "Returns statistics about the node's reprovider system.",
25+
ShortDescription: `
26+
Returns statistics about the content the node is reproviding.
27+
28+
This interface is not stable and may change from release to release.
29+
`,
30+
},
31+
Arguments: []cmds.Argument{},
32+
Options: []cmds.Option{},
33+
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
34+
nd, err := cmdenv.GetNode(env)
35+
if err != nil {
36+
return err
37+
}
38+
39+
if !nd.IsOnline {
40+
return ErrNotOnline
41+
}
42+
43+
stats, err := nd.Provider.Stat()
44+
if err != nil {
45+
return err
46+
}
47+
_, fullRT := nd.DHTClient.(*fullrt.FullRT)
48+
49+
if err := res.Emit(reprovideStats{stats, fullRT}); err != nil {
50+
return err
51+
}
52+
53+
return nil
54+
},
55+
Encoders: cmds.EncoderMap{
56+
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s reprovideStats) error {
57+
wtr := tabwriter.NewWriter(w, 1, 2, 1, ' ', 0)
58+
defer wtr.Flush()
59+
60+
fmt.Fprintf(wtr, "TotalReprovides:\t%s\n", humanNumber(s.TotalReprovides))
61+
fmt.Fprintf(wtr, "AvgReprovideDuration:\t%s\n", humanDuration(s.AvgReprovideDuration))
62+
fmt.Fprintf(wtr, "LastReprovideDuration:\t%s\n", humanDuration(s.LastReprovideDuration))
63+
if !s.LastRun.IsZero() {
64+
fmt.Fprintf(wtr, "LastReprovide:\t%s\n", humanTime(s.LastRun))
65+
if s.fullRT {
66+
fmt.Fprintf(wtr, "NextReprovide:\t%s\n", humanTime(s.LastRun.Add(s.ReprovideInterval)))
67+
}
68+
}
69+
return nil
70+
}),
71+
},
72+
Type: reprovideStats{},
73+
}
74+
75+
func humanDuration(val time.Duration) string {
76+
return val.Truncate(time.Microsecond).String()
77+
}
78+
79+
func humanTime(val time.Time) string {
80+
return val.Format("2006-01-02 15:04:05")
81+
}
82+
83+
func humanNumber[T constraints.Float | constraints.Integer](n T) string {
84+
nf := float64(n)
85+
str := humanSI(nf, 0)
86+
fullStr := humanFull(nf, 0)
87+
if str != fullStr {
88+
return fmt.Sprintf("%s\t(%s)", str, fullStr)
89+
}
90+
return str
91+
}
92+
93+
func humanSI(val float64, decimals int) string {
94+
v, unit := humanize.ComputeSI(val)
95+
return fmt.Sprintf("%s%s", humanFull(v, decimals), unit)
96+
}
97+
98+
func humanFull(val float64, decimals int) string {
99+
return humanize.CommafWithDigits(val, decimals)
100+
}

docs/changelogs/v0.35.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ This release was brought to you by the [Shipyard](http://ipshipyard.com/) team.
1717
- [New `ipfs add` Options](#new-ipfs-add-options)
1818
- [Persistent `Import.*` Configuration](#persistent-import-configuration)
1919
- [Updated Configuration Profiles](#updated-configuration-profiles)
20-
- [Provide Regression Fix](#provide-regression-fix)
20+
- [Optimized, dedicated queue for providing fresh CIDs](#optimized-dedicated-queue-for-providing-fresh-cids)
21+
- [Deprecated `ipfs stats provider`](#deprecated-ipfs-stats-provider)
2122
- [📦️ Important dependency updates](#-important-dependency-updates)
2223
- [📝 Changelog](#-changelog)
2324
- [👨‍👩‍👧‍👦 Contributors](#-contributors)
@@ -82,7 +83,7 @@ The release updated configuration [profiles](https://github.com/ipfs/kubo/blob/m
8283
> [!TIP]
8384
> Apply one of CIDv1 test [profiles](https://github.com/ipfs/kubo/blob/master/docs/config.md#profiles) with `ipfs config profile apply test-cid-v1[-wide]`.
8485
85-
#### Provide Regression Fix
86+
#### Optimized, dedicated queue for providing fresh CIDs
8687

8788
From `kubo` [`v0.33.0`](https://github.com/ipfs/kubo/releases/tag/v0.33.0),
8889
Bitswap stopped advertising newly added and received blocks to the DHT. Since
@@ -101,6 +102,19 @@ concurrent provide operations:
101102
> Users who need to provide large volumes of content immediately should
102103
> consider removing the cap on concurrent provide operations.
103104
105+
##### Deprecated `ipfs stats provider`
106+
107+
Since the `ipfs stats provider` command was displaying statistics for both
108+
provides and reprovides, this command isn't relevant anymore after separating
109+
the two queues.
110+
111+
The successor command is `ipfs stats reprovide`, showing the same statistics,
112+
but for reprovides only.
113+
114+
`ipfs stats provider` still works, but is marked as deprecated and will be
115+
removed in a future release. It provides only statistics about reprovides
116+
(similar to `ipfs stats reprovide`).
117+
104118
#### 📦️ Important dependency updates
105119

106120
- update `ipfs-webui` to [v4.7.0](https://github.com/ipfs/ipfs-webui/releases/tag/v4.7.0)

docs/config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,12 @@ Type: `duration`
14081408

14091409
## `Provider`
14101410

1411+
Configuration applied to the initial one-time announcement of fresh CIDs
1412+
created with `ipfs add`, `ipfs files`, `ipfs dag import`, `ipfs block|dag put`
1413+
commands.
1414+
1415+
For periodical DHT reprovide settings, see [`Reprovide.*`](#reprovider).
1416+
14111417
### `Provider.WorkerCount`
14121418

14131419
Sets the maximum number of _concurrent_ DHT provide operations. DHT reprovides

0 commit comments

Comments
 (0)