rtctrl

package
v0.0.0-...-d691e2b Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package rtctrl

Package rtctrl

Package rtctrl

Package rtctrl

Package rtctrl

Package rtctrl

Index

Constants

View Source
const (
	ZeroByte byte = '\000'
	TabByte  byte = '\t'
	LineByte byte = '\n'

	StdoutLog = 1
	StderrLog = 2
)
View Source
const (
	StageWaitRuntime rtCtrlInvokeStage = iota
	StageStartRecvLog
	StageInvokeFunc
	StageSendRequest
	StageRecvResponse
	StageInvokeDone
	StageInvokeReportDone
	StageStopRecvLog
	StageCleanup
)
View Source
const (
	RuntimeHTTPSock = ".runtime-http.sock"
)

Variables

This section is empty.

Functions

func ConvertHTTPResponseToProxy

func ConvertHTTPResponseToProxy(rsp *http.Response, reqInfo *RequestInfo)

func ConvertProxyRequestToHTTP

func ConvertProxyRequestToHTTP(reqInfo *RequestInfo) (request *http.Request, cancel func())

func InitRtCtrlMetric

func InitRtCtrlMetric() error

func ListenerFromAddress

func ListenerFromAddress(addr string, fileMode os.FileMode) (net.Listener, error)

func StageName

func StageName(stage rtCtrlInvokeStage) string

func TryConnectAddress

func TryConnectAddress(addr string) error

Types

type CASOpType

type CASOpType int
const (
	OpOccupy CASOpType = iota
	OpMerged
	OpRetrieve
	OpRollback
	OpMark
	OpInit
	OpStop
	OpReset
	OpClose
	OpEnd
)

type Control

type Control interface {
	InvokeFunction(input *InvocationInput) *InvocationOutput
}

type DispatchServerV2

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

func (*DispatchServerV2) ListenAndServe

func (s *DispatchServerV2) ListenAndServe()

func (*DispatchServerV2) StartRecvLog

func (s *DispatchServerV2) StartRecvLog(runtimeID, requestID string, store LogStatStore)

func (*DispatchServerV2) StopRecvLog

func (s *DispatchServerV2) StopRecvLog(runtimeID, requestID string, store LogStatStore)

type DispatcherV2Options

type DispatcherV2Options struct {
	RuntimeServerAddress string
	RunnerServerAddress  string
	UserLogFileDir       string
	UserLogType          string
}

func NewDispatcherV2Options

func NewDispatcherV2Options() *DispatcherV2Options

func (*DispatcherV2Options) AddFlags

func (s *DispatcherV2Options) AddFlags(fs *pflag.FlagSet)

type InvocationInput

type InvocationInput struct {
	// runtime
	Runtime *RuntimeInfo

	// ExternalRequestID: external request ID
	ExternalRequestID string

	// RequestID: internal request ID
	RequestID string

	// User xxx
	User *api.User

	// The object for the Lambda function location.
	Code *api.FunctionCodeLocation

	// A complex type that describes function metadata.
	Configuration *api.FunctionConfiguration

	// log configuration
	LogConfig *api.LogConfiguration

	// define whether transfer request body as a stream
	WithStreamMode bool

	Request  *api.InvokeProxyRequest
	Response *api.InvokeProxyResponse

	// Enable Metric
	EnableMetrics bool

	// IsLogTail
	IsLogTail bool

	Logger      *logs.Logger
	InvokeType  string
	TriggerType string
}

InvocationInput function call input param

type InvocationOutput

type InvocationOutput struct {
	Output    *InvocationResponse
	Statistic *InvocationStatistic
}

type InvocationResponse

type InvocationResponse struct {
	FuncResult string   `json:"result,omitempty"`
	LogMessage []string `json:"log"`
	FuncError  string   `json:"errtype,omitempty"`
	ErrorInfo  string   `json:"errinfo,omitempty"`
	Response   *api.InvokeProxyResponse
}

InvocationOutput function call output param

type InvocationStatistic

type InvocationStatistic struct {
	Statistic *StatisticInfo
	Metric    *RtCtrlInvokeMetric
}

type InvokeHTTPRequest

type InvokeHTTPRequest struct {
	RequestID       string
	Request         *http.Request
	FunctionTimeout int64
	Logger          *logs.Logger
	CtxCancel       func()
}

type InvokeHTTPResponse

type InvokeHTTPResponse struct {
	RequestID string
	Response  *http.Response
}

type InvokeRequest

type InvokeRequest struct {
	RequestID       string `json:"requestid"`
	Version         string `json:"version"`
	AccessKeyID     string `json:"accessKey"`
	AccessKeySecret string `json:"secretKey"`
	SecurityToken   string `json:"securityToken"`
	ClientContext   string `json:"clientContext,omitempty"`
	EventObject     string `json:"eventObject,omitempty"`
}

type InvokeResponse

type InvokeResponse struct {
	RequestID  string `json:"requestid"`
	Success    bool   `json:"success"`
	FuncResult string `json:"result,omitempty"`
	FuncError  string `json:"error,omitempty"`
}

type LogStatStore

type LogStatStore interface {
	Receiver() string
	String() string
	WriteStdLog(from int, buf []byte, eof bool) (int, error)
	WriteFunctionLog(log string) error
	WriteFunctionReportLog(log string, params *reportParameters) error
	SetMemUsed(used int64)
	LogFile() string
	MemUsed() int64
	LogDone(set bool) bool
	Close() (string, error)
	Wait()
}

type LogStatStoreParameter

type LogStatStoreParameter struct {
	RequestID       string
	TriggerType     string
	RuntimeID       string
	UserID          string
	FunctionName    string
	FunctionBrn     string
	FunctionVersion string
	FilePath        string
	LogType         string
}

type MarkInput

type MarkInput struct {
	CommitID        string
	ConcurrentQuota uint64
}

type MergedInput

type MergedInput struct {
	CommitID string
}

type NewRuntimeParameters

type NewRuntimeParameters struct {
	RuntimeID               string
	ConcurrentMode          bool
	StreamMode              bool
	WaitRuntimeAliveTimeout int
	IsFrozen                bool
	Resource                *api.Resource
}

type OccupyInput

type OccupyInput struct {
	CommitID       string
	WithStreamMode bool
	MemorySize     uint64
	MilliCPUs      int64
}

type ReportedRunnerInfo

type ReportedRunnerInfo struct {
	Hostname    string
	ContainerID string
	Status      string
}

type RequestInfo

type RequestInfo struct {
	RequestID         string
	Runtime           *RuntimeInfo
	InvokeStartTimeNS int64
	InvokeStartTimeMS int64
	InitStartTimeMS   int64
	InitDoneTimeMS    int64
	InvokeDoneTimeMS  int64
	InvokeDurationMS  time.Duration
	BilledDurationMS  time.Duration
	MaxMemUsedBytes   int64
	MemorySpecSize    int64
	TriggerType       string

	Status RequestStatus
	Input  *InvocationInput
	Output *InvocationOutput

	SyncChannel    chan struct{}
	TimeoutChannel chan struct{} // timeout notification
	// contains filtered or unexported fields
}

func NewRequestInfo

func NewRequestInfo(requestID string, runtime *RuntimeInfo) *RequestInfo

func (*RequestInfo) CleanInput

func (info *RequestInfo) CleanInput()

func (*RequestInfo) CleanOutput

func (info *RequestInfo) CleanOutput()

func (*RequestInfo) InvokeDone

func (info *RequestInfo) InvokeDone()

func (*RequestInfo) InvokeReportDone

func (info *RequestInfo) InvokeReportDone()

func (*RequestInfo) InvokeResult

func (info *RequestInfo) InvokeResult(status RequestStatus, result string)

func (*RequestInfo) InvokeStart

func (info *RequestInfo) InvokeStart()

func (*RequestInfo) Notify

func (info *RequestInfo) Notify()

func (*RequestInfo) SetInitTime

func (info *RequestInfo) SetInitTime(preInit, postInit int64)

func (*RequestInfo) SetLogStore

func (info *RequestInfo) SetLogStore(store LogStatStore)

func (*RequestInfo) StepDone

func (info *RequestInfo) StepDone(state rtCtrlInvokeStage)

type RequestStatus

type RequestStatus int
const (
	StatusNormal RequestStatus = iota
	StatusRunning
	StatusSuccess
	StatusFailed
	StatusTimeout
)

type ResetInput

type ResetInput struct {
	Deadline time.Time
}

type RetrieveInput

type RetrieveInput struct {
	Deadline time.Time
}

type RollbackInput

type RollbackInput struct {
	CommitID string
}

type RtCtrlInvokeMetric

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

func NewRtCtrlInvokeMetric

func NewRtCtrlInvokeMetric(requestID string) *RtCtrlInvokeMetric

func (*RtCtrlInvokeMetric) MarshalLogObject

func (i *RtCtrlInvokeMetric) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*RtCtrlInvokeMetric) ObserveAll

func (r *RtCtrlInvokeMetric) ObserveAll()

func (*RtCtrlInvokeMetric) StepDone

func (r *RtCtrlInvokeMetric) StepDone(stage rtCtrlInvokeStage)

type RuntimeClient

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

func (*RuntimeClient) InvokeFunc

func (s *RuntimeClient) InvokeFunc(reqInfo *RequestInfo, input *InvocationInput) (err error)

func (*RuntimeClient) InvokeFunction

func (s *RuntimeClient) InvokeFunction(input *InvocationInput) (output *InvocationOutput)

type RuntimeConfigOptions

type RuntimeConfigOptions struct {
	// Time to wait for runtime to connect (Cold Start)
	// Units: seconds
	WaitRuntimeAliveTimeout int
}

func NewRuntimeConfigOptions

func NewRuntimeConfigOptions() *RuntimeConfigOptions

func (*RuntimeConfigOptions) AddFlags

func (s *RuntimeConfigOptions) AddFlags(fs *pflag.FlagSet)

type RuntimeDispatcher

type RuntimeDispatcher interface {
	// runtime
	RuntimeList() []*RuntimeInfo
	GetRuntime(string) (*RuntimeInfo, error)
	NewRuntime(*NewRuntimeParameters) *RuntimeInfo
	OccupyColdRuntime(*InvocationInput) (*RuntimeInfo, *api.ScaleUpRecommendation)
	FindWarmRuntime(*InvocationInput) *RuntimeInfo
	CoolDownRuntime(*RuntimeInfo) (*api.ScaleDownRecommendation, error)
	ResetRuntime(*RuntimeInfo) (*api.ScaleDownRecommendation, error)

	// resource
	IncreaseUsedResource(*api.Resource) bool
	ReleaseUsedResource(*api.Resource) bool
	ReleaseMarkedResource(rs *api.Resource) bool
	SyncResource(*api.FuncletResource) bool
	SyncRuntimeResource(string, *api.Resource) (bool, error)

	// statistic
	RuntimeStatistics() (cold, inUse, all int)
	ResourceStatistics() *api.ServiceResource
}

type RuntimeInfo

type RuntimeInfo struct {
	RuntimeID string `json:"RuntimeID"`

	// runtime state machine
	State         RuntimeStateType `json:"State"`
	Used          bool             `json:"used"`
	Marked        bool             `json:"marked"`
	Abnormal      bool             `json:"abnormal"`
	AbnormalTimes uint             `json:"abnormalTimes"`

	// runtime resource
	Resource *api.Resource `json:"Resource"`

	// Function meta
	UserID                  string `json:"UserID"` // CFC User ID
	CommitID                string `json:"CommitID"`
	MemorySize              uint64 `json:"MemorySize"`
	ConcurrentMode          bool   `json:"ConcurrentMode"`
	DefaultConcurrentMode   bool   `json:"DefaultConcurrentMode"`
	Concurrency             uint64 `json:"Concurrency"`
	WithStreamMode          bool   `json:"WithStreamMode"` // is http stream mode
	WaitRuntimeAliveTimeout int    `json:"WaitRuntimeAliveTimeout"`

	// Statistics
	PreLoadTimeMS  int64 `json:"PreLoadTimeMS"`
	PostLoadTimeMS int64 `json:"PostLoadTimeMS"`
	PreInitTimeMS  int64 `json:"PreInitTimeMS"`
	PostInitTimeMS int64 `json:"PostInitTimeMS"`
	AcceptReqCnt   int64 `json:"AcceptReqCnt"`
	RejectReqCnt   int64 `json:"RejectReqCnt"`

	LastLivenessTime time.Time `json:"LastLivenessTime"`
	LastAccessTime   time.Time `json:"LastAccessTime"`
	LastResetTime    time.Time `json:"LastResetTime"`
	// contains filtered or unexported fields
}

func NewRuntimeInfo

func NewRuntimeInfo(params *NewRuntimeParameters) *RuntimeInfo

func (*RuntimeInfo) CAS

func (info *RuntimeInfo) CAS(opType CASOpType, args interface{}) (err error)

CAS check and set runtime info

func (*RuntimeInfo) Invalidate

func (info *RuntimeInfo) Invalidate()

func (*RuntimeInfo) InvokeDone

func (info *RuntimeInfo) InvokeDone(request *RequestInfo, signal bool)

func (*RuntimeInfo) InvokeFunc

func (info *RuntimeInfo) InvokeFunc(request *RequestInfo, invokeReq *InvokeRequest) error

InvokeFunc

func (*RuntimeInfo) InvokeHTTPFunc

func (info *RuntimeInfo) InvokeHTTPFunc(request *RequestInfo, invokeReq *InvokeHTTPRequest) error

InvokeFunc

func (*RuntimeInfo) IsRunnerDefunct

func (info *RuntimeInfo) IsRunnerDefunct(deadline time.Time) bool

IsRunnerDefunct

func (*RuntimeInfo) RebootBegin

func (info *RuntimeInfo) RebootBegin()

RebootBegin

func (*RuntimeInfo) RebootEnd

func (info *RuntimeInfo) RebootEnd()

RebootEnd

func (*RuntimeInfo) RebootWait

func (info *RuntimeInfo) RebootWait()

func (*RuntimeInfo) Release

func (info *RuntimeInfo) Release() error

Release: release the occupation of runtime

func (*RuntimeInfo) SetCommitID

func (info *RuntimeInfo) SetCommitID(cm string)

func (*RuntimeInfo) SetInitTime

func (info *RuntimeInfo) SetInitTime(pre, post int64)

func (*RuntimeInfo) SetLoadTime

func (info *RuntimeInfo) SetLoadTime(pre, post int64)

func (*RuntimeInfo) SetMarked

func (info *RuntimeInfo) SetMarked(m bool)

func (*RuntimeInfo) SetMemorySize

func (info *RuntimeInfo) SetMemorySize(mem uint64)

func (*RuntimeInfo) SetResource

func (info *RuntimeInfo) SetResource(mem uint64, cpu int64)

func (*RuntimeInfo) SetState

func (info *RuntimeInfo) SetState(s RuntimeStateType)

func (*RuntimeInfo) SetUsed

func (info *RuntimeInfo) SetUsed(m bool)

func (*RuntimeInfo) Wait

func (info *RuntimeInfo) Wait(timeout int) bool

Wait

type RuntimeInfoError

type RuntimeInfoError struct {
	RuntimeID string
}

RuntimeInfoError

func (RuntimeInfoError) Error

func (e RuntimeInfoError) Error() string

type RuntimeManager

type RuntimeManager struct {
	MaxRuntimeIdle        int
	MaxRunnerDefunct      int
	MaxRunnerResetTimeout int
	// contains filtered or unexported fields
}

func (*RuntimeManager) CoolDownRuntime

func (m *RuntimeManager) CoolDownRuntime(runtime *RuntimeInfo) (recommend *api.ScaleDownRecommendation, err error)

func (*RuntimeManager) DelRuntime

func (m *RuntimeManager) DelRuntime(runtimeID string)

func (*RuntimeManager) FindWarmRuntime

func (m *RuntimeManager) FindWarmRuntime(req *InvocationInput) *RuntimeInfo

FindWarmRuntime

func (*RuntimeManager) GetRuntime

func (m *RuntimeManager) GetRuntime(runtimeID string) (ri *RuntimeInfo, err error)

func (*RuntimeManager) IncreaseUsedResource

func (m *RuntimeManager) IncreaseUsedResource(rs *api.Resource) bool

ReleaseUsedResource

func (*RuntimeManager) NewRuntime

func (m *RuntimeManager) NewRuntime(params *NewRuntimeParameters) *RuntimeInfo

func (*RuntimeManager) OccupyColdRuntime

func (m *RuntimeManager) OccupyColdRuntime(req *InvocationInput) (ri *RuntimeInfo, recommend *api.ScaleUpRecommendation)

OccupyColdRuntime

func (*RuntimeManager) ReleaseMarkedResource

func (m *RuntimeManager) ReleaseMarkedResource(rs *api.Resource) bool

ReleaseUsedResource

func (*RuntimeManager) ReleaseUsedResource

func (m *RuntimeManager) ReleaseUsedResource(rs *api.Resource) bool

ReleaseUsedResource

func (*RuntimeManager) ResetRuntime

func (m *RuntimeManager) ResetRuntime(runtime *RuntimeInfo) (recommend *api.ScaleDownRecommendation, err error)

func (*RuntimeManager) ResourceStatistics

func (m *RuntimeManager) ResourceStatistics() (resource *api.ServiceResource)

func (*RuntimeManager) RuntimeList

func (m *RuntimeManager) RuntimeList() []*RuntimeInfo

func (*RuntimeManager) RuntimeStatistics

func (m *RuntimeManager) RuntimeStatistics() (cold, inUse, all int)

func (*RuntimeManager) String

func (m *RuntimeManager) String() string

func (*RuntimeManager) SyncResource

func (m *RuntimeManager) SyncResource(resource *api.FuncletResource) bool

func (*RuntimeManager) SyncRuntimeResource

func (m *RuntimeManager) SyncRuntimeResource(ID string, resource *api.Resource) (sync bool, err error)

type RuntimeManagerParameters

type RuntimeManagerParameters struct {
	// Runtime maximum idle time
	// Units: seconds
	MaxRuntimeIdle int

	// The longest expire time after runner disconnect
	// Units: seconds
	MaxRunnerDefunct int

	// The longest expire time after runner last reset
	// Units: seconds
	MaxRunnerResetTimeout int
}

type RuntimeMatchError

type RuntimeMatchError struct {
	Reason string
}

RuntimeMatchError

func (RuntimeMatchError) Error

func (e RuntimeMatchError) Error() string

type RuntimeNoNeedToReset

type RuntimeNoNeedToReset struct {
	RuntimeID string
}

RuntimeNoNeedToReset

func (RuntimeNoNeedToReset) Error

func (e RuntimeNoNeedToReset) Error() string

type RuntimeNotExist

type RuntimeNotExist struct {
	RuntimeID string
}

RuntimeNotExist: runtime does not exist

func (RuntimeNotExist) Error

func (e RuntimeNotExist) Error() string

type RuntimeReleaseError

type RuntimeReleaseError struct {
	RuntimeID string
	Reason    string
}

RuntimeReleaseError: release runtime failed

func (RuntimeReleaseError) Error

func (e RuntimeReleaseError) Error() string

type RuntimeStateType

type RuntimeStateType = string
const (
	RuntimeStateCold       RuntimeStateType = "cold"
	RuntimeStateWarmUp     RuntimeStateType = "warmup"
	RuntimeStateWarm       RuntimeStateType = "warm"
	RuntimeStateMerged     RuntimeStateType = "merged"
	RuntimeStateStopping   RuntimeStateType = "stopping"
	RuntimeStateStopped    RuntimeStateType = "stopped"
	RuntimeStateClosed     RuntimeStateType = "closed"
	RuntimeStateReclaiming RuntimeStateType = "reclaiming"
)

type RuntimeStateUnmatched

type RuntimeStateUnmatched struct {
	RuntimeID     string
	CurrentState  RuntimeStateType
	ExpectedState []RuntimeStateType
}

func (RuntimeStateUnmatched) Error

func (e RuntimeStateUnmatched) Error() string

type RuntimeSyncError

type RuntimeSyncError struct {
	RuntimeID string
	Reason    string
}

RuntimeReleaseError: release runtime failed

func (RuntimeSyncError) Error

func (e RuntimeSyncError) Error() string

type StatisticInfo

type StatisticInfo struct {
	UserID     string  `json:"userid"`
	RequestID  string  `json:"reqid,omitempty"`
	Function   string  `json:"function"`
	Version    string  `json:"version"`
	StartTime  int64   `json:"startms"`
	Duration   float64 `json:"duration"`
	MemoryUsed int64   `json:"memused"`
	StatusCode int     `json:"status"`
}

func (*StatisticInfo) Decode

func (si *StatisticInfo) Decode(str string) error

func (*StatisticInfo) Encode

func (si *StatisticInfo) Encode() string

type StopInput

type StopInput struct {
	Deadline time.Time
}

type UserLogType

type UserLogType string
const (
	UserLogTypePlain UserLogType = "plain"
	UserLogTypeJson  UserLogType = "json"
)

func (UserLogType) Valid

func (u UserLogType) Valid() bool

Jump to

Keyboard shortcuts

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