Documentation
¶
Index ¶
- Constants
- Variables
- func ClientHost(client *opensearch.Client) string
- func ContainsRegex(search string) string
- func InspectionTargetPrefix(identity, target string) string
- func NewClient(ctx context.Context, backend Backend, base http.RoundTripper) (*opensearch.Client, error)
- func ReadError(response ErrorResponse) error
- func RetryTooManyRequests[T any](ctx context.Context, send func() (T, error)) (T, error)
- type Backend
- type CircuitBreakerError
- type ErrorResponse
- type HitsInfo
- type OpenSearchError
- type OpenSearchErrorCause
- type RawClientMixin
- type Request
- type Response
- type Result
- type ScrollPageRequest
- type ScrollRequest
- type SearchHit
- type Searcher
- func (t *Searcher) ClearScroll(ctx context.Context, scrollID string) error
- func (t *Searcher) ClosePIT(ctx context.Context, pitID string) error
- func (t *Searcher) DistinctValues(ctx context.Context, req ValuesRequest) (ValuesResult, error)
- func (t *Searcher) GetRawClient() *opensearch.Client
- func (t *Searcher) InspectionKey() string
- func (t *Searcher) OpenPIT(ctx context.Context, index string, keepAlive time.Duration) (string, error)
- func (t *Searcher) OpenScroll(ctx context.Context, request ScrollRequest) (Response, error)
- func (t *Searcher) ParseResponse(ctx context.Context, r Response) *logs.LogResult
- func (t *Searcher) ScrollNext(ctx context.Context, request ScrollPageRequest) (Response, error)
- func (t *Searcher) Search(ctx context.Context, q Request) (*logs.LogResult, error)
- func (t *Searcher) SearchRaw(ctx context.Context, q Request) (Response, error)
- type TotalHitsInfo
- type Value
- type ValuesRequest
- type ValuesResult
Constants ¶
const ( // PropertyBreakerAttempts bounds how many times a request answered 429 // (a circuit breaker or a full queue) is sent in all. PropertyBreakerAttempts = "opensearch.breaker.attempts" // PropertyBreakerBackoff is the wait before the first resend; it doubles // for each one after. PropertyBreakerBackoff = "opensearch.breaker.backoff" )
const ( BreakerTransient = "TRANSIENT" BreakerPermanent = "PERMANENT" )
const DefaultPITKeepAlive = time.Minute
DefaultPITKeepAlive is how long a point-in-time is held between pages. It only has to outlive the gap between one page and the next, not the whole walk: each search extends it.
const DefaultScrollKeepAlive = time.Minute
const ( // DefaultValueLimit caps how many distinct values one lookup returns when the // caller does not say. DefaultValueLimit = 1000 )
const OpenSearchCircuitBreakerType = "circuit_breaking_exception"
OpenSearchCircuitBreakerType is the error type OpenSearch rejects a request with when answering it would exceed the memory a circuit breaker allows.
Variables ¶
var DefaultFieldMappingConfig = logs.FieldMappingConfig{ Message: []string{"message"}, Timestamp: []string{"@timestamp"}, Severity: []string{"log"}, }
Functions ¶
func ClientHost ¶ added in v0.1.101
func ClientHost(client *opensearch.Client) string
ClientHost names the cluster a client talks to, for messages about the cluster itself. It is the first configured address's host.
func ContainsRegex ¶ added in v0.1.29
ContainsRegex renders a substring match as the anchored regexp OpenSearch aggregations take, escaping every character its regexp grammar reserves.
func InspectionTargetPrefix ¶ added in v0.1.101
InspectionTargetPrefix starts every mapping-inspection cache key for one target on one connection, so a search that finds the mapping stale can drop all of them without knowing which index was inspected or which fields asked.
func NewClient ¶ added in v0.1.101
func NewClient(ctx context.Context, backend Backend, base http.RoundTripper) (*opensearch.Client, error)
NewClient builds the OpenSearch client NewWithTransport searches with, without pinging it. A caller that needs a second client to the same backend on a different transport — a sampler kept off a recorded transport — uses it to skip a second round trip.
func ReadError ¶ added in v0.1.101
func ReadError(response ErrorResponse) error
ReadError summarises a non-success OpenSearch response: an *OpenSearchError, or a *CircuitBreakerError wrapping one when the cluster refused the request with a 429 for lack of heap.
func RetryTooManyRequests ¶ added in v0.1.101
RetryTooManyRequests sends a request until it is answered with something other than a 429, at most opensearch.breaker.attempts times (default 4) with a doubling opensearch.breaker.backoff (default 1s: waits 1s, 2s, 4s).
A PERMANENT circuit-breaker rejection is retried too: the parent breaker counts real heap use, garbage the JVM has not collected yet included, and it reports PERMANENT whenever fielddata is part of that total. The request after the next collection usually goes through. Once the attempts are spent, the last rejection is returned, naming how many were made.
Types ¶
type Backend ¶
type Backend struct {
Address string `json:"address"`
Username *types.EnvVar `json:"username,omitempty"`
Password *types.EnvVar `json:"password,omitempty"`
InsecureTLS bool `json:"insecureTLS,omitempty"`
// InspectionKey identifies the resolved connection without placing its URL
// or credentials in metadata cache keys.
InspectionKey string `json:"-"`
}
+kubebuilder:object:generate=true
func (*Backend) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Backend.
func (*Backend) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
type CircuitBreakerError ¶ added in v0.1.101
type CircuitBreakerError struct {
Host string
Breaker string
Wanted string
Limit string
Fielddata string
Durability string
Response *OpenSearchError
}
CircuitBreakerError is a 429 circuit_breaking_exception: the cluster refused the request because its heap is over a breaker's limit. Nothing about the request was wrong. Response keeps the parsed body, so a caller classifying *OpenSearchError still sees it.
func (*CircuitBreakerError) Error ¶ added in v0.1.101
func (e *CircuitBreakerError) Error() string
func (*CircuitBreakerError) Unwrap ¶ added in v0.1.101
func (e *CircuitBreakerError) Unwrap() error
type ErrorResponse ¶ added in v0.1.101
type ErrorResponse struct {
Operation string
// Host names the cluster in a circuit-breaker error, which is about the
// cluster rather than the request.
Host string
StatusCode int
Status string
Body io.Reader
}
ErrorResponse is a non-success OpenSearch response to summarise.
type HitsInfo ¶
type HitsInfo struct {
Total TotalHitsInfo `json:"total"`
MaxScore float64 `json:"max_score"`
Hits []SearchHit `json:"hits"`
}
type OpenSearchError ¶ added in v0.1.29
type OpenSearchError struct {
Operation string
StatusCode int
Status string
Type string
Reason string
Causes []OpenSearchErrorCause
BodyTruncated bool
// Durability is the circuit breaker's TRANSIENT or PERMANENT, when the
// response was a circuit_breaking_exception.
Durability string
}
OpenSearchError is a bounded summary of a non-success OpenSearch response.
func (*OpenSearchError) CircuitBreaker ¶ added in v0.1.95
func (e *OpenSearchError) CircuitBreaker() bool
CircuitBreaker reports that the cluster refused the request for lack of memory: nothing about the request was wrong, and a narrower or later one can succeed.
func (*OpenSearchError) Error ¶ added in v0.1.29
func (e *OpenSearchError) Error() string
func (*OpenSearchError) UnmappedField ¶ added in v0.1.101
func (e *OpenSearchError) UnmappedField() bool
UnmappedField reports that the request named a field the index does not map, which is the one failure that says the cached mapping is out of date.
type OpenSearchErrorCause ¶ added in v0.1.29
type RawClientMixin ¶
type RawClientMixin interface {
GetRawClient() any
}
type Request ¶
type Request struct {
Index string `json:"index" template:"true"`
Query string `json:"query" template:"true"`
// Limit is how many documents to return. It is required — "0" asks for none,
// which is what an aggregation-only search wants.
Limit string `json:"limit,omitempty" template:"true"`
// PIT pins the search to a point-in-time, so consecutive pages of one walk
// read the same view of the index.
PIT string `json:"-"`
// OpaqueID is sent as X-Opaque-Id, which OpenSearch copies onto the task
// running the search, so a sampler can find it in _tasks.
OpaqueID string `json:"-"`
}
+kubebuilder:object:generate=true
func (*Request) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Request.
func (*Request) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
type Result ¶
type Result struct {
// Id is the unique identifier provided by the underlying system, use to link to a point in time of a log stream
Id string `json:"id,omitempty"`
// RFC3339 timestamp
Time string `json:"timestamp,omitempty"`
Message string `json:"message,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
type ScrollPageRequest ¶ added in v0.1.30
type ScrollRequest ¶
ScrollRequest opens a scroll; its Request.OpaqueID tags the opening search.
type SearchHit ¶
type SearchHit struct {
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Sort []any `json:"sort"`
Source map[string]any `json:"_source"`
Fields map[string]any `json:"fields,omitempty"`
}
func (*SearchHit) UnmarshalJSON ¶ added in v0.1.72
type Searcher ¶
type Searcher struct {
// contains filtered or unexported fields
}
func NewWithTransport ¶ added in v0.1.15
func NewWithTransport(ctx context.Context, backend Backend, mappingConfig *logs.FieldMappingConfig, base http.RoundTripper) (*Searcher, error)
NewWithTransport creates an OpenSearch client using a caller-provided HTTP transport. Connection-backed callers use this to share Basic, OAuth and mTLS behavior with the generic HTTP connection layer; direct log backends retain the legacy username/password configuration through New.
func (*Searcher) ClearScroll ¶
ClearScroll releases a scroll context.
func (*Searcher) ClosePIT ¶ added in v0.1.29
ClosePIT releases a point-in-time. A PIT holds segments open until it expires, so a walk that ends early says so rather than leaving the cluster to time it out.
func (*Searcher) DistinctValues ¶ added in v0.1.29
func (t *Searcher) DistinctValues(ctx context.Context, req ValuesRequest) (ValuesResult, error)
DistinctValues answers what values a field holds, ordered by document count. The request body is reused as the aggregation's scope, so the values reflect whatever the query already narrows to.
func (*Searcher) GetRawClient ¶
func (t *Searcher) GetRawClient() *opensearch.Client
func (*Searcher) InspectionKey ¶ added in v0.1.29
func (*Searcher) OpenPIT ¶ added in v0.1.29
func (t *Searcher) OpenPIT(ctx context.Context, index string, keepAlive time.Duration) (string, error)
OpenPIT opens a point-in-time over index and returns its id.
A PIT is what makes a walk a walk rather than a series of unrelated searches: every page reads the same frozen view, so a document written or merged mid-walk cannot shift the rows under a position already handed out. Without one, search_after is stable against ties but still sees the index change.
func (*Searcher) OpenScroll ¶ added in v0.1.30
OpenScroll starts a scroll-backed snapshot read.
func (*Searcher) ParseResponse ¶ added in v0.1.29
ParseResponse maps a raw search response to log lines, one per hit and in hit order.
It is exported so a caller needing both the mapped rows and the raw hits — their sort values for a cursor, the total for a footer — can map a response it already holds, rather than searching twice or being handed rows whose positions have been thrown away.
func (*Searcher) ScrollNext ¶
ScrollNext continues a scroll-backed snapshot read.
type TotalHitsInfo ¶
type ValuesRequest ¶ added in v0.1.29
type ValuesRequest struct {
Index string
Field string
// Search keeps only the values containing it, matched as a substring.
Search string
Limit int
Body map[string]any
// Nested names the `nested` field Field lives inside, and Where pins the
// entry of it the values are read from — the key of a key/value tag list.
//
// Both are required for a nested field to answer at all: its entries are
// indexed as separate documents, so an aggregation that does not descend into
// them returns no buckets, and one that descends without pinning the entry
// returns every tag's values mixed together.
Nested string
Where map[string]string
}
ValuesRequest asks what a field holds. Body scopes the question to the documents a query already narrows to; nil asks the whole index.
type ValuesResult ¶ added in v0.1.29
ValuesResult carries the values the terms aggregation returned and how many distinct ones exist behind them, which is what tells an author the list is a window rather than the whole set.