mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 20:37:53 +08:00
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.
(cherry picked from commit a35dd2ea0d)
This commit is contained in:
parent
0884f2dd70
commit
63dd43b8cd
@ -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
|
||||
@ -16,4 +17,5 @@ func init() {
|
||||
Preload(pluginbadgerds.Plugins...)
|
||||
Preload(pluginflatfs.Plugins...)
|
||||
Preload(pluginlevelds.Plugins...)
|
||||
Preload(pluginpeerlog.Plugins...)
|
||||
}
|
||||
|
||||
@ -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 *
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
53
test/sharness/t0280-plugin-peerlog.sh
Executable file
53
test/sharness/t0280-plugin-peerlog.sh
Executable file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user