server

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHTTPConnection = errors.New("cannot operate over HTTP connection")

ErrInvalidHTTPConnection represents an event of misuse function for plain HTTP connection, such as httpConnection.Send() or httpConnection.Disconnect(). Usage will not result with change but return this error to indicate current state might not be as expected.

Functions

func New

func New(logger types.Logger) *server

New creates a new OpAMP Server.

Types

type CallbacksStruct

type CallbacksStruct struct {
	OnConnectingFunc func(request *http.Request) types.ConnectionResponse
}

CallbacksStruct is a struct that implements Callbacks interface and allows to override only the methods that are needed. If a method is not overridden then it will accept all connections.

func (CallbacksStruct) OnConnecting

func (c CallbacksStruct) OnConnecting(request *http.Request) types.ConnectionResponse

OnConnecting implements Callbacks.interface.

type ConnContext added in v0.6.0

type ConnContext func(ctx context.Context, c net.Conn) context.Context

type ConnectionCallbacksStruct added in v0.7.0

type ConnectionCallbacksStruct struct {
	OnConnectedFunc       func(ctx context.Context, conn types.Connection)
	OnMessageFunc         func(ctx context.Context, conn types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent
	OnConnectionCloseFunc func(conn types.Connection)
}

ConnectionCallbacksStruct is a struct that implements ConnectionCallbacks interface and allows to override only the methods that are needed.

func (ConnectionCallbacksStruct) OnConnected added in v0.7.0

func (c ConnectionCallbacksStruct) OnConnected(ctx context.Context, conn types.Connection)

OnConnected implements ConnectionCallbacks.OnConnected.

func (ConnectionCallbacksStruct) OnConnectionClose added in v0.7.0

func (c ConnectionCallbacksStruct) OnConnectionClose(conn types.Connection)

OnConnectionClose implements ConnectionCallbacks.OnConnectionClose.

func (ConnectionCallbacksStruct) OnMessage added in v0.7.0

OnMessage implements ConnectionCallbacks.OnMessage. If OnMessageFunc is nil then it will send an empty response to the agent

type HTTPHandlerFunc

type HTTPHandlerFunc func(http.ResponseWriter, *http.Request)

type OpAMPServer

type OpAMPServer interface {
	// Attach prepares the OpAMP Server to begin handling requests from an existing
	// http.Server. The returned HTTPHandlerFunc and ConnContext should be added as a
	// handler and ConnContext respectively to the desired http.Server by the caller
	// and the http.Server should be started by the caller after that. The ConnContext
	// is only used for plain http connections.
	// For example:
	//   handler, connContext, _ := Server.Attach()
	//   mux := http.NewServeMux()
	//   mux.HandleFunc("/opamp", handler)
	//   httpSrv := &http.Server{Handler:mux,Addr:"127.0.0.1:4320", ConnContext: connContext}
	//   httpSrv.ListenAndServe()
	Attach(settings Settings) (HTTPHandlerFunc, ConnContext, error)

	// Start an OpAMP Server and begin accepting connections. Starts its own http.Server
	// using provided settings. This should block until the http.Server is ready to
	// accept connections.
	Start(settings StartSettings) error

	// Stop accepting new connections and close all current connections. This should
	// block until all connections are closed.
	Stop(ctx context.Context) error

	// Addr returns the network address Server is listening on. Nil if not started.
	// Typically used to fetch the port when ListenEndpoint's port is specified as 0 to
	// allocate an ephemeral port.
	Addr() net.Addr
}

OpAMPServer is an interface representing the server side of the OpAMP protocol.

type Settings

type Settings struct {
	// Callbacks that the Server will call after successful Attach/Start.
	Callbacks types.Callbacks

	// EnableCompression can be set to true to enable the compression. Note that for WebSocket transport
	// the compression is only effectively enabled if the client also supports compression.
	// The data will be compressed in both directions.
	EnableCompression bool

	// Defines the custom capabilities of the Server. Each capability is a reverse FQDN with
	// optional version information that uniquely identifies the custom capability and
	// should match a capability specified in a supported CustomMessage.
	//
	// See
	// https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#customcapabilities
	// for more details.
	CustomCapabilities []string
}

Settings contains the settings for attaching an OpAMP Server.

type StartSettings

type StartSettings struct {
	Settings

	// ListenEndpoint specifies the endpoint to listen on, e.g. "127.0.0.1:4320"
	ListenEndpoint string

	// ListenPath specifies the URL path on which to accept the OpAMP connections
	// If this is empty string then Start() will use the default "/v1/opamp" path.
	ListenPath string

	// Server's TLS configuration.
	TLSConfig *tls.Config

	// HTTPMiddleware specifies middleware for HTTP messages received by the server.
	// Note that the function will be called once for websockets upon connecting and will
	// be called for every HTTP request. This function is optional to set.
	HTTPMiddleware func(handler http.Handler) http.Handler
}

StartSettings contains the settings for starting an OpAMP Server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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