@cryptotaxi247 / kubo / commits / a35dd2ea0

ci: preload peerlog plugin, disable by default

This preloads the peerlog plugin in the ipfs binary, but keeps it disabled by default. To enabled it, set Enabled=true in its config. The motivation is to simplify building and deploying gateways, and for them to use binaries that are more similar to release bins.

guseggert committed Aug 23, 2021 at 21:44 UTC a35dd2ea0d0493f1d7524a70f2d414d51523efe9
5 files changed +80 -2
plugin/loader/preload.go
+2
@@ -5,6 +5,7 @@ import (
5 pluginflatfs "github.com/ipfs/go-ipfs/plugin/plugins/flatfs"
6 pluginipldgit "github.com/ipfs/go-ipfs/plugin/plugins/git"
7 pluginlevelds "github.com/ipfs/go-ipfs/plugin/plugins/levelds"
8 + pluginpeerlog "github.com/ipfs/go-ipfs/plugin/plugins/peerlog"
9 )
10
11 // DO NOT EDIT THIS FILE
@@ -16,4 +17,5 @@ func init() {
17 Preload(pluginbadgerds.Plugins...)
18 Preload(pluginflatfs.Plugins...)
19 Preload(pluginlevelds.Plugins...)
20 + Preload(pluginpeerlog.Plugins...)
21 }
plugin/loader/preload_list
+1
@@ -8,3 +8,4 @@ ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git *
8 badgerds github.com/ipfs/go-ipfs/plugin/plugins/badgerds *
9 flatfs github.com/ipfs/go-ipfs/plugin/plugins/flatfs *
10 levelds github.com/ipfs/go-ipfs/plugin/plugins/levelds *
11 +peerlog github.com/ipfs/go-ipfs/plugin/plugins/peerlog *
\ No newline at end of file
plugin/plugins/Rules.mk
+1 -1
@@ -1,6 +1,6 @@
1 include mk/header.mk
2
3 -$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds
3 +$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds $(d)/peerlog
4 $(d)_plugins_so:=$(addsuffix .so,$($(d)_plugins))
5 $(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins))
6
plugin/plugins/peerlog/peerlog.go
+23 -1
@@ -45,6 +45,7 @@ type plEvent struct {
45 // {"level":"info","ts":"2020-02-10T13:54:59.095Z","logger":"plugin/peerlog","caller":"peerlog/peerlog.go:56","msg":"identified","peer":"QmS2H72gdrekXJggGdE9SunXPntBqdkJdkXQJjuxcH8Cbt","agent":"go-ipfs/0.5.0/"}
46 //
47 type peerLogPlugin struct {
48 + enabled bool
49 droppedCount uint64
50 events chan plEvent
51 }
@@ -67,8 +68,25 @@ func (*peerLogPlugin) Version() string {
68 }
69
70 // Init initializes plugin
70 -func (pl *peerLogPlugin) Init(*plugin.Environment) error {
71 +func (pl *peerLogPlugin) Init(env *plugin.Environment) error {
72 pl.events = make(chan plEvent, eventQueueSize)
73 +
74 + // plugin is disabled by default, unless Enabled=true
75 + if env.Config != nil {
76 + mapIface, ok := env.Config.(map[string]interface{})
77 + if !ok {
78 + return nil
79 + }
80 + enabledIface, ok := mapIface["Enabled"]
81 + if !ok || enabledIface == nil {
82 + return nil
83 + }
84 + enabled, ok := enabledIface.(bool)
85 + if !ok {
86 + return nil
87 + }
88 + pl.enabled = enabled
89 + }
90 return nil
91 }
92
@@ -153,6 +171,10 @@ func (pl *peerLogPlugin) emit(evt eventType, p peer.ID) {
171 }
172
173 func (pl *peerLogPlugin) Start(node *core.IpfsNode) error {
174 + if !pl.enabled {
175 + return nil
176 + }
177 +
178 // Ensure logs from this plugin get printed regardless of global IPFS_LOGGING value
179 if err := logging.SetLogLevel("plugin/peerlog", "info"); err != nil {
180 return fmt.Errorf("failed to set log level: %w", err)
test/sharness/t0280-plugin-peerlog.sh new
+53
@@ -0,0 +1,53 @@
1 +#!/usr/bin/env bash
2 +#
3 +# Copyright (c) 2017 Jakub Sztandera
4 +# MIT Licensed; see the LICENSE file in this repository.
5 +#
6 +
7 +test_description="Test peerlog plugin"
8 +
9 +. lib/test-lib.sh
10 +
11 +test_expect_success "setup testbed" '
12 + iptb testbed create -type localipfs -count 2 -force -init
13 +'
14 +
15 +startup_cluster 2
16 +
17 +test_expect_success "peerlog is disabled by default" '
18 + go-sleep 100ms
19 + iptb logs 0 >node0logs
20 + test_expect_code 1 grep peerlog node0logs
21 +'
22 +
23 +test_expect_success 'stop iptb' 'iptb stop'
24 +
25 +
26 +
27 +test_expect_success "setup testbed" '
28 + iptb testbed create -type localipfs -count 2 -force -init
29 +'
30 +
31 +test_expect_success "enable peerlog config setting" '
32 + iptb run -- ipfs config --json Plugins.Plugins.peerlog.Config.Enabled true
33 +'
34 +
35 +startup_cluster 2
36 +
37 +test_expect_success "peerlog plugin is logged" '
38 + go-sleep 100ms
39 + iptb logs 0 >node0logs
40 + grep peerlog node0logs
41 +'
42 +
43 +test_expect_success 'peer id' '
44 + PEERID_1=$(iptb attr get 1 id)
45 +'
46 +
47 +test_expect_success "peer id is logged" '
48 + iptb logs 0 | grep -q "$PEERID_1"
49 +'
50 +
51 +test_expect_success 'stop iptb' 'iptb stop'
52 +
53 +test_done