Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ endif
$(QUIET) contrib/scripts/check-xfrmstate.sh
@$(ECHO_CHECK) contrib/scripts/check-legacy-header-guard.sh
$(QUIET) contrib/scripts/check-legacy-header-guard.sh
@$(ECHO_CHECK) contrib/scripts/check-logrus.sh
$(QUIET) contrib/scripts/check-logrus.sh

pprof-heap: ## Get Go pprof heap profile.
$(QUIET)$(GO) tool pprof http://localhost:6060/debug/pprof/heap
Expand Down
29 changes: 29 additions & 0 deletions contrib/scripts/check-logrus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Copyright Authors of Cilium

set -eu

GOIMPORTS=("golang.org/x/tools/cmd/goimports" "-w")
MATCH="^\s*\"github.com/sirupsen/logrus\"$"

# File paths that have switched to slog and for which reintroducing use of logrus
# is forbidden.
CONVERTED=(
"hubble"
"pkg/hive/health"
"pkg/datapath/linux"
)

EXCLUDED_FILES=(
# pkg/datapath/linux/...
"routing.go"
)

for dir in "${CONVERTED[@]}"; do
if grep -r --include \*.go -i "$MATCH" --exclude-from=<(printf "%s\n" "${EXCLUDED_FILES[@]}") "$dir"; then
>&2 echo "Found match for '$MATCH'. Please use slog and not logrus."
>&2 echo "slog is available via Hive with type *slog.Logger"
exit 1
fi
done
2 changes: 0 additions & 2 deletions daemon/cmd/daemon_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,6 @@ func initEnv(vp *viper.Viper) {
log.WithError(err).Fatalf("BPF template directory: NOT OK. Please run 'make install-bpf'")
}

linuxdatapath.CheckRequirements()

if err := probes.CreateHeaderFiles(filepath.Join(option.Config.BpfDir, "include/bpf"), probes.ExecuteHeaderProbes()); err != nil {
log.WithError(err).Fatal("failed to create header files with feature macros")
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/datapath/cells.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package datapath

import (
"fmt"
"log"
"log/slog"
"path/filepath"

"github.com/cilium/hive/cell"
Expand Down Expand Up @@ -178,6 +180,10 @@ func newDatapath(params datapathParams) types.Datapath {

params.LC.Append(cell.Hook{
OnStart: func(cell.HookContext) error {
if err := linuxdatapath.CheckRequirements(params.Log); err != nil {
return fmt.Errorf("requirements failed: %w", err)
}

datapath.NodeIDs().RestoreNodeIDs()
return nil
},
Expand All @@ -189,6 +195,8 @@ func newDatapath(params datapathParams) types.Datapath {
type datapathParams struct {
cell.In

Log *slog.Logger

LC cell.Lifecycle
WgAgent *wg.Agent

Expand Down
31 changes: 15 additions & 16 deletions pkg/datapath/linux/bandwidth/bandwidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/asm"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/resource"

"github.com/cilium/cilium/pkg/datapath/linux/config/defines"
Expand Down Expand Up @@ -110,7 +109,7 @@ func (m *manager) probe() error {
return nil
}
if _, err := m.params.Sysctl.Read("net.core.default_qdisc"); err != nil {
m.params.Log.WithError(err).Warn("BPF bandwidth manager could not read procfs. Disabling the feature.")
m.params.Log.Warn("BPF bandwidth manager could not read procfs. Disabling the feature.", logfields.Error, err)
return nil
}
if !kernelGood {
Expand All @@ -136,7 +135,7 @@ func (m *manager) probe() error {
}

if m.params.Config.EnableBandwidthManager && m.params.DaemonConfig.EnableIPSec {
m.params.Log.Warning("The bandwidth manager cannot be used with IPSec. Disabling the bandwidth manager.")
m.params.Log.Warn("The bandwidth manager cannot be used with IPSec. Disabling the bandwidth manager.")
return nil
}

Expand Down Expand Up @@ -171,11 +170,11 @@ func setBaselineSysctls(p bandwidthManagerParams) error {
return fmt.Errorf("read sysctl %s failed: %w", name, err)
}

scopedLog := p.Log.WithFields(logrus.Fields{
logfields.SysParamName: name,
logfields.SysParamValue: currentValue,
"baselineValue": value,
})
scopedLog := p.Log.With(
logfields.SysParamName, name,
logfields.SysParamValue, currentValue,
"baselineValue", value,
)

if currentValue >= value {
scopedLog.Info("Skip setting sysctl as it already meets baseline")
Expand All @@ -200,10 +199,10 @@ func setBaselineSysctls(p bandwidthManagerParams) error {
}

for name, value := range baseStringSettings {
p.Log.WithFields(logrus.Fields{
logfields.SysParamName: name,
"baselineValue": value,
}).Info("Setting sysctl to baseline for BPF bandwidth manager")
p.Log.Info("Setting sysctl to baseline for BPF bandwidth manager",
logfields.SysParamName, name,
"baselineValue", value,
)

if err := p.Sysctl.Write(name, value); err != nil {
return fmt.Errorf("set sysctl %s=%s failed: %w", name, value, err)
Expand All @@ -219,10 +218,10 @@ func setBaselineSysctls(p bandwidthManagerParams) error {
// also provides the right kernel dependency implicitly as well.
if p.Config.EnableBBR {
for name, value := range extraSettings {
p.Log.WithFields(logrus.Fields{
logfields.SysParamName: name,
"baselineValue": value,
}).Info("Setting sysctl to baseline for BPF bandwidth manager")
p.Log.Info("Setting sysctl to baseline for BPF bandwidth manager",
logfields.SysParamName, name,
"baselineValue", value,
)

if err := p.Sysctl.WriteInt(name, value); err != nil {
return fmt.Errorf("set sysctl %s=%d failed: %w", name, value, err)
Expand Down
7 changes: 4 additions & 3 deletions pkg/datapath/linux/bandwidth/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
package bandwidth

import (
"log/slog"

"github.com/cilium/hive/cell"
"github.com/cilium/statedb"
"github.com/cilium/statedb/reconciler"
"github.com/sirupsen/logrus"

"github.com/cilium/cilium/pkg/datapath/linux/config/defines"
"github.com/cilium/cilium/pkg/datapath/linux/sysctl"
Expand All @@ -37,7 +38,7 @@ var Cell = cell.Module(
cell.Invoke(registerReconciler),
)

func newReconcilerConfig(log logrus.FieldLogger, tbl statedb.RWTable[*tables.BandwidthQDisc], bwm types.BandwidthManager) reconciler.Config[*tables.BandwidthQDisc] {
func newReconcilerConfig(log *slog.Logger, tbl statedb.RWTable[*tables.BandwidthQDisc], bwm types.BandwidthManager) reconciler.Config[*tables.BandwidthQDisc] {
return reconciler.Config[*tables.BandwidthQDisc]{
Table: tbl,
FullReconcilationInterval: 10 * time.Minute,
Expand Down Expand Up @@ -79,7 +80,7 @@ func (*manager) Stop(cell.HookContext) error {
type bandwidthManagerParams struct {
cell.In

Log logrus.FieldLogger
Log *slog.Logger
Config types.BandwidthConfig
DaemonConfig *option.DaemonConfig
Sysctl sysctl.Sysctl
Expand Down
11 changes: 5 additions & 6 deletions pkg/datapath/linux/bandwidth/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ package bandwidth
import (
"context"
"fmt"

"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"log/slog"

"github.com/cilium/statedb"
"github.com/cilium/statedb/reconciler"
"github.com/vishvananda/netlink"

"github.com/cilium/cilium/pkg/datapath/tables"
"github.com/cilium/cilium/pkg/datapath/types"
)

type ops struct {
log logrus.FieldLogger
log *slog.Logger
isEnabled func() bool
}

func newOps(log logrus.FieldLogger, mgr types.BandwidthManager) reconciler.Operations[*tables.BandwidthQDisc] {
func newOps(log *slog.Logger, mgr types.BandwidthManager) reconciler.Operations[*tables.BandwidthQDisc] {
return &ops{log, mgr.Enabled}
}

Expand Down Expand Up @@ -110,7 +109,7 @@ func (ops *ops) Update(ctx context.Context, txn statedb.ReadTxn, q *tables.Bandw
}
which = "fq"
}
ops.log.WithField("device", device).Infof("Setting qdisc to %s", which)
ops.log.Info("Setting qdisc", "qdisc", which, "device", device)

// Set the fq parameters
qdiscs, err = netlink.QdiscList(link)
Expand Down
5 changes: 3 additions & 2 deletions pkg/datapath/linux/bandwidth/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
"github.com/stretchr/testify/require"
"github.com/vishvananda/netlink"

"github.com/cilium/hive/hivetest"
"github.com/cilium/statedb/reconciler"

"github.com/cilium/cilium/pkg/datapath/tables"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/testutils"
"github.com/cilium/cilium/pkg/testutils/netns"
)

func TestOps(t *testing.T) {
testutils.PrivilegedTest(t)
log := hivetest.Logger(t)

var nlh *netlink.Handle
var err error
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestOps(t *testing.T) {
require.Equal(t, "noqueue", qdiscs[0].Type()) // the default for dummys

ops := &ops{
log: logging.DefaultLogger,
log: log,
isEnabled: func() bool { return true },
}
ctx := context.TODO()
Expand Down
Loading