dal

package
v0.0.0-...-7cb0e1f Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

An abstraction layer for accessing data in etcd

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CfgUtilPushStats

type CfgUtilPushStats struct {
	MonitorAdded   int
	AlerterAdded   int
	MonitorSkipped int
	AlerterSkipped int
	MonitorRemoved int
	AlerterRemoved int
}

type ClusterStats

type ClusterStats struct {
	Members  map[string]*json.RawMessage
	Director *json.RawMessage
}

type Dal

type Dal struct {
	Client     client.Client
	ClientConf client.Config
	KeysAPI    client.KeysAPI
	Members    []string
	Prefix     string
	Replace    bool
	Dryrun     bool
	Nosync     bool
	Log        log.FieldLogger
}

func New

func New(prefix string, members []string, userpass string, replace, dryrun, nosync bool) (*Dal, error)

func (*Dal) ClearCheckReference

func (d *Dal) ClearCheckReference(memberID, keyName string) error

Remove check reference for a given memberID + checkName

func (*Dal) ClearCheckReferences

func (d *Dal) ClearCheckReferences(memberID string) error

Remove all key refs under individual member config dir

func (*Dal) CreateCheckReference

func (d *Dal) CreateCheckReference(memberID, keyName string) error

Create a check reference for a specific member under /cluster/members/*/config/*; check ref key is base64 encodded, value is set to the keyName

func (*Dal) CreateDirectorState

func (d *Dal) CreateDirectorState(data string) error

Create director state entry (expecting director state key to not exist)

func (*Dal) Delete

func (d *Dal) Delete(key string, recursive bool) error

func (*Dal) FetchAlerterConfig

func (d *Dal) FetchAlerterConfig(alertKey string) (string, error)

Fetch a specific alerter config by its key name

func (*Dal) FetchAllMemberRefs

func (d *Dal) FetchAllMemberRefs() (map[string]string, []string, error)

Recursively fetch '/cluster/members/*/config/*', construct and return dataset that has 'map[check_key]memberID' structure

TODO: This is not great; should utilize caching at some point

func (*Dal) FetchCheckStats

func (d *Dal) FetchCheckStats() (map[string]*MemberStat, error)

Fetch how many checks each cluster member has

func (*Dal) FetchEvents

func (d *Dal) FetchEvents(types []string) ([]byte, error)

Fetch event data that matches at least one type specified in 'types'; if 'types' is empty, do not perform any filtering.

func (*Dal) FetchState

func (d *Dal) FetchState() ([]byte, error)

Wrapper for fetching state information

func (*Dal) FetchStateWithTags

func (d *Dal) FetchStateWithTags(tags []string) ([]byte, error)

Wrapper for fetching state information that is tagged with `tags`

Note: To avoid having to import the MonitorConfig struct, we will inspect it

manually via assertions and reflect.

func (*Dal) Get

func (d *Dal) Get(key string, getOptions *GetOptions) (map[string]string, error)

Get wrapper; either returns the key contents or error; accepts *GetOptions for specifying whether the method should recurse and/or use the default prefix.

By default, passing a nil for Options will NOT recurse and use the default prefix of `d.Prefix`. Passing in a `GetOptions{NoPrefix: true}` will cause GET to not use ANY prefix (assuming key name includes full path).

Returns a map[keyname]value; if dir is empty, return an empty map.

func (*Dal) GetCheckKeys

func (d *Dal) GetCheckKeys() ([]string, error)

Get a slice of all check keys in etcd (under /monitor/*)

func (*Dal) GetCheckKeysWithMemberTag

func (d *Dal) GetCheckKeysWithMemberTag() (map[string]string, error)

Return check keys along with tags (if any); map k = check key name, v = member tag (if any)

func (*Dal) GetCheckMemberTag

func (d *Dal) GetCheckMemberTag(checkKey string) (string, error)

func (*Dal) GetClusterMemberTags

func (d *Dal) GetClusterMemberTags(memberID string) ([]string, error)

Get tags for a single cluster member

func (*Dal) GetClusterMembers

func (d *Dal) GetClusterMembers() ([]string, error)

Get slice of all member id's under /cluster/members/*

func (*Dal) GetClusterMembersWithTags

func (d *Dal) GetClusterMembersWithTags() (map[string][]string, error)

Keys == member id, value == slice of tags

func (*Dal) GetClusterStats

func (d *Dal) GetClusterStats() (*ClusterStats, error)

func (*Dal) IsKeyNotFound

func (d *Dal) IsKeyNotFound(err error) bool

wrapper for etcd client's KeyNotFound error

func (*Dal) KeyExists

func (d *Dal) KeyExists(key string) (bool, bool, error)

Check if a given key exists and whether it's a dir or not (or return error)

func (*Dal) NewWatcher

func (d *Dal) NewWatcher(key string, recursive bool) client.Watcher

func (*Dal) NewWatcherForOverwatch

func (d *Dal) NewWatcherForOverwatch(key string, recursive bool) (client.Watcher, error)

Same as NewWatcher, except we generate a fresh etcd client

func (*Dal) PushConfigs

func (d *Dal) PushConfigs(configType string, configs map[string][]byte) (int, int, error)

Wrapper for comparing existing value in etcd + (potentially) pushing value to etcd. If d.Replace is set, value in etcd will be replaced even if it's found to match

func (*Dal) PushFullConfigs

func (d *Dal) PushFullConfigs(fullConfigs *FullConfigs) (*CfgUtilPushStats, []string)

Wrapper for pushing monitor and alerter configs + optionally syncing data

func (*Dal) Refresh

func (d *Dal) Refresh(key string, ttl int) error

Set TTL for a given key

func (*Dal) Set

func (d *Dal) Set(key, value string, opt *SetOptions) error

A wrapper for setting a new key

func (*Dal) UpdateCheckState

func (d *Dal) UpdateCheckState(state bool, checkName string) error

func (*Dal) UpdateDirectorState

func (d *Dal) UpdateDirectorState(data, prevValue string, force bool) error

Update director state entry (expecting previous director state to match 'prevValue') (or force the update, ignoring prevValue)

type FullConfigs

type FullConfigs struct {
	AlerterConfigs map[string][]byte // alerter name : json blob
	MonitorConfigs map[string][]byte // monitor name : json blob
}

type GetOptions

type GetOptions struct {
	Recurse  bool
	NoPrefix bool
	// contains filtered or unexported fields
}

type IDal

type IDal interface {
	Get(string, *GetOptions) (map[string]string, error)
	Set(string, string, *SetOptions) error
	Delete(string, bool) error
	Refresh(string, int) error
	KeyExists(string) (bool, bool, error)
	IsKeyNotFound(error) bool
	CreateDirectorState(string) error
	UpdateDirectorState(string, string, bool) error
	NewWatcher(string, bool) client.Watcher
	NewWatcherForOverwatch(string, bool) (client.Watcher, error)
	GetClusterMembers() ([]string, error)
	GetCheckKeys() ([]string, error)
	GetCheckKeysWithMemberTag() (map[string]string, error)
	CreateCheckReference(string, string) error
	ClearCheckReference(string, string) error
	ClearCheckReferences(string) error
	FetchAllMemberRefs() (map[string]string, []string, error)
	FetchCheckStats() (map[string]*MemberStat, error)
	FetchAlerterConfig(string) (string, error)
	FetchState() ([]byte, error)
	FetchStateWithTags([]string) ([]byte, error)
	UpdateCheckState(bool, string) error
	GetClusterStats() (*ClusterStats, error)
	FetchEvents([]string) ([]byte, error)
	GetClusterMembersWithTags() (map[string][]string, error)
	GetClusterMemberTags(string) ([]string, error)
	GetCheckMemberTag(string) (string, error)
	PushConfigs(string, map[string][]byte) (int, int, error)
	PushFullConfigs(*FullConfigs) (*CfgUtilPushStats, []string)
}

type MemberStat

type MemberStat struct {
	NumChecks int
	Tags      []string
}

Helper struct for FetchCheckStats()

type SetOptions

type SetOptions struct {
	// If SetOptions.Dir=true then value is ignored.
	Dir       bool
	TTLSec    int
	PrevExist string

	// Create parents will recursively create parent directories as needed.
	// The overall prefix defined as Dal.Prefix can not be set this way. This will create any
	// parents up to but not including that prefix.
	CreateParents bool

	// To be used with create parents.
	// If depth > 0 it will only create depth number of parents.
	// If depth < 0 it will try to create as many parents as necessary.
	// If depth == 0 it will not create any parents. This behaves the same as Set().
	Depth int
}

Jump to

Keyboard shortcuts

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