util

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2022 License: Apache-2.0 Imports: 18 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// ProfilerEndpointExpiredValue is the value of endpoint in profiler status after expiration duration.
	ProfilerEndpointExpiredValue = "expired"
	// KubeletRunDirectory specifies the directory where the kubelet runtime information is stored.
	KubeletRunDirectory = "/var/lib/kubelet"
	// KubeletPodDirectory specifies the directory where the kubelet pod information is stored.
	KubeletPodDirectory = "/var/lib/kubelet/pods"
	// DefautlNamespace is the default namespace of kubediag.
	DefautlNamespace = "kubediag"
	// PodKillGracePeriodSeconds is the duration in seconds after the pod is forcibly halted
	// with a kill signal and the time when the pod is taken as an abormal pod.
	PodKillGracePeriodSeconds = 30
	// TerminatingPodDiagnosisNamePrefix is the name prefix for creating terminating pod diagnosis.
	TerminatingPodDiagnosisNamePrefix = "terminating-pod"
	// MemoryAnalyzerLeakSuspectsReportAPI is the eclipse memory analyzer api for leak suspects report.
	MemoryAnalyzerLeakSuspectsReportAPI = "org.eclipse.mat.api:suspects"
	// MemoryAnalyzerSystemOverviewReportAPI is the eclipse memory analyzer api for system overview report.
	MemoryAnalyzerSystemOverviewReportAPI = "org.eclipse.mat.api:overview"
	// MemoryAnalyzerTopComponentsReportAPI is the eclipse memory analyzer api for top components report.
	MemoryAnalyzerTopComponentsReportAPI = "org.eclipse.mat.api:top_components"
	// MemoryAnalyzerLeakSuspectsSuffix is the suffix for leak suspects report directory.
	MemoryAnalyzerLeakSuspectsSuffix = "_Leak_Suspects"
	// MemoryAnalyzerSystemOverviewSuffix is the suffix for system overview report directory.
	MemoryAnalyzerSystemOverviewSuffix = "_System_Overview"
	// MemoryAnalyzerTopComponentsSuffix is the suffix for top components report directory.
	MemoryAnalyzerTopComponentsSuffix = "_Top_Components"
	// MemoryAnalyzerHomepage is the html text for memory analyzer homepage.
	MemoryAnalyzerHomepage = `` /* 200-byte string literal not displayed */
	// GoProfilerPathPrefix is the path prefix for go profiler pprof url.
	GoProfilerPathPrefix = "/debug/pprof/"
	// KubeDiagPrefix is the key prefix for annotations about kubediag.
	KubeDiagPrefix = "diagnosis.kubediag.org/"
	// OperationSetUniqueLabelKey is the default key of the label that is added to existing OperationSets and Diagnoses
	// to prevent conflicts on changed OperationSets and running Diagnoses.
	OperationSetUniqueLabelKey = "adjacency-list-hash"
	// AlphaNums omits vowels from the set of available characters to reduce the chances of "bad words" being formed.
	AlphaNums = "bcdfghjklmnpqrstvwxz2456789"
)

Variables

This section is empty.

Functions

func BlockingRunCommandWithTimeout

func BlockingRunCommandWithTimeout(command []string, timeoutSeconds int32) ([]byte, error)

BlockingRunCommandWithTimeout executes command in blocking mode with timeout seconds.

func ComputeHash

func ComputeHash(template interface{}) string

ComputeHash returns a hash value calculated from a template. The hash will be safe encoded to avoid bad words.

func CreateFile added in v0.2.2

func CreateFile(path string, content string) error

CreateFile creates a file on the destination path and writes content to the the file.

func DecompressHPROFFileArchives

func DecompressHPROFFileArchives(dirname string, fileInfo os.FileInfo, timeoutSeconds int32) (string, string, string, error)

DecompressHPROFFileArchives decompresses result archives from hprof files by executing "unzip" command.

func DiskUsage

func DiskUsage(path string) (int, error)

DiskUsage calculates the disk usage of a directory by executing "du" command.

func FormatURL

func FormatURL(scheme string, host string, port string, path string) *url.URL

FormatURL formats a URL from args.

func GetAvailableBytes

func GetAvailableBytes(path string) uint64

GetAvailableBytes gets available bytes in filesystem.

func GetAvailablePort

func GetAvailablePort() (int, error)

GetAvailablePort returns a free open port that is ready to use.

func GetDiagnosisCondition

func GetDiagnosisCondition(status *diagnosisv1.DiagnosisStatus, conditionType diagnosisv1.DiagnosisConditionType) (int, *diagnosisv1.DiagnosisCondition)

GetDiagnosisCondition extracts the provided condition from the given status. Returns -1 and nil if the condition is not present, otherwise returns the index of the located condition.

func GetDiagnosisConditionFromList

func GetDiagnosisConditionFromList(conditions []diagnosisv1.DiagnosisCondition, conditionType diagnosisv1.DiagnosisConditionType) (int, *diagnosisv1.DiagnosisCondition)

GetDiagnosisConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.

func GetFreeBytes

func GetFreeBytes(path string) uint64

GetFreeBytes gets free bytes in filesystem.

func GetNodeUnhealthyConditionType

func GetNodeUnhealthyConditionType(node corev1.Node) corev1.NodeConditionType

GetNodeUnhealthyConditionType extracts the condition type of unhealthy node. The parameter must be an unhealthy node. It returns the type of the first unhealthy condition.

func GetPodUnhealthyReason

func GetPodUnhealthyReason(pod corev1.Pod) string

GetPodUnhealthyReason extracts the reason of terminated or waiting container in the pod if the pod is not ready. The parameter must be an unhealthy pod. It returns the reason of the first terminated or waiting container.

func GetProgramPID

func GetProgramPID(program string) ([]int, error)

GetProgramPID finds the process ID of a running program by executing "pidof" command.

func GetTotalBytes

func GetTotalBytes(path string) uint64

GetTotalBytes gets total bytes in filesystem.

func GetUsedBytes

func GetUsedBytes(path string) uint64

GetUsedBytes gets used bytes in filesystem.

func IsDiagnosisCompleted

func IsDiagnosisCompleted(diagnosis diagnosisv1.Diagnosis) bool

IsDiagnosisCompleted return true if Diagnosis is failed or succeed

func IsDiagnosisNodeNameMatched

func IsDiagnosisNodeNameMatched(diagnosis diagnosisv1.Diagnosis, nodeName string) bool

IsDiagnosisNodeNameMatched checks if the diagnosis is on the specific node. It returns true if current node name of the diagnosis matches provided NodeName field or the NodeName based on podReference field.

func IsNodeReady

func IsNodeReady(node corev1.Node) bool

IsNodeReady returns true if its Ready condition is set to true and it does not have NetworkUnavailable condition set to true.

func MoveFiles added in v0.3.0

func MoveFiles(src string, dst string) error

MoveFiles moves all files within src to an output directory.

func ParseHPROFFile

func ParseHPROFFile(workdir string, path string, timeoutSeconds int32) error

ParseHPROFFile parses hprof file with eclipse memory analyzer. The results are stored in zip files under the same directory of hprof file. It takes command working directory, hprof file path and timeout seconds as parameters.

func QueueDiagnosis

func QueueDiagnosis(ctx context.Context, channel chan diagnosisv1.Diagnosis, diagnosis diagnosisv1.Diagnosis) error

QueueDiagnosis sends a diagnosis to a channel. It returns an error if the channel is blocked.

func QueueEvent

func QueueEvent(ctx context.Context, channel chan corev1.Event, event corev1.Event) error

QueueEvent sends an event to a channel. It returns an error if the channel is blocked.

func QueueOperationSet

func QueueOperationSet(ctx context.Context, channel chan diagnosisv1.OperationSet, operationSet diagnosisv1.OperationSet) error

QueueOperationSet sends an operation set to a channel. It returns an error if the channel is blocked.

func RemoveFile

func RemoveFile(path string) error

RemoveFile removes a file or a directory by executing "rm" command.

func RetrieveDiagnosesOnNode

func RetrieveDiagnosesOnNode(diagnoses []diagnosisv1.Diagnosis, nodeName string) []diagnosisv1.Diagnosis

RetrieveDiagnosesOnNode retrieves all diagnoses on the provided node.

func RetrievePodsOnNode

func RetrievePodsOnNode(pods []corev1.Pod, nodeName string) []corev1.Pod

RetrievePodsOnNode retrieves all pods on the provided node.

func SafeEncodeString

func SafeEncodeString(s string) string

SafeEncodeString encodes s using the same characters as rand.String. This reduces the chances of bad words and ensures that strings generated from hash functions appear consistent throughout the API.

func ScanLastNonEmptyLine added in v0.2.2

func ScanLastNonEmptyLine(data []byte, eof bool) (advance int, token []byte, err error)

ScanLastNonEmptyLine get the last available line. It is an implementation of scanner.SplitFunc.

func StringToNamespacedName

func StringToNamespacedName(s string) (types.NamespacedName, error)

StringToNamespacedName converts a string to NamespacedName.

func Unzip

func Unzip(src string, dst string, timeoutSeconds int32) error

Unzip decompresses a zip archive, moving all files and folders within the zip file to an output directory by executing "unzip" command. It takes source zip file, destination output directory and timeout seconds as parameters.

func UpdateDiagnosisCondition

func UpdateDiagnosisCondition(status *diagnosisv1.DiagnosisStatus, condition *diagnosisv1.DiagnosisCondition) bool

UpdateDiagnosisCondition updates existing diagnosis condition or creates a new one. Sets LastTransitionTime to now if the status has changed. Returns true if diagnosis condition has changed or has been added.

func UpdatePodUnhealthyReasonStatistics

func UpdatePodUnhealthyReasonStatistics(containerStateReasons map[string]int, reason string) bool

UpdatePodUnhealthyReasonStatistics updates container state reason map of unhealthy pods. It returns true if the reason is not empty, otherwise false.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL