Skip to content

Commit

Permalink
ci: preload peerlog plugin, disable by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guseggert committed Aug 25, 2021
1 parent 4e132af commit a35dd2e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
2 changes: 2 additions & 0 deletions plugin/loader/preload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
pluginflatfs "github.com/ipfs/go-ipfs/plugin/plugins/flatfs"
pluginipldgit "github.com/ipfs/go-ipfs/plugin/plugins/git"
pluginlevelds "github.com/ipfs/go-ipfs/plugin/plugins/levelds"
pluginpeerlog "github.com/ipfs/go-ipfs/plugin/plugins/peerlog"
)

// DO NOT EDIT THIS FILE
Expand All @@ -16,4 +17,5 @@ func init() {
Preload(pluginbadgerds.Plugins...)
Preload(pluginflatfs.Plugins...)
Preload(pluginlevelds.Plugins...)
Preload(pluginpeerlog.Plugins...)
}
1 change: 1 addition & 0 deletions plugin/loader/preload_list
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git *
badgerds github.com/ipfs/go-ipfs/plugin/plugins/badgerds *
flatfs github.com/ipfs/go-ipfs/plugin/plugins/flatfs *
levelds github.com/ipfs/go-ipfs/plugin/plugins/levelds *
peerlog github.com/ipfs/go-ipfs/plugin/plugins/peerlog *
2 changes: 1 addition & 1 deletion plugin/plugins/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include mk/header.mk

$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds
$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds $(d)/peerlog
$(d)_plugins_so:=$(addsuffix .so,$($(d)_plugins))
$(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins))

Expand Down
24 changes: 23 additions & 1 deletion plugin/plugins/peerlog/peerlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type plEvent struct {
// {"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/"}
//
type peerLogPlugin struct {
enabled bool
droppedCount uint64
events chan plEvent
}
Expand All @@ -67,8 +68,25 @@ func (*peerLogPlugin) Version() string {
}

// Init initializes plugin
func (pl *peerLogPlugin) Init(*plugin.Environment) error {
func (pl *peerLogPlugin) Init(env *plugin.Environment) error {
pl.events = make(chan plEvent, eventQueueSize)

// plugin is disabled by default, unless Enabled=true
if env.Config != nil {
mapIface, ok := env.Config.(map[string]interface{})
if !ok {
return nil
}
enabledIface, ok := mapIface["Enabled"]
if !ok || enabledIface == nil {
return nil
}
enabled, ok := enabledIface.(bool)
if !ok {
return nil
}
pl.enabled = enabled
}
return nil
}

Expand Down Expand Up @@ -153,6 +171,10 @@ func (pl *peerLogPlugin) emit(evt eventType, p peer.ID) {
}

func (pl *peerLogPlugin) Start(node *core.IpfsNode) error {
if !pl.enabled {
return nil
}

// Ensure logs from this plugin get printed regardless of global IPFS_LOGGING value
if err := logging.SetLogLevel("plugin/peerlog", "info"); err != nil {
return fmt.Errorf("failed to set log level: %w", err)
Expand Down
53 changes: 53 additions & 0 deletions test/sharness/t0280-plugin-peerlog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
# Copyright (c) 2017 Jakub Sztandera
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test peerlog plugin"

. lib/test-lib.sh

test_expect_success "setup testbed" '
iptb testbed create -type localipfs -count 2 -force -init
'

startup_cluster 2

test_expect_success "peerlog is disabled by default" '
go-sleep 100ms
iptb logs 0 >node0logs
test_expect_code 1 grep peerlog node0logs
'

test_expect_success 'stop iptb' 'iptb stop'



test_expect_success "setup testbed" '
iptb testbed create -type localipfs -count 2 -force -init
'

test_expect_success "enable peerlog config setting" '
iptb run -- ipfs config --json Plugins.Plugins.peerlog.Config.Enabled true
'

startup_cluster 2

test_expect_success "peerlog plugin is logged" '
go-sleep 100ms
iptb logs 0 >node0logs
grep peerlog node0logs
'

test_expect_success 'peer id' '
PEERID_1=$(iptb attr get 1 id)
'

test_expect_success "peer id is logged" '
iptb logs 0 | grep -q "$PEERID_1"
'

test_expect_success 'stop iptb' 'iptb stop'

test_done

0 comments on commit a35dd2e

Please sign in to comment.