document

package
v0.0.0-...-2721b3e Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingId = errors.New("no id specified")
)

Functions

func NewCircuitBreaker

func NewCircuitBreaker(graceDuration, doomDuration time.Duration) *timeCircuitBreaker

Types

type CircuitBreaker

type CircuitBreaker interface {
	Success()
	Failure()
	State() CircuitState
}

type CircuitState

type CircuitState int
const (
	// CircuitClosed represents a closed circuit. Documents are processed successfully
	CircuitClosed CircuitState = iota
	// CircuitHalfOpen represents a half-open circuit. Some errors have happend, but processing may still recover
	CircuitHalfOpen
	// CircuitOpen represents a open circuit. Something is broken. We should no longer process documents
	CircuitOpen
)

type Client

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

Client represents a HTTP client for the /document/v1/ API.

func NewClient

func NewClient(options ClientOptions, httpClients []httputil.Client) (*Client, error)

func (*Client) Get

func (c *Client) Get(id Id) Result

Get retrieves document with given ID.

func (*Client) Send

func (c *Client) Send(document Document) Result

Send given document to the endpoint configured in this client.

type ClientOptions

type ClientOptions struct {
	BaseURL     string
	Timeout     time.Duration
	Route       string
	TraceLevel  int
	Compression Compression
	Speedtest   bool
	NowFunc     func() time.Time
}

ClientOptions specifices the configuration options of a feed client.

type Compression

type Compression int
const (
	CompressionAuto Compression = iota
	CompressionNone
	CompressionGzip
)

type Decoder

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

Decoder decodes documents from a JSON structure which is either an array of objects, or objects separated by newline.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode() (Document, error)

type Dispatcher

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

Dispatcher dispatches documents from a queue to a Feeder.

func NewDispatcher

func NewDispatcher(feeder Feeder, throttler Throttler, breaker CircuitBreaker, output io.Writer, verbose bool) *Dispatcher

func (*Dispatcher) Close

func (d *Dispatcher) Close() error

Close waits for all inflight operations to complete and closes the dispatcher.

func (*Dispatcher) Enqueue

func (d *Dispatcher) Enqueue(doc Document) error

func (*Dispatcher) Stats

func (d *Dispatcher) Stats() Stats

type Document

type Document struct {
	Id        Id
	Condition string
	Body      []byte
	Operation Operation
	Create    bool
	// contains filtered or unexported fields
}

Document represents a Vespa document operation.

func (Document) Equal

func (d Document) Equal(o Document) bool

func (*Document) Reset

func (d *Document) Reset()

Reset discards the body of this document.

func (Document) String

func (d Document) String() string

type Feeder

type Feeder interface{ Send(Document) Result }

Feeder is the interface for a consumer of documents.

type Generator

type Generator struct {
	Size     int
	Deadline time.Time
	// contains filtered or unexported fields
}

Generator is a reader that returns synthetic documents until a given deadline.

func NewGenerator

func NewGenerator(size int, deadline time.Time) *Generator

func (*Generator) Read

func (g *Generator) Read(p []byte) (int, error)

type Id

type Id struct {
	Type         string
	Namespace    string
	Number       *int64
	Group        string
	UserSpecific string
	// contains filtered or unexported fields
}

Id represents a Vespa document ID.

func ParseId

func ParseId(serialized string) (Id, error)

ParseId parses a serialized document ID string.

func (Id) Equal

func (d Id) Equal(o Id) bool

func (Id) String

func (d Id) String() string

type Operation

type Operation int
const (
	OperationPut Operation = iota
	OperationUpdate
	OperationRemove
)

func (Operation) String

func (o Operation) String() string

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue is a generic wrapper around a doubly linked list.

func NewQueue

func NewQueue[T any]() *Queue[T]

func (*Queue[T]) Add

func (q *Queue[T]) Add(item T, front bool)

func (*Queue[T]) Poll

func (q *Queue[T]) Poll() (T, bool)

type Result

type Result struct {
	Err        error
	Id         Id
	Trace      string
	Body       []byte
	Status     Status
	HTTPStatus int
	Latency    time.Duration
	BytesSent  int64
	BytesRecv  int64
}

Result represents the result of a feeding operation.

func (Result) Success

func (r Result) Success() bool

type Stats

type Stats struct {
	// Number of operations passed to the feeder by the user, not counting retries.
	Operations int64
	// Number of responses received, grouped by the HTTP status code. Requests that do not receive a response (i.e. no
	// status code) are not counted.
	ResponsesByCode map[int]int64
	// Number of requests made, including retries.
	Requests int64
	// Number of responses received.
	Responses int64
	// Number of transport layer errors.
	Errors int64
	// Number of requests currently in-flight.
	Inflight int64
	// Sum of response latency
	TotalLatency time.Duration
	// Lowest recorded response latency
	MinLatency time.Duration
	// Highest recorded response latency
	MaxLatency time.Duration
	// Total bytes sent
	BytesSent int64
	// Total bytes received
	BytesRecv int64
}

Stats represents feeding operation statistics.

func (*Stats) Add

func (s *Stats) Add(result Result, retry bool)

Add statistics from result to this.

func (Stats) AvgLatency

func (s Stats) AvgLatency() time.Duration

AvgLatency returns the average latency for a request.

func (Stats) Clone

func (s Stats) Clone() Stats

func (Stats) Successful

func (s Stats) Successful() int64

func (Stats) Unsuccessful

func (s Stats) Unsuccessful() int64

type Status

type Status int

Status of a document operation.

const (
	// StatusSuccess indicates a successful document operation.
	StatusSuccess Status = iota
	// StatusConditionNotMet indicates that the document operation itself was successful, but did not satisfy its
	// test-and-set condition.
	StatusConditionNotMet
	// StatusVespaFailure indicates that Vespa failed to process the document operation.
	StatusVespaFailure
	// StatusTransportFailure indicates that there was failure in the transport layer error while sending the document
	// operation to Vespa.
	StatusTransportFailure
)

type Throttler

type Throttler interface {
	// Sent notifies the the throttler that a document has been sent.
	Sent()
	// Success notifies the throttler that document operation succeeded.
	Success()
	// Throttled notifies the throttler that a throttling event occured while count documents were in-flight.
	Throttled(count int64)
	// TargetInflight returns the ideal number of documents to have in-flight now.
	TargetInflight() int64
}

func NewThrottler

func NewThrottler(connections int) Throttler

Jump to

Keyboard shortcuts

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