Skip to content

Commit b3973fa

Browse files
gammazerolidel
andauthored
refactor: make datastore metrics opt-in (#10788)
* datastore: metrics optional and off by default When ipfs is initialized, the datastore metrics wrapper is not configured by default as it previously was. To enable datastore metrics during initialization, specifying the appropriate `--profile` option. To enable datastore metrics tracking wrapper, initialize with datastore profile name + "-measure" suffix. For example: ``` ipfs init --profile flatfs-measure ``` Closes #10767 * fix sharness tests for new datastore dafaults * Add sharness test to check metrics added by flatfs-measure profile * Document updated metrics in changelog * update config doc with new profiles * docs(changelog): separate section * initialize non-measure pebbleds with FormatMajorVersion config * docs: fix typos, add docs link --------- Co-authored-by: gammazero <[email protected]> Co-authored-by: Marcin Rataj <[email protected]>
1 parent de16861 commit b3973fa

File tree

9 files changed

+341
-163
lines changed

9 files changed

+341
-163
lines changed

config/init.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ func DefaultDatastoreConfig() Datastore {
141141
}
142142

143143
func pebbleSpec() map[string]interface{} {
144+
return map[string]interface{}{
145+
"type": "pebbleds",
146+
"prefix": "pebble.datastore",
147+
"path": "pebbleds",
148+
"formatMajorVersion": int(pebble.FormatNewest),
149+
}
150+
}
151+
152+
func pebbleSpecMeasure() map[string]interface{} {
144153
return map[string]interface{}{
145154
"type": "measure",
146155
"prefix": "pebble.datastore",
@@ -153,6 +162,16 @@ func pebbleSpec() map[string]interface{} {
153162
}
154163

155164
func badgerSpec() map[string]interface{} {
165+
return map[string]interface{}{
166+
"type": "badgerds",
167+
"prefix": "badger.datastore",
168+
"path": "badgerds",
169+
"syncWrites": false,
170+
"truncate": true,
171+
}
172+
}
173+
174+
func badgerSpecMeasure() map[string]interface{} {
156175
return map[string]interface{}{
157176
"type": "measure",
158177
"prefix": "badger.datastore",
@@ -166,6 +185,29 @@ func badgerSpec() map[string]interface{} {
166185
}
167186

168187
func flatfsSpec() map[string]interface{} {
188+
return map[string]interface{}{
189+
"type": "mount",
190+
"mounts": []interface{}{
191+
map[string]interface{}{
192+
"mountpoint": "/blocks",
193+
"type": "flatfs",
194+
"prefix": "flatfs.datastore",
195+
"path": "blocks",
196+
"sync": false,
197+
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
198+
},
199+
map[string]interface{}{
200+
"mountpoint": "/",
201+
"type": "levelds",
202+
"prefix": "leveldb.datastore",
203+
"path": "datastore",
204+
"compression": "none",
205+
},
206+
},
207+
}
208+
}
209+
210+
func flatfsSpecMeasure() map[string]interface{} {
169211
return map[string]interface{}{
170212
"type": "mount",
171213
"mounts": []interface{}{

config/profile.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ NOTE: This profile may only be applied when first initializing node at IPFS_PATH
150150
return nil
151151
},
152152
},
153+
"flatfs-measure": {
154+
Description: `Configures the node to use the flatfs datastore with metrics tracking wrapper.
155+
Additional '*_datastore_*' metrics will be exposed on /debug/metrics/prometheus
156+
157+
NOTE: This profile may only be applied when first initializing node at IPFS_PATH
158+
via 'ipfs init --profile flatfs-measure'
159+
`,
160+
161+
InitOnly: true,
162+
Transform: func(c *Config) error {
163+
c.Datastore.Spec = flatfsSpecMeasure()
164+
return nil
165+
},
166+
},
153167
"pebbleds": {
154168
Description: `Configures the node to use the pebble high-performance datastore.
155169
@@ -176,6 +190,20 @@ NOTE: This profile may only be applied when first initializing node at IPFS_PATH
176190
return nil
177191
},
178192
},
193+
"pebbleds-measure": {
194+
Description: `Configures the node to use the pebble datastore with metrics tracking wrapper.
195+
Additional '*_datastore_*' metrics will be exposed on /debug/metrics/prometheus
196+
197+
NOTE: This profile may only be applied when first initializing node at IPFS_PATH
198+
via 'ipfs init --profile pebbleds-measure'
199+
`,
200+
201+
InitOnly: true,
202+
Transform: func(c *Config) error {
203+
c.Datastore.Spec = pebbleSpecMeasure()
204+
return nil
205+
},
206+
},
179207
"badgerds": {
180208
Description: `Configures the node to use the legacy badgerv1 datastore.
181209
@@ -205,6 +233,20 @@ NOTE: This profile may only be applied when first initializing node at IPFS_PATH
205233
return nil
206234
},
207235
},
236+
"badgerds-measure": {
237+
Description: `Configures the node to use the legacy badgerv1 datastore with metrics wrapper.
238+
Additional '*_datastore_*' metrics will be exposed on /debug/metrics/prometheus
239+
240+
NOTE: This profile may only be applied when first initializing node at IPFS_PATH
241+
via 'ipfs init --profile badgerds-measure'
242+
`,
243+
244+
InitOnly: true,
245+
Transform: func(c *Config) error {
246+
c.Datastore.Spec = badgerSpecMeasure()
247+
return nil
248+
},
249+
},
208250
"lowpower": {
209251
Description: `Reduces daemon overhead on the system. May affect node
210252
functionality - performance of content discovery and data

docs/changelogs/v0.35.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This release was brought to you by the [Shipyard](http://ipshipyard.com/) team.
1616
- [Enhanced DAG-Shaping Controls for `ipfs add`](#enhanced-dag-shaping-controls-for-ipfs-add)
1717
- [New `ipfs add` Options](#new-ipfs-add-options)
1818
- [Persistent `Import.*` Configuration](#persistent-import-configuration)
19-
- [Updated Configuration Profiles](#updated-configuration-profiles)
19+
- [Updated `Import` Profiles](#updated-import-profiles)
20+
- [`Datastore` Metrics Now Opt-In](#datastore-metrics-now-opt-in)
2021
- [Optimized, dedicated queue for providing fresh CIDs](#optimized-dedicated-queue-for-providing-fresh-cids)
2122
- [Deprecated `ipfs stats provider`](#deprecated-ipfs-stats-provider)
2223
- [Pebble Database Format Config](#pebble-database-format-config)
@@ -74,7 +75,7 @@ You can set default values for these options using the following configuration s
7475
- [`Import.UnixFSHAMTDirectoryMaxFanout`](https://github.com/ipfs/kubo/blob/master/docs/config.md#importunixfshamtdirectorymaxfanout)
7576
- [`Import.UnixFSHAMTDirectorySizeThreshold`](https://github.com/ipfs/kubo/blob/master/docs/config.md#importunixfshamtdirectorysizethreshold)
7677

77-
##### Updated Configuration Profiles
78+
##### Updated `Import` Profiles
7879

7980
The release updated configuration [profiles](https://github.com/ipfs/kubo/blob/master/docs/config.md#profiles) to incorporate these new `Import.*` settings:
8081
- Updated Profile: `test-cid-v1` now includes current defaults as explicit `Import.UnixFSFileMaxLinks=174`, `Import.UnixFSDirectoryMaxLinks=0`, `Import.UnixFSHAMTDirectoryMaxFanout=256` and `Import.UnixFSHAMTDirectorySizeThreshold=256KiB`
@@ -84,6 +85,15 @@ The release updated configuration [profiles](https://github.com/ipfs/kubo/blob/m
8485
> [!TIP]
8586
> 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]`.
8687
88+
#### `Datastore` Metrics Now Opt-In
89+
90+
To reduce overhead in the default configuration, datastore metrics are no longer enabled by default when initializing a Kubo repository with `ipfs init`.
91+
Metrics prefixed with `<dsname>_datastore` (e.g., `flatfs_datastore_...`, `leveldb_datastore_...`) are not exposed unless explicitly enabled. For a complete list of affected default metrics, refer to [`prometheus_metrics_added_by_measure_profile`](https://github.com/ipfs/kubo/blob/master/test/sharness/t0119-prometheus-data/prometheus_metrics_added_by_measure_profile).
92+
93+
Convenience opt-in [profiles](https://github.com/ipfs/kubo/blob/master/docs/config.md#profiles) can be enabled at initialization time with `ipfs init --profile`: `flatfs-measure`, `pebbleds-measure`, `badgerds-measure`
94+
95+
It is also possible to manually add the `measure` wrapper. See examples in [`Datastore.Spec`](https://github.com/ipfs/kubo/blob/master/docs/config.md#datastorespec) documentation.
96+
8797
#### Optimized, dedicated queue for providing fresh CIDs
8898

8999
From `kubo` [`v0.33.0`](https://github.com/ipfs/kubo/releases/tag/v0.33.0),

docs/config.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ config file at runtime.
203203
- [`local-discovery` profile](#local-discovery-profile)
204204
- [`default-networking` profile](#default-networking-profile)
205205
- [`flatfs` profile](#flatfs-profile)
206+
- [`flatfs-measure` profile](#flatfs-measure-profile)
206207
- [`pebbleds` profile](#pebbleds-profile)
208+
- [`pebbleds-measure` profile](#pebbleds-measure-profile)
207209
- [`badgerds` profile](#badgerds-profile)
210+
- [`badgerds-measure` profile](#badgerds-measure-profile)
208211
- [`lowpower` profile](#lowpower-profile)
209212
- [`announce-off` profile](#announce-off-profile)
210213
- [`announce-on` profile](#announce-on-profile)
@@ -735,6 +738,30 @@ datastores to provide extra functionality (eg metrics, logging, or caching).
735738
736739
Default:
737740
```
741+
{
742+
"mounts": [
743+
{
744+
"mountpoint": "/blocks",
745+
"path": "blocks",
746+
"prefix": "flatfs.datastore",
747+
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
748+
"sync": false,
749+
"type": "flatfs"
750+
},
751+
{
752+
"compression": "none",
753+
"mountpoint": "/",
754+
"path": "datastore",
755+
"prefix": "leveldb.datastore",
756+
"type": "levelds"
757+
}
758+
],
759+
"type": "mount"
760+
}
761+
```
762+
763+
With `flatfs-measure` profile:
764+
```
738765
{
739766
"mounts": [
740767
{
@@ -2773,9 +2800,13 @@ You should use this datastore if:
27732800
> [!NOTE]
27742801
> See caveats and configuration options at [`datastores.md#flatfs`](datastores.md#flatfs)
27752802
2803+
### `flatfs-measure` profile
2804+
2805+
Configures the node to use the flatfs datastore with metrics. This is the same as [`flatfs` profile](#flatfs-profile) with the addition of the `measure` datastore wrapper.
2806+
27762807
### `pebbleds` profile
27772808

2778-
Configures the node to use the **EXPERIMENTAL** pebble high-performance datastore.
2809+
Configures the node to use the pebble high-performance datastore.
27792810

27802811
Pebble is a LevelDB/RocksDB inspired key-value store focused on performance and internal usage by CockroachDB.
27812812
You should use this datastore if:
@@ -2793,6 +2824,10 @@ You should use this datastore if:
27932824
> [!NOTE]
27942825
> See other caveats and configuration options at [`datastores.md#pebbleds`](datastores.md#pebbleds)
27952826
2827+
### `pebbleds-measure` profile
2828+
2829+
Configures the node to use the pebble datastore with metrics. This is the same as [`pebbleds` profile](#pebble-profile) with the addition of the `measure` datastore wrapper.
2830+
27962831
### `badgerds` profile
27972832

27982833
Configures the node to use the **legacy** badgerv1 datastore.
@@ -2818,6 +2853,10 @@ Also, be aware that:
28182853
> [!NOTE]
28192854
> See other caveats and configuration options at [`datastores.md#pebbleds`](datastores.md#pebbleds)
28202855
2856+
### `badgerds-measure` profile
2857+
2858+
Configures the node to use the **legacy** badgerv1 datastore with metrics. This is the same as [`badgerds` profile](#badger-profile) with the addition of the `measure` datastore wrapper.
2859+
28212860
### `lowpower` profile
28222861

28232862
Reduces daemon overhead on the system by disabling optional swarm services.

test/sharness/lib/test-lib.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ test_init_ipfs() {
214214

215215
}
216216

217+
test_init_ipfs_measure() {
218+
args=("$@")
219+
220+
# we set the Addresses.API config variable.
221+
# the cli client knows to use it, so only need to set.
222+
# todo: in the future, use env?
223+
224+
test_expect_success "ipfs init succeeds" '
225+
export IPFS_PATH="$(pwd)/.ipfs" &&
226+
ipfs init "${args[@]}" --profile=test,flatfs-measure > /dev/null
227+
'
228+
229+
test_expect_success "prepare config -- mounting" '
230+
mkdir mountdir ipfs ipns &&
231+
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
232+
test_config_set Mounts.IPNS "$(pwd)/ipns" ||
233+
test_fsh cat "\"$IPFS_PATH/config\""
234+
'
235+
236+
}
237+
217238
test_wait_for_file() {
218239
loops=$1
219240
delay=$2

test/sharness/t0060-daemon.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_description="Test daemon command"
88

99
. lib/test-lib.sh
1010

11-
test_expect_success "create badger config" '
11+
test_expect_success "create pebble config" '
1212
ipfs init --profile=pebbleds,test > /dev/null &&
1313
cp "$IPFS_PATH/config" init-config
1414
'
@@ -21,7 +21,7 @@ test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile
2121
test_kill_ipfs_daemon
2222

2323
test_expect_success "daemon initialization with existing config works" '
24-
ipfs config "Datastore.Spec.child.path" >actual &&
24+
ipfs config "Datastore.Spec.path" >actual &&
2525
test $(cat actual) = "pebbleds" &&
2626
ipfs config Addresses > orig_addrs
2727
'

0 commit comments

Comments
 (0)