plugin

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: AGPL-3.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AddressPortPairLength = 2

Variables

View Source
var (
	GetPluginConfigCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "get_plugin_config_total",
		Help:      "The total number of calls to the getPluginConfig method",
	})
	OnClosedCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_closed_total",
		Help:      "The total number of calls to the onClosed method",
	})
	OnTrafficFromClientCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_from_client_total",
		Help:      "The total number of calls to the onTrafficFromClient method",
	})
	OnTrafficFromServerCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "on_traffic_from_server_total",
		Help:      "The total number of calls to the onTrafficFromServer method",
	})

	CacheHitsCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_hits_total",
		Help:      "The total number of cache hits",
	})
	CacheMissesCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_misses_total",
		Help:      "The total number of cache misses",
	})
	CacheSetsCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_sets_total",
		Help:      "The total number of cache sets",
	})
	CacheGetsCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_gets_total",
		Help:      "The total number of cache gets",
	})
	CacheDeletesCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_deletes_total",
		Help:      "The total number of cache deletes",
	})
	CacheScanCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_scans_total",
		Help:      "The total number of cache scans",
	})
	CacheScanKeysCounter = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: metrics.Namespace,
		Name:      "cache_scan_keys_total",
		Help:      "The total number of cache scan keys",
	})
)
View Source
var (
	PluginID = v1.PluginID{
		Name:      "gatewayd-plugin-cache",
		Version:   "0.0.1",
		RemoteUrl: "github.com/gatewayd-io/gatewayd-plugin-cache",
	}
	PluginMap = map[string]goplugin.Plugin{
		PluginID.Name: &CachePlugin{},
	}
	PluginConfig = map[string]interface{}{
		"id": map[string]interface{}{
			"name":      PluginID.Name,
			"version":   PluginID.Version,
			"remoteUrl": PluginID.RemoteUrl,
		},
		"description": "GatewayD plugin for caching query results",
		"authors": []interface{}{
			"Mostafa Moradian <mostafa@gatewayd.io>",
		},
		"license":    "AGPL-3.0",
		"projectUrl": "https://github.com/gatewayd-io/gatewayd-plugin-cache",

		"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"),
			"redisURL":        sdkConfig.GetEnv("REDIS_URL", "redis://localhost:6379/0"),
			"expiry":          sdkConfig.GetEnv("EXPIRY", "1h"),
			"defaultDBName":   sdkConfig.GetEnv("DEFAULT_DB_NAME", ""),
			"scanCount":       sdkConfig.GetEnv("SCAN_COUNT", "1000"),
			"periodicInvalidatorEnabled": sdkConfig.GetEnv(
				"PERIODIC_INVALIDATOR_ENABLED", "true"),
			"periodicInvalidatorStartDelay": sdkConfig.GetEnv(
				"PERIODIC_INVALIDATOR_START_DELAY", "1m"),
			"periodicInvalidatorInterval": sdkConfig.GetEnv(
				"PERIODIC_INVALIDATOR_INTERVAL", "1m"),
			"apiAddress":         sdkConfig.GetEnv("API_ADDRESS", "localhost:8080"),
			"exitOnStartupError": sdkConfig.GetEnv("EXIT_ON_STARTUP_ERROR", "false"),
		},
		"hooks": []interface{}{
			int32(v1.HookName_HOOK_NAME_ON_CLOSED),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC_FROM_CLIENT),
			int32(v1.HookName_HOOK_NAME_ON_TRAFFIC_FROM_SERVER),
		},
		"tags":       []interface{}{"plugin", "cache", "redis", "postgres"},
		"categories": []interface{}{"builtin", "cache", "redis", "postgres"},
	}
)
View Source
var ErrInvalidAddressPortPair = errors.New("invalid address:port pair")

Functions

This section is empty.

Types

type CachePlugin

type CachePlugin struct {
	goplugin.NetRPCUnsupportedPlugin
	Impl Plugin
}

func NewCachePlugin

func NewCachePlugin(impl Plugin) *CachePlugin

NewCachePlugin returns a new instance of the CachePlugin.

func (*CachePlugin) GRPCClient

func (p *CachePlugin) GRPCClient(_ context.Context, _ *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient returns the plugin client.

func (*CachePlugin) GRPCServer

func (p *CachePlugin) GRPCServer(_ *goplugin.GRPCBroker, s *grpc.Server) error

GRPCServer registers the plugin with the gRPC server.

type Plugin

type Plugin struct {
	goplugin.GRPCPlugin
	v1.GatewayDPluginServiceServer

	Logger hclog.Logger

	// Cache configuration.
	RedisClient        *goRedis.Client
	RedisURL           string
	Expiry             time.Duration
	DefaultDBName      string
	ScanCount          int64
	ExitOnStartupError bool

	// Periodic invalidator configuration.
	PeriodicInvalidatorEnabled    bool
	PeriodicInvalidatorStartDelay time.Duration
	PeriodicInvalidatorInterval   time.Duration
	APIAddress                    string
}

func (*Plugin) GetPluginConfig

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

GetPluginConfig returns the plugin config.

func (*Plugin) OnClosed added in v0.0.5

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

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.

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.

func (*Plugin) PeriodicInvalidator added in v0.0.8

func (p *Plugin) PeriodicInvalidator()

PeriodicInvalidator is a function that runs periodically and deletes all the cached client keys that are not valid anymore. This has two purposes: 1. If a client is not connected to the GatewayD anymore, it will be deleted. 2. Invalidate stale keys for responses. (This is not implemented yet.) https://github.com/gatewayd-io/gatewayd-plugin-cache/issues/4

type Proxy added in v0.0.8

type Proxy struct {
	Available []string `json:"available"`
	Busy      []string `json:"busy"`
	Total     int      `json:"total"`
}

Jump to

Keyboard shortcuts

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