api

package module
v0.0.0-...-ca60117 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: BSD-2-Clause Imports: 10 Imported by: 0

README

mock-es

A mock elasticsearch server for testing. This provides the absolute minimum responses for something like filebeat to send bulk requests to and to provide a response. The data is thrown away. By default successful responses are sent for all data.

It is also possible to return errors. It is possible to configure so that each POST to the bulk endpoint can result in an error. It is also possible to configure it so that each create action in the bulk request has the possibility of an error. Any other action always return StatusOK.

Flag Meaning
-a string address to listen on ip:port (default ":9200")
-d uint percent chance StatusConflict is returned for create action
-l uint percent chance StatusEntityTooLarge is returned for POST method on _bulk endpoint
-n uint percent chance StatusNotAcceptable is returned for create action
-t uint percent chance StatusTooManyRequests is returned for create action

-d, -n, and -t cannot total more than 100 percent, if the total is less than 100, the remaining percentage chance is for StatusOK.

eg:

-d 20 -n 10 -t 5 would result in a 20 percent chance StatusConflict, 10 percent chance StatusNotAcceptable, 5 percent chance StatusTooManyRequests and 65 percent chance that StatusOK would be returned for each create action in the bulk request

-l cannot be larger than 100, if the total is less than 100, the remaining percentage chance is for StatusOK

eg:

-l 25 would result in a 25 percent chance that each POST to the bulk endpoint would result in StatusEntityTooLarge, the remaining 75 percent would be StatusOK.

Building

go build

Running

Always return success

./mock-es

20 percent chance for StatusTooManyRequests (429 response)

./mock-es -t 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIHandler

type APIHandler struct {
	ActionOdds [100]int
	MethodOdds [100]int
	UUID       uuid.UUID
	Expire     time.Time
	// contains filtered or unexported fields
}

APIHandler docstring

func NewAPIHandler

func NewAPIHandler(uuid uuid.UUID, metricsRegistry metrics.Registry, expire time.Time, percentDuplicate, percentTooMany, percentNonIndex, percentTooLarge uint) *APIHandler

NewAPIHandler return handler with Action and Method Odds array filled in

func (*APIHandler) Bulk

func (h *APIHandler) Bulk(w http.ResponseWriter, r *http.Request)

Bulk handles bulk posts

func (*APIHandler) License

func (h *APIHandler) License(w http.ResponseWriter, r *http.Request)

License handles /_license get requests

func (*APIHandler) Root

func (h *APIHandler) Root(w http.ResponseWriter, r *http.Request)

Root handles / get requests

func (*APIHandler) ServeHTTP

func (h *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type BulkResponse

type BulkResponse struct {
	Errors bool             `json:"errors"`
	Items  []map[string]any `json:"items,omitempty"`
}

BulkResponse is an Elastic Search Bulk Response, assuming filter_path is "errors,items.*.error,items.*.status"

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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