plugin

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GetPluginConfig = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "get_plugin_config_total",
		Help:      "The total number of calls to the getPluginConfig method",
	})
	OnConfigLoaded = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Help:      "The total number of calls to the onConfigLoaded method",
		Name:      "on_config_loaded_total",
	})
	OnNewLogger = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_new_logger_total",
		Help:      "The total number of calls to the onNewLogger method",
	})
	OnNewPool = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_new_pool_total",
		Help:      "The total number of calls to the onNewPool method",
	})
	OnNewClient = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_new_client_total",
		Help:      "The total number of calls to the onNewClient method",
	})
	OnNewProxy = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_new_proxy_total",
		Help:      "The total number of calls to the onNewProxy method",
	})
	OnNewServer = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_new_server_total",
		Help:      "The total number of calls to the onNewServer method",
	})
	OnSignal = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_signal_total",
		Help:      "The total number of calls to the onSignal method",
	})
	OnRun = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_run_total",
		Help:      "The total number of calls to the onRun method",
	})
	OnBooting = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_booting_total",
		Help:      "The total number of calls to the onBooting method",
	})
	OnBooted = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_booted_total",
		Help:      "The total number of calls to the onBooted method",
	})
	OnOpening = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_opening_total",
		Help:      "The total number of calls to the onOpening method",
	})
	OnOpened = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_opened_total",
		Help:      "The total number of calls to the onOpened method",
	})
	OnClosing = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_closing_total",
		Help:      "The total number of calls to the onClosing method",
	})
	OnClosed = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_closed_total",
		Help:      "The total number of calls to the onClosed method",
	})
	OnTraffic = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_total",
		Help:      "The total number of calls to the onTraffic method",
	})
	OnShutdown = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_shutdown_total",
		Help:      "The total number of calls to the onShutdown method",
	})
	OnTick = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_tick_total",
		Help:      "The total number of calls to the onTick method",
	})
	OnTrafficFromClient = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_from_client_total",
		Help:      "The total number of calls to the onTrafficFromClient method",
	})
	OnTrafficToServer = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_to_server_total",
		Help:      "The total number of calls to the onTrafficToServer method",
	})
	OnTrafficFromServer = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_from_server_total",
		Help:      "The total number of calls to the onTrafficFromServer method",
	})
	OnTrafficToClient = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_to_client_total",
		Help:      "The total number of calls to the onTrafficToClient method",
	})
)

The following metrics are defined in the plugin and are used to track the number of times the plugin methods are called. These metrics are used as examples to test the plugin metrics functionality.

View Source
var (
	PluginID = v1.PluginID{
		Name:      "plugin-template-go",
		Version:   "0.0.1",
		RemoteUrl: "github.com/gatewayd-io/plugin-template-go",
	}
	PluginMap = map[string]goplugin.Plugin{
		"plugin-template-go": &TemplatePlugin{},
	}
	// TODO: Handle this in a better way
	// https://github.com/gatewayd-io/gatewayd-plugin-sdk/issues/3
	PluginConfig = map[string]interface{}{
		"id": map[string]interface{}{
			"name":      PluginID.GetName(),
			"version":   PluginID.GetVersion(),
			"remoteUrl": PluginID.GetRemoteUrl(),
		},
		"description": "Template plugin",
		"authors": []interface{}{
			"Mostafa Moradian <mostafa@gatewayd.io>",
		},
		"license":    "Apache 2.0",
		"projectUrl": "https://github.com/gatewayd-io/plugin-template-go",

		"config": map[string]interface{}{
			"metricsEnabled": sdkConfig.GetEnv("METRICS_ENABLED", "true"),
			"metricsUnixDomainSocket": sdkConfig.GetEnv(
				"METRICS_UNIX_DOMAIN_SOCKET", "/tmp/plugin-template-go.sock"),
			"metricsEndpoint": sdkConfig.GetEnv("METRICS_ENDPOINT", "/metrics"),
		},

		"hooks": []interface{}{

			int32(v1.HookName_HOOK_NAME_ON_CONFIG_LOADED),
			int32(v1.HookName_HOOK_NAME_ON_NEW_LOGGER),
			int32(v1.HookName_HOOK_NAME_ON_NEW_POOL),
			int32(v1.HookName_HOOK_NAME_ON_NEW_CLIENT),
			int32(v1.HookName_HOOK_NAME_ON_NEW_PROXY),
			int32(v1.HookName_HOOK_NAME_ON_NEW_SERVER),
			int32(v1.HookName_HOOK_NAME_ON_SIGNAL),
			int32(v1.HookName_HOOK_NAME_ON_RUN),
			int32(v1.HookName_HOOK_NAME_ON_BOOTING),
			int32(v1.HookName_HOOK_NAME_ON_BOOTED),
			int32(v1.HookName_HOOK_NAME_ON_OPENING),
			int32(v1.HookName_HOOK_NAME_ON_OPENED),
			int32(v1.HookName_HOOK_NAME_ON_CLOSING),
			int32(v1.HookName_HOOK_NAME_ON_CLOSED),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC_FROM_CLIENT),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC_TO_SERVER),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC_FROM_SERVER),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC_TO_CLIENT),
			int32(v1.HookName_HOOK_NAME_ON_SHUTDOWN),
			int32(v1.HookName_HOOK_NAME_ON_TICK),

			int32(v1.HookName(1000)),
		},
		"tags":       []interface{}{"template", "plugin"},
		"categories": []interface{}{"template"},
	}
)

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	goplugin.GRPCPlugin
	v1.GatewayDPluginServiceServer
	Logger hclog.Logger
}

func (*Plugin) GetPluginConfig

func (p *Plugin) GetPluginConfig(
	ctx context.Context, _ *v1.Struct) (*v1.Struct, error)

GetPluginConfig returns the plugin config. This is called by GatewayD when the plugin is loaded. The plugin config is used to configure the plugin.

func (*Plugin) OnBooted

func (p *Plugin) OnBooted(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnBooted is called when GatewayD is booted.

func (*Plugin) OnBooting

func (p *Plugin) OnBooting(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnBooting is called when GatewayD is booting.

func (*Plugin) OnClosed

func (p *Plugin) OnClosed(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnClosed is called when a client connection is closed.

func (*Plugin) OnClosing

func (p *Plugin) OnClosing(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnClosing is called when a client connection is being closed.

func (*Plugin) OnConfigLoaded

func (p *Plugin) OnConfigLoaded(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnConfigLoaded is called when the global config is loaded by GatewayD. This can be used to modify the global config. Note that the plugin config cannot be modified via plugins.

func (*Plugin) OnNewClient

func (p *Plugin) OnNewClient(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnNewClient is called when a new client is created by GatewayD. This is a notification and the plugin cannot modify the client.

func (*Plugin) OnNewLogger

func (p *Plugin) OnNewLogger(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnNewLogger is called when a new logger is created by GatewayD. This is a notification and the plugin cannot modify the logger.

func (*Plugin) OnNewPool

func (p *Plugin) OnNewPool(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnNewPool is called when a new pool is created by GatewayD. This is a notification and the plugin cannot modify the pool.

func (*Plugin) OnNewProxy

func (p *Plugin) OnNewProxy(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnNewProxy is called when a new proxy is created by GatewayD. This is a notification and the plugin cannot modify the proxy.

func (*Plugin) OnNewServer

func (p *Plugin) OnNewServer(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnNewServer is called when a new server is created by GatewayD. This is a notification and the plugin cannot modify the server.

func (*Plugin) OnOpened

func (p *Plugin) OnOpened(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnOpened is called when a new client connection is opened.

func (*Plugin) OnOpening

func (p *Plugin) OnOpening(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnOpening is called when a new client connection is being opened.

func (*Plugin) OnRun

func (p *Plugin) OnRun(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnRun is called when GatewayD is started.

func (*Plugin) OnShutdown

func (p *Plugin) OnShutdown(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnShutdown is called when GatewayD is shutting down.

func (*Plugin) OnSignal

func (p *Plugin) OnSignal(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnSignal is called when a signal (for example, SIGKILL) is received by GatewayD. This is a notification and the plugin cannot modify the signal.

func (*Plugin) OnTick

func (p *Plugin) OnTick(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnTick is called when GatewayD is ticking (if enabled).

func (*Plugin) OnTraffic

func (p *Plugin) OnTraffic(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnTraffic is called when a request is being received by GatewayD from the client. This is a notification and the plugin cannot modify the request at this point.

func (*Plugin) OnTrafficFromClient

func (p *Plugin) OnTrafficFromClient(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnTrafficFromClient is called when a request is received by GatewayD from the client. This can be used to modify the request or terminate the connection by returning an error or a response.

func (*Plugin) OnTrafficFromServer

func (p *Plugin) OnTrafficFromServer(
	ctx context.Context, resp *v1.Struct) (*v1.Struct, error)

OnTrafficFromServer is called when a response is received by GatewayD from the server. This can be used to modify the response or terminate the connection by returning an error or a response.

func (*Plugin) OnTrafficToClient

func (p *Plugin) OnTrafficToClient(
	ctx context.Context, resp *v1.Struct) (*v1.Struct, error)

OnTrafficToClient is called when a response is sent by GatewayD to the client. This can be used to modify the response or terminate the connection by returning an error or a response.

func (*Plugin) OnTrafficToServer

func (p *Plugin) OnTrafficToServer(ctx context.Context, req *v1.Struct) (*v1.Struct, error)

OnTrafficToServer is called when a request is sent by GatewayD to the server. This can be used to modify the request or terminate the connection by returning an error or a response while also sending the request to the server.

type TemplatePlugin

type TemplatePlugin struct {
	goplugin.NetRPCUnsupportedPlugin
	Impl Plugin
}

func NewTemplatePlugin

func NewTemplatePlugin(impl Plugin) *TemplatePlugin

NewTemplatePlugin returns a new instance of the TestPlugin.

func (*TemplatePlugin) GRPCClient

func (p *TemplatePlugin) GRPCClient(ctx context.Context, b *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient returns the plugin client.

func (*TemplatePlugin) GRPCServer

func (p *TemplatePlugin) GRPCServer(b *goplugin.GRPCBroker, s *grpc.Server) error

GRPCServer registers the plugin with the gRPC server.

Jump to

Keyboard shortcuts

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