Documentation ¶
Overview ¶
Package kvdbproxy implements proxy for a kvdbsync with ability to skip selected change events.
The primary use case is:
- a plugin watches configuration in key-value datastore and processes the changes in a "standard" way
- a part of the configuration is processed "alternatively" and it is persisted into key-value datastore afterwards
- the change events caused by persisting need to be ignored since the change is already applied
The limitations:
- it is not possible to define multiple ignored events for the key.
Index ¶
- Variables
- type Deps
- type KvdbsyncMock
- func (kv *KvdbsyncMock) AddIgnoreEntry(key string, op datasync.Op)
- func (kv *KvdbsyncMock) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)
- func (kv *KvdbsyncMock) Put(key string, data proto.Message, opts ...datasync.PutOption) error
- func (kv *KvdbsyncMock) Watch(resyncName string, changeChan chan datasync.ChangeEvent, ...) (datasync.WatchRegistration, error)
- type Option
- type Plugin
- func (plugin *Plugin) AddIgnoreEntry(key string, op datasync.Op)
- func (plugin *Plugin) Close() error
- func (plugin *Plugin) DelIgnoreEntry(key string)
- func (plugin *Plugin) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)
- func (plugin *Plugin) Init() error
- func (plugin *Plugin) Put(key string, data proto.Message, opts ...datasync.PutOption) error
- func (plugin *Plugin) Watch(resyncName string, changeChan chan datasync.ChangeEvent, ...) (datasync.WatchRegistration, error)
- type Proxy
Constants ¶
This section is empty.
Variables ¶
var DefaultPlugin = *NewPlugin()
DefaultPlugin is default instance of Plugin.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct { infra.PluginDeps KVDB kvsyncDelegate }
Deps group the dependencies of the Plugin
type KvdbsyncMock ¶
type KvdbsyncMock struct {
// contains filtered or unexported fields
}
KvdbsyncMock mocks the behavior of kvdbproxy plugin for test purposes
func (*KvdbsyncMock) AddIgnoreEntry ¶
func (kv *KvdbsyncMock) AddIgnoreEntry(key string, op datasync.Op)
AddIgnoreEntry is a mock function that currently does nothing.
func (*KvdbsyncMock) Delete ¶
Delete mocks the delete operation. If the key matches a prefix that is watched it generates a change event.
func (*KvdbsyncMock) Put ¶
Put mocks the put operation. If the key matches a prefix that is watched it generates a change event.
func (*KvdbsyncMock) Watch ¶
func (kv *KvdbsyncMock) Watch(resyncName string, changeChan chan datasync.ChangeEvent, resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error)
Watch mocks the watch operation. It stores the changeChan and keyPrefixes for the subsequent asserts. Other arguments are ignored.
type Option ¶
type Option func(*Plugin)
Option is a function that acts on a Plugin to inject Dependencies or configuration
type Plugin ¶
Plugin implements proxy for a kvdbsync with ability to skip selected change events. The primary use case is:
- a plugin watches configuration in key-value datastore and processes the changes in a "standard" way
- a part of the configuration is processed "alternatively" and it is persisted into key-value datastore afterwards
- the change events caused by persisting need to be ignored since the change is already applied
The limitations:
- it is not possible to define multiple ignored events for the key.
func (*Plugin) AddIgnoreEntry ¶
AddIgnoreEntry adds the entry into ignore list. The first change event matching the given key and operation is skipped. Once the event is skipped the entry is removed from the list.
func (*Plugin) DelIgnoreEntry ¶
DelIgnoreEntry removes the entry from ignore list. E.g.: The method might be used if the call that was supposed to generate the change failed.
func (*Plugin) Watch ¶
func (plugin *Plugin) Watch(resyncName string, changeChan chan datasync.ChangeEvent, resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error)
Watch forwards the subscription request to the injected kvdbsync plugin. The change events are filtered based on the plugin ignore list. The resync events are untouched.
type Proxy ¶
type Proxy interface { // AddIgnoreEntry adds the entry into ignore list. The first change event matching the given key and operation // is skipped. Once the event is skipped the entry is removed from the list. AddIgnoreEntry(key string, op datasync.Op) // Watch forwards the subscription request to the injected kvdbsync plugin. The change events // are filtered based on the plugin ignore list. The resync events are untouched. Watch(resyncName string, changeChan chan datasync.ChangeEvent, resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error) // Put puts data into a datastore using the injected kvdbsync plugin. Put(key string, data proto.Message, opts ...datasync.PutOption) error // Delete deletes data from a datastore using the injected kvdbsync plugin. Delete(key string, opts ...datasync.DelOption) (existed bool, err error) }
Proxy forwards calls to a kvdbsync plugin. It allows to filter changeEvents that come from the plugin.
func NewKvdbsyncMock ¶
func NewKvdbsyncMock() Proxy
NewKvdbsyncMock creates new instance of KvdbsyncMock