Skip to content

Commit

Permalink
Merge pull request #483 from bfforever/kmesh-bugfix703
Browse files Browse the repository at this point in the history
Fix bpfloglevel update error bug in Ads mode.
  • Loading branch information
kmesh-bot authored Jul 5, 2024
2 parents 4674b1f + bb4419d commit c78488f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion daemon/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Execute(configs *options.BootstrapConfigs) error {
log.Info("controller Start successful")
defer c.Stop()

statusServer := status.NewServer(c.GetXdsClient(), configs, bpfLoader.GetBpfKmeshWorkload())
statusServer := status.NewServer(c.GetXdsClient(), configs, bpfLoader.GetBpfLogLevel())
statusServer.StartServer()
defer func() {
_ = statusServer.StopServer()
Expand Down
9 changes: 9 additions & 0 deletions pkg/bpf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type BpfLoader struct {

obj *BpfKmesh
workloadObj *BpfKmeshWorkload
bpfLogLevel *ebpf.Map
}

func NewBpfLoader(config *options.BpfConfig) *BpfLoader {
Expand Down Expand Up @@ -80,6 +81,7 @@ func (l *BpfLoader) StartAdsMode() (err error) {
return fmt.Errorf("api env config failed, %s", err)
}

l.bpfLogLevel = l.obj.SockConn.BpfLogLevel
ret := C.deserial_init()
if ret != 0 {
l.Stop()
Expand Down Expand Up @@ -133,6 +135,13 @@ func (l *BpfLoader) GetBpfKmeshWorkload() *BpfKmeshWorkload {
return l.workloadObj
}

func (l *BpfLoader) GetBpfLogLevel() *ebpf.Map {
if l == nil {
return nil
}
return l.bpfLogLevel
}

func StopMda() error {
cmd := exec.Command("mdacore", "disable")
output, err := cmd.CombinedOutput()
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/bpf_kmesh_l4_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (l *BpfLoader) StartWorkloadMode() error {
l.Stop()
return fmt.Errorf("bpf Attach failed, %s", err)
}

l.bpfLogLevel = l.workloadObj.SockConn.BpfLogLevel
return nil
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/status/status_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
adminv2 "kmesh.net/kmesh/api/v2/admin"
"kmesh.net/kmesh/api/v2/workloadapi/security"
"kmesh.net/kmesh/daemon/options"
"kmesh.net/kmesh/pkg/bpf"
"kmesh.net/kmesh/pkg/constants"
"kmesh.net/kmesh/pkg/controller"
"kmesh.net/kmesh/pkg/controller/ads"
Expand Down Expand Up @@ -64,7 +63,7 @@ type Server struct {
xdsClient *controller.XdsClient
mux *http.ServeMux
server *http.Server
bpfWorkloadObj *bpf.BpfKmeshWorkload
bpfLogLevelMap *ebpf.Map
}

func GetConfigDumpAddr(mode string) string {
Expand All @@ -75,12 +74,12 @@ func GetLoggerURL() string {
return "http://" + adminAddr + patternLoggers
}

func NewServer(c *controller.XdsClient, configs *options.BootstrapConfigs, bpfWorkloadObj *bpf.BpfKmeshWorkload) *Server {
func NewServer(c *controller.XdsClient, configs *options.BootstrapConfigs, bpfLogLevel *ebpf.Map) *Server {
s := &Server{
config: configs,
xdsClient: c,
mux: http.NewServeMux(),
bpfWorkloadObj: bpfWorkloadObj,
bpfLogLevelMap: bpfLogLevel,
}
s.server = &http.Server{
Addr: adminAddr,
Expand Down Expand Up @@ -295,7 +294,11 @@ func (s *Server) bpfLogLevel(w http.ResponseWriter, r *http.Request) {
}
key := uint32(0)
levelPtr := uint32(level)
if err := s.bpfWorkloadObj.SockConn.BpfLogLevel.Update(&key, &levelPtr, ebpf.UpdateAny); err != nil {
if s.bpfLogLevelMap == nil {
http.Error(w, fmt.Errorf("update log level error:%v", "bpfLogLevelMap is nil").Error(), http.StatusBadRequest)
return
}
if err := s.bpfLogLevelMap.Update(&key, &levelPtr, ebpf.UpdateAny); err != nil {
http.Error(w, fmt.Errorf("update log level error:%v", err).Error(), http.StatusBadRequest)
return
}
Expand Down

0 comments on commit c78488f

Please sign in to comment.