chrysom

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 20 Imported by: 7

Documentation

Overview

Package chrysom provides a client in order to interact with argus.

Index

Constants

View Source
const (
	SuccessOutcome = "success"
	FailureOutcome = "failure"
)

Label Values

View Source
const (
	OutcomeLabel = "outcome"
)

Labels

View Source
const (
	PollCounter = "chrysom_polls_total"
)

Names

Variables

View Source
var (
	ErrAddressEmpty            = errors.New("argus address is required")
	ErrBucketEmpty             = errors.New("bucket name is required")
	ErrItemIDEmpty             = errors.New("item ID is required")
	ErrItemDataEmpty           = errors.New("data field in item is required")
	ErrUndefinedIntervalTicker = errors.New("interval ticker is nil. Can't listen for updates")
	ErrAuthAcquirerFailure     = errors.New("failed acquiring auth token")

	ErrFailedAuthentication = errors.New("failed to authentication with argus")
	ErrBadRequest           = errors.New("argus rejected the request as invalid")

	ErrListenerNotStopped = errors.New("listener is either running or starting")
	ErrListenerNotRunning = errors.New("listener is either stopped or stopping")
)

Errors that can be returned by this package. Since some of these errors are returned wrapped, it is safest to use errors.Is() to check for them. Some internal errors might be unwrapped from output errors but unless these errors become exported, they are not part of the library API and may change in future versions.

Functions

func Metrics added in v0.3.5

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

Types

type Auth

type Auth struct {
	JWT   acquire.RemoteBearerTokenAcquirerOptions
	Basic string
}

type Client

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

func NewClient added in v0.3.11

func NewClient(config ClientConfig, getLogger func(ctx context.Context) log.Logger) (*Client, error)

func (*Client) GetItems

func (c *Client) GetItems(ctx context.Context, owner string) (Items, error)

GetItems fetches all items that belong to a given owner.

func (*Client) PushItem added in v0.3.11

func (c *Client) PushItem(ctx context.Context, owner string, item model.Item) (PushResult, error)

PushItem creates a new item if one doesn't already exist. If an item exists and the ownership matches, the item is simply updated.

func (*Client) RemoveItem added in v0.3.11

func (c *Client) RemoveItem(ctx context.Context, id, owner string) (model.Item, error)

RemoveItem removes the item if it exists and returns the data associated to it.

func (*Client) Start added in v0.3.5

func (c *Client) Start(ctx context.Context) error

Start begins listening for updates on an interval given that client configuration is setup correctly. If a listener process is already in progress, calling Start() is a NoOp. If you want to restart the current listener process, call Stop() first.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop requests the current listener process to stop and waits for its goroutine to complete. Calling Stop() when a listener is not running (or while one is getting stopped) returns an error.

type ClientConfig

type ClientConfig struct {
	// Address is the Argus URL (i.e. https://example-argus.io:8090)
	Address string

	// Bucket partition to be used by this client.
	Bucket string

	// HTTPClient refers to the client that will be used to send requests.
	// (Optional) Defaults to http.DefaultClient.
	HTTPClient *http.Client

	// Auth provides the mechanism to add auth headers to outgoing requests.
	// (Optional) If not provided, no auth headers are added.
	Auth Auth

	// Logger to be used by the client.
	// (Optional). By default a no op logger will be used.
	Logger log.Logger

	// Listen helps enable and configure the listener feature of the client.
	// (Optional) If section is not provided with Listener, this
	// feature will be disabled for the client.
	Listen ListenerConfig
}

type ConfigureListener

type ConfigureListener interface {
	// SetListener will attempt to set the lister.
	SetListener(listener Listener) error
}

type Items added in v0.3.11

type Items []model.Item

type Listener

type Listener interface {
	// Update is called when we get changes to our item listeners with either
	// additions, or updates.
	//
	// The list of hooks must contain only the current items.
	Update(items Items)
}

type ListenerConfig added in v0.3.12

type ListenerConfig struct {
	// Listener provides a mechanism to fetch a copy of all items within a bucket on
	// an interval.
	// (Optional). If not provided, listening won't be enabled for this client.
	Listener Listener

	// PullInterval is how often listeners should get updates.
	// (Optional). Defaults to 5 seconds.
	PullInterval time.Duration

	// MetricsProvider helps initialize metrics collectors.
	// (Optional). By default a discard provider will be used.
	MetricsProvider provider.Provider
}

ListenerConfig contains config data to enable listening for the Argus client.

type ListenerFunc

type ListenerFunc func(items Items)

func (ListenerFunc) Update

func (listener ListenerFunc) Update(items Items)

type Option

type Option func(r *storeConfig)

Option is the function used to configure a store.

func WithListener

func WithListener(listener Listener) Option

WithListener sets a Listener to use for the store.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets a logger to use for the store.

func WithStorage

func WithStorage(pusher Pusher) Option

WithStorage sets a Pusher to use for the store.

type PushReader added in v0.3.3

type PushReader interface {
	Pusher
	Reader
}

type PushResult added in v0.3.8

type PushResult string

PushResult is a simple type to indicate the result type for the PushItem operation.

const (
	CreatedPushResult PushResult = "created"
	UpdatedPushResult PushResult = "ok"
)

Types of pushItem successful results.

type Pusher

type Pusher interface {
	// PushItem adds the item and establishes its link to the given owner in the store.
	PushItem(ctx context.Context, owner string, item model.Item) (PushResult, error)

	// Remove will remove the matching item from the store and return it.
	RemoveItem(ctx context.Context, id, owner string) (model.Item, error)
}

type Reader

type Reader interface {
	// GeItems returns all the items that belong to this owner.
	GetItems(ctx context.Context, owner string) (Items, error)

	// Start kicks off listening for snapshots of all items in the store.
	Start(ctx context.Context) error

	// Stop will stop the listener provided there was an active one.
	Stop(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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