monitor

package
v0.0.0-...-35e2b90 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

README

Monitor

This package provides the ability to populate a crd.Controller dynamically via a functon that provides additional config. The monitor will acquire snapshots of additional changes and populate the crd.Controller as needed.

Creating a Monitor

To create a monitor, you should provide the crd.Controller, a polling interval, and a function that returns []*model.Config.

monitor := file.NewMonitor(
    controller,      // The crd controller holding the store and event handlers
    1*time.Second,   // How quickly the monitor requests new snapshots
    getSnapshotFunc) // The function used to acquire new config

Running a Monitor

Once created, you simply run the monitor, providing a stop channel.

stop := make(chan struct{})
...
monitor.Start(stop)

The Start method will kick off an asynchronous polling loop and will return immediately.

Example

To configure and run a monitor that watches for file changes to update an in-memory config store:

// Configure the config store
store := memory.Make(configDescriptor)
controller = memory.NewController(store)
// Create an object that will take snapshots of config
fileSnapshot := configmonitor.NewFileSnapshot(args.Config.FileDir, configDescriptor)
// Provide snapshot func to monitor
fileMonitor := configmonitor.NewMonitor(controller, 100*time.Millisecond, fileSnapshot.ReadFile)

// Run the controller and monitor
stop := make(chan struct{})
go controller.run(stop)
monitor.Start(stop)

See monitor_test.go and file_snapshot_test.go for more examples.

Notes

Always use a Controller

While the API supports any model.ConfigStore, it is recommended to always use a crd.Controller so that other system components can be notified of changes via controller.RegisterEventHandler().

Start behavior

The Start method will immediately check the provided getSnapshotFunc and update the controller appropriately before returning. This helps to simplify tests that rely on starting in a particular state.

After performing an initial update, the Start method then forks an asynchronous polling loop for update/termination.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopilotClient

type CopilotClient interface {
	copilotapi.IstioCopilotClient
}

CopilotClient defines a local interface for interacting with Cloud Foundry Copilot

type CopilotSnapshot

type CopilotSnapshot struct {
	// contains filtered or unexported fields
}

CopilotSnapshot provides a snapshot of configuration from the Cloud Foundry Copilot component.

func NewCopilotSnapshot

func NewCopilotSnapshot(store model.ConfigStore, client CopilotClient, hostnameBlacklist []string, timeout time.Duration) *CopilotSnapshot

NewCopilotSnapshot returns a CopilotSnapshot used for integration with Cloud Foundry. The store is required to discover any existing gateways: the generated config will reference those gateways The client is used to discover Cloud Foundry Routes from Copilot The snapshot will not return routes for any hostnames which end with strings on the hostnameBlacklist

func (*CopilotSnapshot) ReadConfigFiles

func (c *CopilotSnapshot) ReadConfigFiles() ([]*model.Config, error)

ReadConfigFiles returns a complete set of VirtualServices for all Cloud Foundry routes known to Copilot. It may be used for the getSnapshotFunc when constructing a NewMonitor

type FileSnapshot

type FileSnapshot struct {
	// contains filtered or unexported fields
}

FileSnapshot holds a reference to a file directory that contains crd config and filter criteria for which of those configs will be parsed.

func NewFileSnapshot

func NewFileSnapshot(root string, descriptor model.ConfigDescriptor) *FileSnapshot

NewFileSnapshot returns a snapshotter. If no types are provided in the descriptor, all IstioConfigTypes will be allowed.

func (*FileSnapshot) ReadConfigFiles

func (f *FileSnapshot) ReadConfigFiles() ([]*model.Config, error)

ReadConfigFiles parses files in the root directory and returns a sorted slice of eligible model.Config. This can be used as a configFunc when creating a Monitor.

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor will poll a config function in order to update a ConfigStore as changes are found.

func NewMonitor

func NewMonitor(delegateStore model.ConfigStore, checkInterval time.Duration, getSnapshotFunc func() ([]*model.Config, error)) *Monitor

NewMonitor creates a Monitor and will delegate to a passed in controller. The controller holds a reference to the actual store. Any func that returns a []*model.Config can be used with the Monitor

func (*Monitor) Start

func (m *Monitor) Start(stop chan struct{})

Start starts a new Monitor. Immediately checks the Monitor getSnapshotFunc and updates the controller. It then kicks off an asynchronous event loop that periodically polls the getSnapshotFunc for changes until a close event is sent.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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