client

package
v2.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: Apache-2.0, Apache-2.0 Imports: 19 Imported by: 0

README

Log Cache Client

GoDoc slack.cloudfoundry.org

This is a golang client library for Log-Cache.

Usage

This repository should be imported as:

import logcache "code.cloudfoundry.org/log-cache/pkg/client"

NOTE: This client library is compatible with log-cache versions 1.5.x and above. For versions 1.4.x and below, please use go-log-cache.

Also, the master branch of log-cache/pkg/client reflects current (potentially development) state of log-cache-release. Branches are provided for compatibility with released versions of log-cache.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LAST_LOG_CACHE_VERSION_WITHOUT_INFO = semver.Version{
		Major: 1,
		Minor: 4,
		Patch: 7,
	}
	FIRST_LOG_CACHE_VERSION_AFTER_API_MOVE = semver.Version{
		Major: 2,
		Minor: 0,
		Patch: 0,
	}
)

Functions

func Walk

func Walk(ctx context.Context, sourceID string, v Visitor, r Reader, opts ...WalkOption)

Walk reads from the LogCache until the Visitor returns false.

func Window

func Window(ctx context.Context, v Visitor, w Walker, opts ...WindowOption)

Window crawls a reader incrementally to give the Visitor a batch of envelopes. Each start time is incremented by the set increment duration if that window produced data or not. This is useful when looking for trends over time.

Types

type AlwaysDoneBackoff

type AlwaysDoneBackoff struct{}

AlwaysDoneBackoff returns false for both OnErr and OnEmpty.

func (AlwaysDoneBackoff) OnEmpty

func (b AlwaysDoneBackoff) OnEmpty() bool

OnEmpty implements Backoff.

func (AlwaysDoneBackoff) OnErr

func (b AlwaysDoneBackoff) OnErr(error) bool

OnErr implements Backoff.

func (AlwaysDoneBackoff) Reset

func (b AlwaysDoneBackoff) Reset()

Reset implements Backoff.

type AlwaysRetryBackoff

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

AlwaysRetryBackoff returns true for both OnErr and OnEmpty after sleeping the given interval.

func NewAlwaysRetryBackoff

func NewAlwaysRetryBackoff(interval time.Duration) AlwaysRetryBackoff

NewAlwaysRetryBackoff returns a new AlwaysRetryBackoff.

func (AlwaysRetryBackoff) OnEmpty

func (b AlwaysRetryBackoff) OnEmpty() bool

OnEmpty implements Backoff.

func (AlwaysRetryBackoff) OnErr

func (b AlwaysRetryBackoff) OnErr(error) bool

OnErr implements Backoff.

func (AlwaysRetryBackoff) Reset

func (b AlwaysRetryBackoff) Reset()

Reset implements Backoff.

type Backoff

type Backoff interface {
	OnErr(error) bool
	OnEmpty() bool
	Reset()
}

Backoff is used to determine what to do if there is an empty batch or error. If there is an error, it will be passed to the method OnErr. If there is not an error and just an empty batch, the method OnEmpty will be invoked. If the either method returns false, then Walk exits. On a successful read that has envelopes, Reset will be invoked.

type Client

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

Client reads from LogCache via the RESTful or gRPC API.

func NewClient

func NewClient(addr string, opts ...ClientOption) *Client

NewIngressClient creates a Client.

func (*Client) LogCacheVMUptime

func (c *Client) LogCacheVMUptime(ctx context.Context) (int64, error)

func (*Client) LogCacheVersion

func (c *Client) LogCacheVersion(ctx context.Context) (semver.Version, error)

func (*Client) Meta

func (c *Client) Meta(ctx context.Context) (map[string]*logcache_v1.MetaInfo, error)

Meta returns meta information from the entire LogCache.

func (*Client) PromQL

func (c *Client) PromQL(
	ctx context.Context,
	query string,
	opts ...PromQLOption,
) (*logcache_v1.PromQL_InstantQueryResult, error)

PromQL issues a PromQL instant query against Log Cache data.

func (*Client) PromQLRange

func (c *Client) PromQLRange(
	ctx context.Context,
	query string,
	opts ...PromQLOption,
) (*logcache_v1.PromQL_RangeQueryResult, error)

PromQL issues a PromQL range query against Log Cache data.

func (*Client) PromQLRangeRaw

func (c *Client) PromQLRangeRaw(
	ctx context.Context,
	query string,
	opts ...PromQLOption,
) (*PromQLQueryResult, error)

func (*Client) PromQLRaw

func (c *Client) PromQLRaw(
	ctx context.Context,
	query string,
	opts ...PromQLOption,
) (*PromQLQueryResult, error)

func (*Client) Read

func (c *Client) Read(
	ctx context.Context,
	sourceID string,
	start time.Time,
	opts ...ReadOption,
) ([]*loggregator_v2.Envelope, error)

Read queries the LogCache and returns the given envelopes. To override any query defaults (e.g., end time), use the according option.

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption configures the LogCache client.

func WithHTTPClient

func WithHTTPClient(h HTTPClient) ClientOption

WithHTTPClient sets the HTTP client. It defaults to a client that timesout after 5 seconds.

func WithViaGRPC

func WithViaGRPC(opts ...grpc.DialOption) ClientOption

WithViaGRPC enables gRPC instead of HTTP/1 for reading from LogCache.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is an interface that represents a http.Client.

type Oauth2HTTPClient

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

Oauth2HTTPClient sets the "Authorization" header of any outgoing request. It gets a JWT from the configured Oauth2 server. It only gets a new JWT when a request comes back with a 401.

func NewOauth2HTTPClient

func NewOauth2HTTPClient(oauth2Addr, client, clientSecret string, opts ...Oauth2Option) *Oauth2HTTPClient

NewOauth2HTTPClient creates a new Oauth2HTTPClient.

func (*Oauth2HTTPClient) Do

func (c *Oauth2HTTPClient) Do(req *http.Request) (*http.Response, error)

Do implements HTTPClient. It adds the Authorization header to the request (unless the header already exists). If the token is expired, it will reach out the Oauth2 server and get a new one. The given error CAN be from the request to the Oauth2 server.

Do modifies the given Request. It is invalid to use the same Request instance on multiple go-routines.

type Oauth2Option

type Oauth2Option interface {
	// contains filtered or unexported methods
}

Oauth2Option configures the Oauth2HTTPClient.

func WithOauth2HTTPClient

func WithOauth2HTTPClient(client HTTPClient) Oauth2Option

WithOauth2HTTPClient sets the HTTPClient for the Oauth2HTTPClient. It defaults to the same default as Client.

func WithOauth2HTTPUser

func WithOauth2HTTPUser(username, password string) Oauth2Option

WithOauth2HTTPUser sets the username and password for user authentication.

type PromQLOption

type PromQLOption func(u *url.URL, q url.Values)

PromQLOption configures the URL that is used to submit the query. The RawQuery is set to the decoded query parameters after each option is invoked.

func WithPromQLEnd

func WithPromQLEnd(t time.Time) PromQLOption

func WithPromQLStart

func WithPromQLStart(t time.Time) PromQLOption

func WithPromQLStep

func WithPromQLStep(step string) PromQLOption

func WithPromQLTime

func WithPromQLTime(t time.Time) PromQLOption

WithPromQLTime returns a PromQLOption that configures the 'time' query parameter for a PromQL query.

type PromQLQueryResult

type PromQLQueryResult struct {
	Status    string           `json:"status"`
	Data      PromQLResultData `json:"data"`
	ErrorType string           `json:"errorType,omitempty"`
	Error     string           `json:"error,omitempty"`
}

type PromQLResultData

type PromQLResultData struct {
	ResultType string          `json:"resultType"`
	Result     json.RawMessage `json:"result,omitempty"`
}

type ReadOption

type ReadOption func(u *url.URL, q url.Values)

ReadOption configures the URL that is used to submit the query. The RawQuery is set to the decoded query parameters after each option is invoked.

func WithDescending

func WithDescending() ReadOption

WithDescending set the 'descending' query parameter to true. It defaults to false, yielding ascending order.

func WithEndTime

func WithEndTime(t time.Time) ReadOption

WithEndTime sets the 'end_time' query parameter to the given time. It defaults to empty, and therefore the end of the cache.

func WithEnvelopeTypes

func WithEnvelopeTypes(t ...logcache_v1.EnvelopeType) ReadOption

WithEnvelopeTypes sets the 'envelope_types' query parameter to the given value. It defaults to empty, and therefore any envelope type.

func WithLimit

func WithLimit(limit int) ReadOption

WithLimit sets the 'limit' query parameter to the given value. It defaults to empty, and therefore 100 envelopes.

func WithNameFilter

func WithNameFilter(nameFilter string) ReadOption

type Reader

type Reader func(
	ctx context.Context,
	sourceID string,
	start time.Time,
	opts ...ReadOption,
) ([]*loggregator_v2.Envelope, error)

Reader reads envelopes from LogCache. It will be invoked by Walker several time to traverse the length of the cache.

type RetryBackoff

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

RetryBackoff returns true for both OnErr and OnEmpty after sleeping the given interval for a limited number of times.

func NewRetryBackoff

func NewRetryBackoff(interval time.Duration, maxCount int) *RetryBackoff

NewRetryBackoff returns a new RetryBackoff.

func NewRetryBackoffOnErr

func NewRetryBackoffOnErr(interval time.Duration, maxCount int) *RetryBackoff

NewRetryBackoffOnErr returns a new RetryBackoff that only backs off no errors.

func (*RetryBackoff) OnEmpty

func (b *RetryBackoff) OnEmpty() bool

OnEmpty implements Backoff.

func (*RetryBackoff) OnErr

func (b *RetryBackoff) OnErr(error) bool

OnErr implements Backoff.

func (*RetryBackoff) Reset

func (b *RetryBackoff) Reset()

Reset implements Backoff.

type Visitor

type Visitor func([]*loggregator_v2.Envelope) bool

Visitor is invoked for each envelope batch. If the function returns false, it doesn't make any more requests. Otherwise it reaches out for the next batch of envelopes.

type WalkOption

type WalkOption interface {
	// contains filtered or unexported methods
}

WalkOption overrides defaults for Walk.

func WithWalkBackoff

func WithWalkBackoff(b Backoff) WalkOption

WithWalkBackoff sets the backoff strategy for an empty batch or error. It defaults to stopping on an error or empty batch via AlwaysDoneBackoff.

func WithWalkDelay

func WithWalkDelay(delay time.Duration) WalkOption

WithWalkDelay sets the value that the walk algorithm will consider "old" enough. If an envelope has a timestamp that has a value that is greater than time.Now().Add(-delay), it will be considered too "new", and not included. This protects from distributed clocks causing data to be skipped. Defaults to 1 second.

func WithWalkEndTime

func WithWalkEndTime(t time.Time) WalkOption

WithWalkEndTime sets the end time of the query. Once reached, Walk will exit.

func WithWalkEnvelopeTypes

func WithWalkEnvelopeTypes(t ...logcache_v1.EnvelopeType) WalkOption

WithWalkEnvelopeType sets the envelope_types of the query.

func WithWalkLimit

func WithWalkLimit(limit int) WalkOption

WithWalkLimit sets the limit of the query.

func WithWalkLogger

func WithWalkLogger(l *log.Logger) WalkOption

WithWalkLogger is used to set the logger for the Walk. It defaults to not logging.

func WithWalkNameFilter

func WithWalkNameFilter(nameFilter string) WalkOption

func WithWalkStartTime

func WithWalkStartTime(t time.Time) WalkOption

WithWalkStartTime sets the start time of the query.

type Walker

type Walker func(
	ctx context.Context,
	start time.Time,
	end time.Time,
) []*loggregator_v2.Envelope

Walker walks a reader. It makes several calls to get all the data between a boundary of time.

func BuildWalker

func BuildWalker(sourceID string, r Reader) Walker

BuildWalker captures the sourceID and reader to be used with a Walker.

type WindowOption

type WindowOption interface {
	// contains filtered or unexported methods
}

WindowOption configures the Window algorithm.

func WithWindowInterval

func WithWindowInterval(i time.Duration) WindowOption

WithWindowInterval sets the duration to advance the start and end of the query. It defaults to a minute.

func WithWindowLogger

func WithWindowLogger(l *log.Logger) WindowOption

WithWindowLogger is used to set the logger for the Walk. It defaults to not logging.

func WithWindowStartTime

func WithWindowStartTime(t time.Time) WindowOption

WithWindowStartTime sets the start time of the query. It defaults to Now-Width.

func WithWindowWidth

func WithWindowWidth(w time.Duration) WindowOption

WithWindowWidth sets the width (end-start=width) of the query. It defaults to an hour.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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