Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize memory profile of file storage #89

Merged
merged 7 commits into from
Jan 18, 2024
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
22 changes: 15 additions & 7 deletions pkg/apis/softwarecomposition/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,24 @@ type ApplicationProfile struct {
}

type ApplicationProfileSpec struct {
Containers []ApplicationProfileContainer `json:"containers,omitempty"`
InitContainers []ApplicationProfileContainer `json:"initContainers,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Containers []ApplicationProfileContainer `json:"containers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
// +patchMergeKey=name
// +patchStrategy=merge
InitContainers []ApplicationProfileContainer `json:"initContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

type ApplicationProfileContainer struct {
Name string `json:"name,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
Execs []ExecCalls `json:"execs,omitempty"`
Opens []OpenCalls `json:"opens,omitempty"`
Syscalls []string `json:"syscalls,omitempty"`
Name string `json:"name,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
// +patchMergeKey=path
// +patchStrategy=merge
Execs []ExecCalls `json:"execs,omitempty" patchStrategy:"merge" patchMergeKey:"path"`
// +patchMergeKey=path
// +patchStrategy=merge
Opens []OpenCalls `json:"opens,omitempty" patchStrategy:"merge" patchMergeKey:"path"`
Syscalls []string `json:"syscalls,omitempty"`
}

type ExecCalls struct {
Expand Down
32 changes: 32 additions & 0 deletions pkg/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ package server

import (
"fmt"
"github.com/kubescape/go-logger/helpers"
"io"
"net"
"net/http"
"net/http/pprof"

"github.com/kubescape/go-logger"
"github.com/kubescape/storage/pkg/admission/wardleinitializer"
Expand Down Expand Up @@ -98,6 +101,13 @@ func NewCommandStartWardleServer(defaults *WardleServerOptions, stopCh <-chan st
o.RecommendedOptions.AddFlags(flags)
utilfeature.DefaultMutableFeatureGate.AddFlag(flags)

// replace built-in profiling with pprof on port 6060
err := flags.Set("profiling", "false")
if err != nil {
logger.L().Warning("failed to set profiling flag to false", helpers.Error(err))
}
servePprof()

// mute klog
// https://github.com/kubernetes/klog/issues/87
// klog.SetLogger(logr.Discard())
Expand Down Expand Up @@ -178,3 +188,25 @@ func (o WardleServerOptions) RunWardleServer(stopCh <-chan struct{}) error {

return server.GenericAPIServer.PrepareRun().Run(stopCh)
}

func servePprof() {
if logger.L().GetLevel() == helpers.DebugLevel.String() {
logger.L().Info("starting pprof server", helpers.String("port", "6060"))
pprofMux := http.NewServeMux()
pprofMux.HandleFunc("/debug/pprof/", pprof.Index)
pprofMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
pprofMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
pprofMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
pprofMux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
pprofMux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
pprofMux.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
pprofMux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
pprofMux.Handle("/debug/pprof/block", pprof.Handler("block"))
pprofMux.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
go func() {
if err := http.ListenAndServe(":6060", pprofMux); err != nil {
logger.L().Error("failed to start pprof server", helpers.Error(err))
}
}()
}
}
24 changes: 24 additions & 0 deletions pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading