Documentation ¶
Overview ¶
Package db is responsible for the communication between the database backends and the bgpmon daemon. It abstracts database operations through types that are named Executors. Executors allow for one off, or transactional operations, that can be timed out using a context, and can be database unware by getting the appropriate SQL statement depending what type of database exists on the back.
Index ¶
- Constants
- type Capture
- type CaptureFilterOptions
- type CaptureTable
- type CommonMessage
- type CommonReply
- type DBer
- type Entity
- type EntityFilterOptions
- type FilterOptions
- type ReadStream
- type Session
- func (s *Session) Close() error
- func (s *Session) DB() *sql.DB
- func (s *Session) GetMaxWorkers() int
- func (s *Session) GetTimeout() time.Duration
- func (s *Session) OpenReadStream(sType SessionType, fo FilterOptions) (ReadStream, error)
- func (s *Session) OpenWriteStream(sType SessionType) (WriteStream, error)
- type SessionExecutor
- type SessionType
- type TimeoutDBer
- type WriteStream
Constants ¶
const (
// AnyCollector is a wild card for collectors in the DB.
AnyCollector = "%"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capture ¶
type Capture struct { ID string // the capture_id that together with the table makes it unique Timestamp time.Time Origin int // origin as Advertised []*net.IPNet Withdrawn []*net.IPNet ASPath []int ColIP net.IP PeerIP net.IP NextHop net.IP // contains filtered or unexported fields }
Capture represent a BGPCapture a row in the generated capture tables. It describes a single BGP event.
func NewCaptureFromPB ¶
func NewCaptureFromPB(pbCap *pb.BGPCapture) (*Capture, error)
NewCaptureFromPB returns a *Capture populated from a pb.BGPCapture
type CaptureFilterOptions ¶
type CaptureFilterOptions struct {
// contains filtered or unexported fields
}
CaptureFilterOptions contains the options to filter by capture messages.
func DefaultCaptureFilterOptions ¶
func DefaultCaptureFilterOptions() *CaptureFilterOptions
DefaultCaptureFilterOptions returns a CaptureFilterOptions with any collector, and time.Now() as the start and end date. This is unlikely to return any captures.
func NewCaptureFilterOptions ¶
func NewCaptureFilterOptions(collector string, start time.Time, end time.Time) *CaptureFilterOptions
NewCaptureFilterOptions returns a FilterOptions interface for filtering captures.
func (*CaptureFilterOptions) AllowAdvPrefixes ¶
func (cfo *CaptureFilterOptions) AllowAdvPrefixes(prefs ...*net.IPNet)
AllowAdvPrefixes adds the provided prefixes to a list of prefixes to filter by. If any prefix on that list appears, the Capture will pass the filter.
func (*CaptureFilterOptions) AllowSubnets ¶
func (cfo *CaptureFilterOptions) AllowSubnets(prefs ...*net.IPNet)
AllowSubnets will allow captures to pass this filter if they have an advertized prefix that falls under one of the provided prefixes.
func (*CaptureFilterOptions) SetOrigin ¶
func (cfo *CaptureFilterOptions) SetOrigin(as int)
SetOrigin filters by the provided origin autonomous system (AS).
type CaptureTable ¶
type CaptureTable struct {
// contains filtered or unexported fields
}
CaptureTable represents a row in the main table. It describes an existing table populated with BGPCaptures
type CommonMessage ¶
type CommonMessage interface { // This table holds the names of all other tables created. GetMainTable() string // This holds all info on the collectors. GetNodeTable() string // This holds info on customers or anyone interested in the stored // BGP data. GetEntityTable() string SetMainTable(string) SetNodeTable(string) SetEntityTable(string) }
CommonMessage is a basic interface which allows the getting and setting of the the main and node tables that are usually involved in most db operations.
type CommonReply ¶
type CommonReply interface {
Error() error
}
CommonReply will wrap any data that needs to be returned by a dbOp. Each CommonReply has one thing in common, the ability to return an error.
type Entity ¶
Entity represents a row in the entities table. It describes a party interested in particular BGP data, like the owner of a prefix.
func NewEntityFromConfig ¶
func NewEntityFromConfig(ec *config.EntityConfig) (e *Entity, err error)
NewEntityFromConfig returns an Entity populated from an EntityConfig.
func NewEntityFromPB ¶
NewEntityFromPB returns an Entity populated from a protobuf.
func (*Entity) ToProtobuf ¶
ToProtobuf returns a protobuf Entity with the same values as this entity
type EntityFilterOptions ¶
type EntityFilterOptions struct {
// contains filtered or unexported fields
}
EntityFilterOptions holds all the fields to filter entities.
func NewEntityFilterOptions ¶
func NewEntityFilterOptions(name string) *EntityFilterOptions
NewEntityFilterOptions returns FilterOptions for an Entity
type FilterOptions ¶
type FilterOptions interface{}
FilterOptions is an empty interface. Only the implementations of it are important.
type ReadStream ¶
type ReadStream interface { Read() bool // Data returns an interface so each implementation of a read stream is free to choose // what type it returns. This should be constant for each stream, and should be documented. Data() interface{} Bytes() []byte Err() error Close() }
ReadStream represents the different kinds of read streams that can be done on a session
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a session to the underlying db. It holds references to the schema manager and workerpool.
func NewSession ¶
NewSession returns a newly allocated Session
func (*Session) GetMaxWorkers ¶
GetMaxWorkers returns the maximum amount of workers that the session supports
func (*Session) GetTimeout ¶
GetTimeout satisfies the GetTimeouter interface on a Session so it can be a TimeoutDBer
func (*Session) OpenReadStream ¶
func (s *Session) OpenReadStream(sType SessionType, fo FilterOptions) (ReadStream, error)
OpenReadStream opens and returns a ReadStream with the given type, or an error if no such type exists
func (*Session) OpenWriteStream ¶
func (s *Session) OpenWriteStream(sType SessionType) (WriteStream, error)
OpenWriteStream opens and returns a WriteStream with the given type, or an error if no such type exists
type SessionExecutor ¶
type SessionExecutor struct { util.SQLExecutor // contains filtered or unexported fields }
SessionExecutor wraps an util.SQLExecutor with queryProvider
type SessionType ¶
type SessionType int
SessionType describes the supported session streams.
const ( // SessionWriteCapture is provided to a Sessioner's OpenWriteStream to open // a capture write stream. SessionWriteCapture SessionType = iota // SessionReadCapture is provided to a Sessioner's OpenReadStream to open a // read capture stream. SessionReadCapture // SessionReadPrefix is provided to a Sessioner's OpenReadStream to open a // read prefix stream. SessionReadPrefix // SessionWriteEntity is provided to a Sessions OpenWriteStream to open // an entity write stream. SessionWriteEntity // SessionReadEntity is provided to a Sessions OpenReadStream to open // an entity read stream. SessionReadEntity )
type TimeoutDBer ¶
type TimeoutDBer interface { DBer util.GetTimeouter }
TimeoutDBer composes DBer and GetTimeouter to return timeout duration for dbOps
type WriteStream ¶
WriteStream represents the different kind of write streams that can be done on a session