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

Skip to content
Closed
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
9 changes: 9 additions & 0 deletions internal/criocli/criocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ func mergeConfig(config *libconfig.Config, ctx *cli.Context) error {
if ctx.IsSet("disable-hostport-mapping") {
config.DisableHostPortMapping = ctx.Bool("disable-hostport-mapping")
}
if ctx.IsSet("enable-heap-dump") {
config.EnableHeapDump = ctx.Bool("enable-heap-dump")
}
return nil
}

Expand Down Expand Up @@ -1164,6 +1167,12 @@ func getCrioFlags(defConf *libconfig.Config) []cli.Flag {
EnvVars: []string{"DISABLE_HOSTPORT_MAPPING"},
Value: defConf.DisableHostPortMapping,
},
&cli.BoolFlag{
Name: "enable-heap-dump",
Usage: "If true, CRI-O generates a file at the specified location containing heap dump information.",
EnvVars: []string{"ENABLE_HEAP_DUMP"},
Value: defConf.EnableHeapDump,
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ type RuntimeConfig struct {
// Option to disable hostport mapping in CRI-O
// Default value is 'false'
DisableHostPortMapping bool `toml:"disable_hostport_mapping"`

// EnableHeapDump option will make CRI-O to generate a file at the specified location
// containing heap dump information.
EnableHeapDump bool `toml:"enable_heap_dump"`
}

// ImageConfig represents the "crio.image" TOML config table.
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ func initCrioTemplateConfig(c *Config) ([]*templateConfigValue, error) {
group: crioRuntimeConfig,
isDefaultValue: simpleEqual(dc.DisableHostPortMapping, c.DisableHostPortMapping),
},
{
templateString: templateStringCrioRuntimeEnableHeapDump,
group: crioRuntimeConfig,
isDefaultValue: simpleEqual(dc.RuntimeConfig.EnableHeapDump, c.RuntimeConfig.EnableHeapDump),
},
{
templateString: templateStringCrioImageDefaultTransport,
group: crioImageConfig,
Expand Down Expand Up @@ -1342,6 +1347,11 @@ const templateStringCrioRuntimeDisableHostPortMapping = `# disable_hostport_mapp

`

const templateStringCrioRuntimeEnableHeapDump = `# Enable/disable to dump heap memory information to a file
{{ $.Comment }}enable_heap_dump = {{ .EnableHeapDump }}

`

const templateStringCrioImage = `# The crio.image table contains settings pertaining to the management of OCI images.
#
# CRI-O reads its configured registries defaults from the system wide
Expand Down
23 changes: 23 additions & 0 deletions server/runtime_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package server
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime/debug"
"strings"
"time"

"golang.org/x/net/context"
types "k8s.io/cri-api/pkg/apis/runtime/v1"
Expand Down Expand Up @@ -43,6 +48,24 @@ func (s *Server) Status(ctx context.Context, req *types.StatusRequest) (*types.S
}
resp.Info = info
}

if s.config.EnableHeapDump {
dumpFilePath := filepath.Join("/tmp", fmt.Sprintf(
"crio-heapdump-%s.out",
strings.ReplaceAll(time.Now().Format(time.RFC3339), ":", ""),
))

f, err := os.Create(dumpFilePath)

if err != nil {
return nil, fmt.Errorf("creating heapdump output file: %w", err)
}

defer f.Close()

debug.WriteHeapDump(f.Fd())
}

return resp, nil
}

Expand Down