diagnostic

package
v0.0.0-...-2714d10 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error used when there is no log directory available.
	ErrManagedLogNotFound = errors.New("managed log directory not found")
	// Error used when it is not possible to collect logs using the log configuration.
	ErrLogConfigurationIsInvalid = errors.New("provided log configuration is invalid")
	// Error used when parsing the fields of the output of collector.
	ErrInsufficientLines = errors.New("insufficient lines")
	// Error used when parsing the lines of the output of collector.
	ErrInsuficientFields = errors.New("insufficient fields")
	// Error used when given key is not found while parsing KV.
	ErrKeyNotFound = errors.New("key not found")
	// Error used when there is no disk volume information available.
	ErrNoVolumeFound = errors.New("no disk volume information found")
	// Error user when the base url of the diagnostic client is not provided.
	ErrNoBaseURL = errors.New("no base url")
	// Error used when no metrics server is found listening to the known addresses list (check [metrics.GetMetricsKnownAddresses]).
	ErrMetricsServerNotFound = errors.New("metrics server not found")
	// Error used when multiple metrics server are found listening to the known addresses list (check [metrics.GetMetricsKnownAddresses]).
	ErrMultipleMetricsServerFound = errors.New("multiple metrics server found")
	// Error used when a temporary file creation fails within the diagnostic procedure
	ErrCreatingTemporaryFile = errors.New("temporary file creation failed")
)

Functions

func CopyFilesFromDirectory

func CopyFilesFromDirectory(path string) (string, error)

func CreateDiagnosticZipFile

func CreateDiagnosticZipFile(base string, paths []string) (zipFileName string, err error)

CreateDiagnosticZipFile create a zip file with the contents from the all files paths. The files will be written in the root of the zip file. In case of an error occurs after whilst writing to the zip file this will be removed.

func FindMetricsServer

func FindMetricsServer(
	log *zerolog.Logger,
	client *httpClient,
	addresses []string,
) (*AddressableTunnelState, []*AddressableTunnelState, error)

The FindMetricsServer will try to find the metrics server url. There are two possible error scenarios: 1. No instance is found which will only return ErrMetricsServerNotFound 2. Multiple instances are found which will return an array of state and ErrMultipleMetricsServerFound In case of success, only the state for the instance is returned.

func NewHTTPClient

func NewHTTPClient() *httpClient

func RawSystemInformation

func RawSystemInformation(osInfoRaw string, memoryInfoRaw string, fdInfoRaw string, disksRaw string) string

Types

type AddressableTunnelState

type AddressableTunnelState struct {
	*TunnelState
	URL *url.URL
}

func RunDiagnostic

func RunDiagnostic(
	log *zerolog.Logger,
	options Options,
) ([]*AddressableTunnelState, error)

type DiskVolumeInformation

type DiskVolumeInformation struct {
	Name        string `json:"name"`        // represents the filesystem in linux/macos or device name in windows
	SizeMaximum uint64 `json:"sizeMaximum"` // represents the maximum size of the disk in kilobytes
	SizeCurrent uint64 `json:"sizeCurrent"` // represents the current size of the disk in kilobytes
}

func NewDiskVolumeInformation

func NewDiskVolumeInformation(name string, maximum, current uint64) *DiskVolumeInformation

func ParseDiskVolumeInformationOutput

func ParseDiskVolumeInformationOutput(output string, skipLines int, scale float64) ([]*DiskVolumeInformation, error)

type DockerLogCollector

type DockerLogCollector struct {
	// contains filtered or unexported fields
}

func NewDockerLogCollector

func NewDockerLogCollector(containerID string) *DockerLogCollector

func (*DockerLogCollector) Collect

func (collector *DockerLogCollector) Collect(ctx context.Context) (*LogInformation, error)

type FileDescriptorInformation

type FileDescriptorInformation struct {
	FileDescriptorMaximum uint64
	FileDescriptorCurrent uint64
}

func ParseFileDescriptorInformationFromKV

func ParseFileDescriptorInformationFromKV(
	output string,
	fileDescriptorMaximumKey string,
	fileDescriptorCurrentKey string,
) (*FileDescriptorInformation, error)

func ParseSysctlFileDescriptorInformation

func ParseSysctlFileDescriptorInformation(output string) (*FileDescriptorInformation, error)

type HTTPClient

type HTTPClient interface {
	GetLogConfiguration(ctx context.Context) (*LogConfiguration, error)
	GetMemoryDump(ctx context.Context, writer io.Writer) error
	GetGoroutineDump(ctx context.Context, writer io.Writer) error
	GetTunnelState(ctx context.Context) (*TunnelState, error)
	GetSystemInformation(ctx context.Context, writer io.Writer) error
	GetMetrics(ctx context.Context, writer io.Writer) error
	GetCliConfiguration(ctx context.Context, writer io.Writer) error
	GetTunnelConfiguration(ctx context.Context, writer io.Writer) error
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewDiagnosticHandler

func NewDiagnosticHandler(
	log *zerolog.Logger,
	timeout time.Duration,
	systemCollector SystemCollector,
	tunnelID uuid.UUID,
	connectorID uuid.UUID,
	tracker *tunnelstate.ConnTracker,
	cliFlags map[string]string,
	icmpSources []string,
) *Handler

func (*Handler) ConfigurationHandler

func (handler *Handler) ConfigurationHandler(writer http.ResponseWriter, _ *http.Request)

func (*Handler) InstallEndpoints

func (handler *Handler) InstallEndpoints(router *http.ServeMux)

func (*Handler) SystemHandler

func (handler *Handler) SystemHandler(writer http.ResponseWriter, request *http.Request)

func (*Handler) TunnelStateHandler

func (handler *Handler) TunnelStateHandler(writer http.ResponseWriter, _ *http.Request)

type HostLogCollector

type HostLogCollector struct {
	// contains filtered or unexported fields
}

func NewHostLogCollector

func NewHostLogCollector(client HTTPClient) *HostLogCollector

func (*HostLogCollector) Collect

func (collector *HostLogCollector) Collect(ctx context.Context) (*LogInformation, error)

type KubernetesLogCollector

type KubernetesLogCollector struct {
	// contains filtered or unexported fields
}

func NewKubernetesLogCollector

func NewKubernetesLogCollector(containerID, pod string) *KubernetesLogCollector

func (*KubernetesLogCollector) Collect

func (collector *KubernetesLogCollector) Collect(ctx context.Context) (*LogInformation, error)

type LogCollector

type LogCollector interface {
	// This function is responsible for returning a path to a single file
	// whose contents are the logs of a cloudflared instance.
	// A new file may be create by a LogCollector, thus, its the caller
	// responsibility to remove the newly create file.
	Collect(ctx context.Context) (*LogInformation, error)
}

type LogConfiguration

type LogConfiguration struct {
	// contains filtered or unexported fields
}

type LogInformation

type LogInformation struct {
	// contains filtered or unexported fields
}

Represents the path of the log file or log directory. This struct is meant to give some ergonimics regarding the logging information.

func NewLogInformation

func NewLogInformation(
	path string,
	wasCreated bool,
	isDirectory bool,
) *LogInformation

func PipeCommandOutputToFile

func PipeCommandOutputToFile(command *exec.Cmd, outputHandle *os.File) (*LogInformation, error)

type MemoryInformation

type MemoryInformation struct {
	MemoryMaximum uint64 // size in KB
	MemoryCurrent uint64 // size in KB
}

func ParseMemoryInformationFromKV

func ParseMemoryInformationFromKV(
	output string,
	memoryMaximumKey string,
	memoryAvailableKey string,
	mapper func(field string) (uint64, error),
) (*MemoryInformation, error)

type Options

type Options struct {
	KnownAddresses []string
	Address        string
	ContainerID    string
	PodID          string
	Toggles        Toggles
}

The Options structure holds every option necessary for the diagnostic procedure to work.

type OsInfo

type OsInfo struct {
	OsSystem     string
	Name         string
	OsVersion    string
	OsRelease    string
	Architecture string
}

func ParseUnameOutput

func ParseUnameOutput(output string, system string) (*OsInfo, error)

func ParseWinOperatingSystemInfo

func ParseWinOperatingSystemInfo(
	output string,
	architectureKey string,
	osSystemKey string,
	osVersionKey string,
	osReleaseKey string,
	nameKey string,
) (*OsInfo, error)

type SystemCollector

type SystemCollector interface {
	// If the collection is successful it will return `SystemInformation` struct,
	// and a nil error.
	//
	// This function expects that the caller sets the context timeout to prevent
	// long-lived collectors.
	Collect(ctx context.Context) (*SystemInformation, error)
}

type SystemCollectorImpl

type SystemCollectorImpl struct {
	// contains filtered or unexported fields
}

func NewSystemCollectorImpl

func NewSystemCollectorImpl(
	version string,
) *SystemCollectorImpl

func (*SystemCollectorImpl) Collect

func (collector *SystemCollectorImpl) Collect(ctx context.Context) (*SystemInformation, error)

type SystemInformation

type SystemInformation struct {
	MemoryMaximum         uint64                   `json:"memoryMaximum,omitempty"`         // represents the maximum memory of the system in kilobytes
	MemoryCurrent         uint64                   `json:"memoryCurrent,omitempty"`         // represents the system's memory in use in kilobytes
	FileDescriptorMaximum uint64                   `json:"fileDescriptorMaximum,omitempty"` // represents the maximum number of file descriptors of the system
	FileDescriptorCurrent uint64                   `json:"fileDescriptorCurrent,omitempty"` // represents the system's file descriptors in use
	OsSystem              string                   `json:"osSystem,omitempty"`              // represents the operating system name i.e.: linux, windows, darwin
	HostName              string                   `json:"hostName,omitempty"`              // represents the system host name
	OsVersion             string                   `json:"osVersion,omitempty"`             // detailed information about the system's release version level
	OsRelease             string                   `json:"osRelease,omitempty"`             // detailed information about the system's release
	Architecture          string                   `json:"architecture,omitempty"`          // represents the system's hardware platform i.e: arm64/amd64
	CloudflaredVersion    string                   `json:"cloudflaredVersion,omitempty"`    // the runtime version of cloudflared
	GoVersion             string                   `json:"goVersion,omitempty"`
	GoArch                string                   `json:"goArch,omitempty"`
	Disk                  []*DiskVolumeInformation `json:"disk,omitempty"`
}

func NewSystemInformation

func NewSystemInformation(
	memoryMaximum,
	memoryCurrent,
	filesMaximum,
	filesCurrent uint64,
	osystem,
	name,
	osVersion,
	osRelease,
	architecture,
	cloudflaredVersion,
	goVersion,
	goArchitecture string,
	disk []*DiskVolumeInformation,
) *SystemInformation

type SystemInformationError

type SystemInformationError struct {
	Err     error  `json:"error"`
	RawInfo string `json:"rawInfo"`
}

func (SystemInformationError) Error

func (err SystemInformationError) Error() string

func (SystemInformationError) MarshalJSON

func (err SystemInformationError) MarshalJSON() ([]byte, error)

type SystemInformationGeneralError

type SystemInformationGeneralError struct {
	OperatingSystemInformationError error
	MemoryInformationError          error
	FileDescriptorsInformationError error
	DiskVolumeInformationError      error
}

func (SystemInformationGeneralError) Error

func (SystemInformationGeneralError) MarshalJSON

func (err SystemInformationGeneralError) MarshalJSON() ([]byte, error)

type SystemInformationResponse

type SystemInformationResponse struct {
	Info *SystemInformation `json:"info"`
	Err  error              `json:"errors"`
}

type Toggles

type Toggles struct {
	NoDiagLogs    bool
	NoDiagMetrics bool
	NoDiagSystem  bool
	NoDiagRuntime bool
	NoDiagNetwork bool
}

The Toggles structure denotes the available toggles for the diagnostic procedure. Each toggle enables/disables tasks from the diagnostic.

type TunnelState

type TunnelState struct {
	TunnelID    uuid.UUID                           `json:"tunnelID,omitempty"`
	ConnectorID uuid.UUID                           `json:"connectorID,omitempty"`
	Connections []tunnelstate.IndexedConnectionInfo `json:"connections,omitempty"`
	ICMPSources []string                            `json:"icmp_sources,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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