Documentation ¶
Index ¶
- Constants
- Variables
- type CachePlugin
- type Plugin
- func (p *Plugin) GetPluginConfig(_ context.Context, _ *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) OnClosed(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(_ context.Context, resp *v1.Struct) (*v1.Struct, error)
- func (p *Plugin) PeriodicInvalidator()
- func (p *Plugin) UpdateCache(ctx context.Context)
- type Proxy
Constants ¶
const AddressPortPairLength = 2
Variables ¶
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", }) )
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.GetName(): &CachePlugin{}, } PluginConfig = map[string]interface{}{ "id": map[string]interface{}{ "name": PluginID.GetName(), "version": PluginID.GetVersion(), "remoteUrl": PluginID.GetRemoteUrl(), }, "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"), "cacheBufferSize": sdkConfig.GetEnv("CACHE_CHANNEL_BUFFER_SIZE", "100"), }, "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"}, } )
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 UpdateCacheChannel chan *v1.Struct // Periodic invalidator configuration. PeriodicInvalidatorEnabled bool PeriodicInvalidatorStartDelay time.Duration PeriodicInvalidatorInterval time.Duration APIAddress string }
func (*Plugin) GetPluginConfig ¶
GetPluginConfig returns the plugin config.
func (*Plugin) OnTrafficFromClient ¶
OnTrafficFromClient is called when a request is received by GatewayD from the client.
func (*Plugin) OnTrafficFromServer ¶
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