Documentation
¶
Index ¶
- Variables
- func GetQueryFromRequest(req string) (string, error)
- func GetTablesFromQuery(query string) ([]string, error)
- type CachePlugin
- type Plugin
- func (p *Plugin) GetPluginConfig(ctx context.Context, req *structpb.Struct) (*structpb.Struct, error)
- func (p *Plugin) OnClosed(ctx context.Context, req *structpb.Struct) (*structpb.Struct, error)
- func (p *Plugin) OnConfigLoaded(ctx context.Context, req *structpb.Struct) (*structpb.Struct, error)
- func (p *Plugin) OnTrafficFromClient(ctx context.Context, req *structpb.Struct) (*structpb.Struct, error)
- func (p *Plugin) OnTrafficFromServer(ctx context.Context, resp *structpb.Struct) (*structpb.Struct, error)
- func (p *Plugin) PeriodicInvalidator()
- type Proxy
Constants ¶
This section is empty.
Variables ¶
var ( 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", }) )
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": "Apache-2.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", ""), "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"), }, "hooks": []interface{}{ "onConfigLoaded", "onTrafficFromClient", "onTrafficFromServer", "onClosed", }, "tags": []interface{}{"plugin", "cache", "redis", "postgres"}, "categories": []interface{}{"builtin", "cache", "redis", "postgres"}, } )
Functions ¶
func GetQueryFromRequest ¶ added in v0.0.7
GetQueryFromRequest decodes the request and returns the query.
func GetTablesFromQuery ¶ added in v0.0.7
GetTablesFromQuery returns the tables used in a query.
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(ctx context.Context, b *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)
GRPCClient returns the plugin client.
func (*CachePlugin) GRPCServer ¶
func (p *CachePlugin) GRPCServer(b *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
RedisStore *redis.RedisStore
RedisURL string
Expiry time.Duration
DefaultDBName string
// Periodic invalidator configuration.
PeriodicInvalidatorEnabled bool
PeriodicInvalidatorStartDelay time.Duration
PeriodicInvalidatorInterval time.Duration
APIAddress string
}
func (*Plugin) GetPluginConfig ¶
func (p *Plugin) GetPluginConfig( ctx context.Context, req *structpb.Struct, ) (*structpb.Struct, error)
GetPluginConfig returns the plugin config.
func (*Plugin) OnConfigLoaded ¶
func (p *Plugin) OnConfigLoaded( ctx context.Context, req *structpb.Struct, ) (*structpb.Struct, error)
OnConfigLoaded is called when the global config is loaded by GatewayD.
func (*Plugin) OnTrafficFromClient ¶
func (p *Plugin) OnTrafficFromClient( ctx context.Context, req *structpb.Struct, ) (*structpb.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 *structpb.Struct, ) (*structpb.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