Documentation ¶
Index ¶
- Variables
- type JSPlugin
- type Plugin
- func (p *Plugin) GetHooks() []interface{}
- func (p *Plugin) GetPluginConfig(ctx context.Context, _ *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnBooted(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnBooting(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnClosed(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnClosing(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnConfigLoaded(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnNewClient(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnNewLogger(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnNewPool(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnNewProxy(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnNewServer(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnOpened(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnOpening(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnRun(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnShutdown(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnSignal(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnTick(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnTraffic(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnTrafficFromClient(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnTrafficFromServer(ctx context.Context, resp *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnTrafficToClient(ctx context.Context, resp *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnTrafficToServer(ctx context.Context, req *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) RegisterFunction(name string)
- func (p *Plugin) RegisterFunctions(names []string)
- func (p *Plugin) RunFunction(name string, ctx context.Context, req *v1.Struct) (*v1.Struct, error)
Constants ¶
This section is empty.
Variables ¶
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.
var ( Version = "0.0.1" PluginID = v1.PluginID{ Name: "gatewayd-plugin-js", Version: Version, RemoteUrl: "github.com/gatewayd-io/gatewayd-plugin-js", } PluginMap = map[string]goplugin.Plugin{ "gatewayd-plugin-js": &JSPlugin{}, } // 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/gatewayd-plugin-js", "config": map[string]interface{}{ "metricsEnabled": sdkConfig.GetEnv("METRICS_ENABLED", "true"), "metricsUnixDomainSocket": sdkConfig.GetEnv( "METRICS_UNIX_DOMAIN_SOCKET", "/tmp/gatewayd-plugin-cache.sock"), "metricsEndpoint": sdkConfig.GetEnv("METRICS_ENDPOINT", "/metrics"), "scriptPath": sdkConfig.GetEnv("SCRIPT_PATH", "./scripts/index.js"), }, "hooks": []interface{}{}, "tags": []interface{}{"plugin", "javascript", "js"}, "categories": []interface{}{"builtin"}, } Hooks = map[string]v1.HookName{ "onConfigLoaded": v1.HookName_HOOK_NAME_ON_CONFIG_LOADED, "onNewLogger": v1.HookName_HOOK_NAME_ON_NEW_LOGGER, "onNewPool": v1.HookName_HOOK_NAME_ON_NEW_POOL, "onNewClient": v1.HookName_HOOK_NAME_ON_NEW_CLIENT, "onNewProxy": v1.HookName_HOOK_NAME_ON_NEW_PROXY, "onNewServer": v1.HookName_HOOK_NAME_ON_NEW_SERVER, "onSignal": v1.HookName_HOOK_NAME_ON_SIGNAL, "onRun": v1.HookName_HOOK_NAME_ON_RUN, "onBooting": v1.HookName_HOOK_NAME_ON_BOOTING, "onBooted": v1.HookName_HOOK_NAME_ON_BOOTED, "onOpening": v1.HookName_HOOK_NAME_ON_OPENING, "onOpened": v1.HookName_HOOK_NAME_ON_OPENED, "onClosing": v1.HookName_HOOK_NAME_ON_CLOSING, "onClosed": v1.HookName_HOOK_NAME_ON_CLOSED, "onTraffic": v1.HookName_HOOK_NAME_ON_TRAFFIC, "onTrafficFromClient": v1.HookName_HOOK_NAME_ON_TRAFFIC_FROM_CLIENT, "onTrafficToServer": v1.HookName_HOOK_NAME_ON_TRAFFIC_TO_SERVER, "onTrafficFromServer": v1.HookName_HOOK_NAME_ON_TRAFFIC_FROM_SERVER, "onTrafficToClient": v1.HookName_HOOK_NAME_ON_TRAFFIC_TO_CLIENT, "onShutdown": v1.HookName_HOOK_NAME_ON_SHUTDOWN, "onTick": v1.HookName_HOOK_NAME_ON_TICK, } )
Functions ¶
This section is empty.
Types ¶
type JSPlugin ¶
type JSPlugin struct { goplugin.NetRPCUnsupportedPlugin Impl Plugin }
func NewJSPlugin ¶
NewJSPlugin returns a new instance of the TestPlugin.
func (*JSPlugin) GRPCClient ¶
func (p *JSPlugin) GRPCClient(ctx context.Context, b *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)
GRPCClient returns the plugin client.
func (*JSPlugin) GRPCServer ¶
GRPCServer registers the plugin with the gRPC server.
type Plugin ¶
type Plugin struct { goplugin.GRPCPlugin v1.GatewayDPluginServiceServer Logger hclog.Logger VM *goja.Runtime Bindings map[string]goja.Callable }
func (*Plugin) GetPluginConfig ¶
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) OnConfigLoaded ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
OnNewServer is called when a new server is created by GatewayD. This is a notification and the plugin cannot modify the server.
func (*Plugin) OnShutdown ¶
OnShutdown is called when GatewayD is shutting down.
func (*Plugin) OnSignal ¶
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) OnTraffic ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.