log-cache: code.cloudfoundry.org/log-cache/pkg/client Index | Files

package client

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

Index

Package Files

client.go oauth2_http_client.go walk.go window.go

Variables

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,
    }
)

func Walk Uses

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 Uses

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.

type AlwaysDoneBackoff Uses

type AlwaysDoneBackoff struct{}

AlwaysDoneBackoff returns false for both OnErr and OnEmpty.

func (AlwaysDoneBackoff) OnEmpty Uses

func (b AlwaysDoneBackoff) OnEmpty() bool

OnEmpty implements Backoff.

func (AlwaysDoneBackoff) OnErr Uses

func (b AlwaysDoneBackoff) OnErr(error) bool

OnErr implements Backoff.

func (AlwaysDoneBackoff) Reset Uses

func (b AlwaysDoneBackoff) Reset()

Reset implements Backoff.

type AlwaysRetryBackoff Uses

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

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

func NewAlwaysRetryBackoff Uses

func NewAlwaysRetryBackoff(interval time.Duration) AlwaysRetryBackoff

NewAlwaysRetryBackoff returns a new AlwaysRetryBackoff.

func (AlwaysRetryBackoff) OnEmpty Uses

func (b AlwaysRetryBackoff) OnEmpty() bool

OnEmpty implements Backoff.

func (AlwaysRetryBackoff) OnErr Uses

func (b AlwaysRetryBackoff) OnErr(error) bool

OnErr implements Backoff.

func (AlwaysRetryBackoff) Reset Uses

func (b AlwaysRetryBackoff) Reset()

Reset implements Backoff.

type Backoff Uses

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 Uses

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

Client reads from LogCache via the RESTful or gRPC API.

func NewClient Uses

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

NewIngressClient creates a Client.

func (*Client) LogCacheVMUptime Uses

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

func (*Client) LogCacheVersion Uses

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

func (*Client) Meta Uses

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

Meta returns meta information from the entire LogCache.

func (*Client) PromQL Uses

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 Uses

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 Uses

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

func (*Client) PromQLRaw Uses

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

func (*Client) Read Uses

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 Uses

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

ClientOption configures the LogCache client.

func WithHTTPClient Uses

func WithHTTPClient(h HTTPClient) ClientOption

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

func WithViaGRPC Uses

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

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

type HTTPClient Uses

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

HTTPClient is an interface that represents a http.Client.

type Oauth2HTTPClient Uses

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 Uses

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

NewOauth2HTTPClient creates a new Oauth2HTTPClient.

func (*Oauth2HTTPClient) Do Uses

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 Uses

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

Oauth2Option configures the Oauth2HTTPClient.

func WithOauth2HTTPClient Uses

func WithOauth2HTTPClient(client HTTPClient) Oauth2Option

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

func WithOauth2HTTPUser Uses

func WithOauth2HTTPUser(username, password string) Oauth2Option

WithOauth2HTTPUser sets the username and password for user authentication.

type PromQLOption Uses

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 Uses

func WithPromQLEnd(t time.Time) PromQLOption

func WithPromQLStart Uses

func WithPromQLStart(t time.Time) PromQLOption

func WithPromQLStep Uses

func WithPromQLStep(step string) PromQLOption

func WithPromQLTime Uses

func WithPromQLTime(t time.Time) PromQLOption

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

type PromQLQueryResult Uses

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

type PromQLResultData Uses

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

type ReadOption Uses

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 Uses

func WithDescending() ReadOption

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

func WithEndTime Uses

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 Uses

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 Uses

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 Uses

func WithNameFilter(nameFilter string) ReadOption

type Reader Uses

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 Uses

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 Uses

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

NewRetryBackoff returns a new RetryBackoff.

func NewRetryBackoffOnErr Uses

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

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

func (*RetryBackoff) OnEmpty Uses

func (b *RetryBackoff) OnEmpty() bool

OnEmpty implements Backoff.

func (*RetryBackoff) OnErr Uses

func (b *RetryBackoff) OnErr(error) bool

OnErr implements Backoff.

func (*RetryBackoff) Reset Uses

func (b *RetryBackoff) Reset()

Reset implements Backoff.

type Visitor Uses

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 Uses

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

WalkOption overrides defaults for Walk.

func WithWalkBackoff Uses

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 Uses

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 Uses

func WithWalkEndTime(t time.Time) WalkOption

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

func WithWalkEnvelopeTypes Uses

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

WithWalkEnvelopeType sets the envelope_types of the query.

func WithWalkLimit Uses

func WithWalkLimit(limit int) WalkOption

WithWalkLimit sets the limit of the query.

func WithWalkLogger Uses

func WithWalkLogger(l *log.Logger) WalkOption

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

func WithWalkNameFilter Uses

func WithWalkNameFilter(nameFilter string) WalkOption

func WithWalkStartTime Uses

func WithWalkStartTime(t time.Time) WalkOption

WithWalkStartTime sets the start time of the query.

type Walker Uses

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 Uses

func BuildWalker(sourceID string, r Reader) Walker

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

type WindowOption Uses

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

WindowOption configures the Window algorithm.

func WithWindowInterval Uses

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 Uses

func WithWindowLogger(l *log.Logger) WindowOption

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

func WithWindowStartTime Uses

func WithWindowStartTime(t time.Time) WindowOption

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

func WithWindowWidth Uses

func WithWindowWidth(w time.Duration) WindowOption

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

Package client imports 19 packages (graph) and is imported by 10 packages. Updated 2019-02-25. Refresh now. Tools for package owners.