plugin

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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",
	})
)
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"),
		},
		"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"},
	}
)

Functions

func GetQueryFromRequest added in v0.0.7

func GetQueryFromRequest(req string) (string, error)

GetQueryFromRequest decodes the request and returns the query.

func GetTablesFromQuery added in v0.0.7

func GetTablesFromQuery(query string) ([]string, error)

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
	ScanCount     int64

	// 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) OnClosed added in v0.0.5

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

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

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