agentapi

package
v0.0.0-...-f673c85 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

Agent API

This is the API used for communication between the agent (process running inside the firecracker VM) and the host (nex-node). This API contains operations to subscribe to logs and events, as well as health query and, of course, a function to start and run a workload.

Documentation

Index

Constants

View Source
const (
	NexTriggerSubject = "x-nex-trigger-subject"
	NexRuntimeNs      = "x-nex-runtime-ns"

	HttpURLHeader = "x-http-url"

	KeyValueKeyHeader = "x-keyvalue-key"

	MessagingSubjectHeader = "x-subject"

	ObjectStoreObjectNameHeader = "x-object-name"
)
View Source
const (
	AgentStartedEventType          = "agent_started"
	AgentStoppedEventType          = "agent_stopped"
	FunctionExecutionFailedType    = "function_exec_failed"
	FunctionExecutionSucceededType = "function_exec_succeeded"
	WorkloadStartedEventType       = "workload_started" // FIXME-- should this be WorkloadDeployed?
	WorkloadStoppedEventType       = "workload_stopped" // FIXME-- should this be in addition to WorkloadUndeployed (likely yes, in case of something bad happening...)

)
View Source
const (
	LogLevelPanic = 0
	LogLevelFatal = 1
	LogLevelError = 2
	LogLevelWarn  = 3
	LogLevelInfo  = 4
	LogLevelDebug = 5
	LogLevelTrace = 6
)
View Source
const DefaultRunloopSleepTimeoutMillis = 25

DefaultRunloopSleepTimeoutMillis default number of milliseconds to sleep during execution runloops

View Source
const NexExecutionProviderELF = "elf"

Executable Linkable Format execution provider

View Source
const NexExecutionProviderOCI = "oci"

OCI execution provider

View Source
const NexExecutionProviderV8 = "v8"

V8 execution provider

View Source
const NexExecutionProviderWasm = "wasm"

Wasm execution provider

View Source
const WorkloadCacheBucket = "NEXCACHE"

Name of the internal, non-public bucket for sharing files between host and agent

Variables

This section is empty.

Functions

func NewAgentEvent

func NewAgentEvent(sourceId string, eventType string, event interface{}) cloudevents.Event

func StringOrNil

func StringOrNil(str string) *string

returns the given string or nil if empty

Types

type AgentClient

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

func NewAgentClient

func NewAgentClient(
	nc *nats.Conn,
	log *slog.Logger,
	handshakeTimeout time.Duration,
	onTimedOut HandshakeCallback,
	onSuccess HandshakeCallback,
	onEvent EventCallback,
	onLog LogCallback,
) *AgentClient

func (*AgentClient) DeployWorkload

func (a *AgentClient) DeployWorkload(request *DeployRequest) (*DeployResponse, error)

func (*AgentClient) Drain

func (a *AgentClient) Drain() error

Stop the agent client instance and cleanup by draining subscriptions and releasing other associated resources

func (*AgentClient) ExecTimeNanos

func (a *AgentClient) ExecTimeNanos() int64

func (*AgentClient) ID

func (a *AgentClient) ID() string

Returns the ID of this agent client, which corresponds to a workload process identifier

func (*AgentClient) RecordExecTime

func (a *AgentClient) RecordExecTime(elapsedNanos int64)

func (*AgentClient) RunTrigger

func (a *AgentClient) RunTrigger(ctx context.Context, tracer trace.Tracer, subject string, data []byte) (*nats.Msg, error)

func (*AgentClient) Start

func (a *AgentClient) Start(agentID string) error

func (*AgentClient) Undeploy

func (a *AgentClient) Undeploy() error

func (*AgentClient) UptimeMillis

func (a *AgentClient) UptimeMillis() time.Duration

Returns the time difference between now and when the agent started

type AgentStartedEvent

type AgentStartedEvent struct {
	AgentVersion string `json:"agent_version"`
}

type AgentStoppedEvent

type AgentStoppedEvent struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

type DeployRequest

type DeployRequest struct {
	Argv            []string          `json:"argv,omitempty"`
	DecodedClaims   jwt.GenericClaims `json:"-"`
	Description     *string           `json:"description"`
	Environment     map[string]string `json:"environment"`
	Essential       *bool             `json:"essential,omitempty"`
	Hash            string            `json:"hash,omitempty"`
	Namespace       *string           `json:"namespace,omitempty"`
	RetriedAt       *time.Time        `json:"retried_at,omitempty"`
	RetryCount      *uint             `json:"retry_count,omitempty"`
	TotalBytes      int64             `json:"total_bytes,omitempty"`
	TriggerSubjects []string          `json:"trigger_subjects"`
	WorkloadName    *string           `json:"workload_name,omitempty"`
	WorkloadType    *string           `json:"workload_type,omitempty"`

	Stderr      io.Writer `json:"-"`
	Stdout      io.Writer `json:"-"`
	TmpFilename *string   `json:"-"`

	EncryptedEnvironment *string  `json:"-"`
	JsDomain             *string  `json:"-"`
	Location             *url.URL `json:"-"`
	SenderPublicKey      *string  `json:"-"`
	TargetNode           *string  `json:"-"`
	WorkloadJwt          *string  `json:"-"`

	Errors []error `json:"errors,omitempty"`
}

DeployRequest processed by the agent

func (*DeployRequest) IsEssential

func (request *DeployRequest) IsEssential() bool

func (*DeployRequest) SupportsEssential

func (request *DeployRequest) SupportsEssential() bool

Returns true if the run request supports essential flag

func (*DeployRequest) SupportsTriggerSubjects

func (request *DeployRequest) SupportsTriggerSubjects() bool

Returns true if the run request supports trigger subjects

func (*DeployRequest) Validate

func (r *DeployRequest) Validate() error

type DeployResponse

type DeployResponse struct {
	Accepted bool    `json:"accepted"`
	Message  *string `json:"message"`
}

type EventCallback

type EventCallback func(string, cloudevents.Event)

type ExecutionProviderParams

type ExecutionProviderParams struct {
	DeployRequest
	TriggerSubjects []string `json:"trigger_subjects"`

	// Fail channel receives bool upon command failing to start
	Fail chan bool `json:"-"`

	// Run channel receives bool upon command successfully starting
	Run chan bool `json:"-"`

	// Exit channel receives int exit code upon command exit
	Exit chan int `json:"-"`

	Stderr io.Writer `json:"-"`
	Stdout io.Writer `json:"-"`

	TmpFilename *string `json:"-"`
	VmID        string  `json:"-"`

	// NATS connection which be injected into the execution provider
	NATSConn *nats.Conn `json:"-"`
}

ExecutionProviderParams parameters for initializing a specific execution provider

type HandshakeCallback

type HandshakeCallback func(string)

type HandshakeRequest

type HandshakeRequest struct {
	ID        *string   `json:"id"`
	StartTime time.Time `json:"start_time"`
	Message   *string   `json:"message,omitempty"`
}

type HandshakeResponse

type HandshakeResponse struct {
}

type HostServicesHTTPRequest

type HostServicesHTTPRequest struct {
	Method string `json:"method"`
	URL    string `json:"url"`

	Body    *string          `json:"body,omitempty"`
	Headers *json.RawMessage `json:"headers,omitempty"`

	// FIXME-- this is very poorly named currently...
	//these params are parsed as an object and serialized as part of the query string
	Params *json.RawMessage `json:"params,omitempty"`
}

type HostServicesHTTPResponse

type HostServicesHTTPResponse struct {
	Status  int              `json:"status"`
	Headers *json.RawMessage `json:"headers,omitempty"`
	Body    string           `json:"body"`

	Error *string `json:"error,omitempty"`
}

type HostServicesKeyValueResponse

type HostServicesKeyValueResponse struct {
	Revision int64 `json:"revision,omitempty"`
	Success  *bool `json:"success,omitempty"`

	Errors []string `json:"errors,omitempty"`
}

type HostServicesMessagingRequest

type HostServicesMessagingRequest struct {
	Subject *string          `json:"key"`
	Payload *json.RawMessage `json:"payload,omitempty"`
}

type HostServicesMessagingResponse

type HostServicesMessagingResponse struct {
	Errors  []string `json:"errors,omitempty"`
	Success bool     `json:"success,omitempty"`
}

type HostServicesObjectStoreResponse

type HostServicesObjectStoreResponse struct {
	Errors  []string `json:"errors,omitempty"`
	Success bool     `json:"success,omitempty"`
}

type LogCallback

type LogCallback func(string, LogEntry)

type LogEntry

type LogEntry struct {
	Source string   `json:"source,omitempty"`
	Level  LogLevel `json:"level,omitempty"`
	Text   string   `json:"text,omitempty"`
}

type LogLevel

type LogLevel int32

type MachineMetadata

type MachineMetadata struct {
	VmID         *string `json:"vmid"`
	NodeNatsHost *string `json:"node_nats_host"`
	NodeNatsPort *int    `json:"node_nats_port"`
	Message      *string `json:"message"`

	Errors []error `json:"errors,omitempty"`
}

func (*MachineMetadata) Validate

func (m *MachineMetadata) Validate() bool

type WorkloadStatusEvent

type WorkloadStatusEvent struct {
	WorkloadName string `json:"workload_name"`
	Code         int    `json:"code"`
	Message      string `json:"message,omitempty"`
}

Jump to

Keyboard shortcuts

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