instance

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	KeyAsString string `json:"key_as_string"`
	Key         int64  `json:"key"`
	DocCount    int64  `json:"doc_count"`
}

Bucket is the structure of a bucket returned by the Elasticsearch API.

type Config

type Config struct {
	Address  string `json:"address"`
	Username string `json:"username"`
	Password string `json:"password"`
	Token    string `json:"token"`
}

Config is the structure of the configuration for a single Elasticsearch instance.

type Data

type Data struct {
	Took      int64            `json:"took"`
	Hits      int64            `json:"hits"`
	Documents []map[string]any `json:"documents"`
	Buckets   []Bucket         `json:"buckets"`
}

Data is the transformed Response result, which is passed to the React UI. It contains only the important fields, like the time a request took, the number of hits, the documents and the buckets.

type Instance

type Instance interface {
	GetName() string
	GetLogs(ctx context.Context, query string, timeStart, timeEnd int64) (*Data, error)
}

Instance is the interface which must be implemented by each configured Elasticsearch instance.

func New

func New(name string, options map[string]any) (Instance, error)

New returns a new Elasticsearch instance for the given configuration. If the configuration contains a username and password we will add a basic auth header to each request against the Elasticsearch api. If the config contains a token we are adding an authentication header with the token.

type MockInstance

type MockInstance struct {
	mock.Mock
}

MockInstance is an autogenerated mock type for the Instance type

func NewMockInstance

func NewMockInstance(t NewMockInstanceT) *MockInstance

NewMockInstance creates a new instance of MockInstance. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockInstance) GetLogs

func (_m *MockInstance) GetLogs(ctx context.Context, query string, timeStart int64, timeEnd int64) (*Data, error)

GetLogs provides a mock function with given fields: ctx, query, timeStart, timeEnd

func (*MockInstance) GetName

func (_m *MockInstance) GetName() string

GetName provides a mock function with given fields:

type NewMockInstanceT

type NewMockInstanceT interface {
	mock.TestingT
	Cleanup(func())
}

type Response

type Response struct {
	ScrollID string `json:"_scroll_id"`
	Took     int64  `json:"took"`
	TimedOut bool   `json:"timed_out"`
	Shards   struct {
		Total      int64 `json:"total"`
		Successful int64 `json:"successful"`
		Skipped    int64 `json:"skipped"`
		Failed     int64 `json:"failed"`
	} `json:"_shards"`
	Hits struct {
		Total struct {
			Value    int64  `json:"value"`
			Relation string `json:"relation"`
		} `json:"total"`
		Hits []map[string]any `json:"hits"`
	} `json:"hits"`
	Aggregations struct {
		LogCount struct {
			Buckets []Bucket `json:"buckets"`
		} `json:"logcount"`
	} `json:"aggregations"`
}

Response is the structure of successful Elasticsearch API call.

type ResponseError

type ResponseError struct {
	Error struct {
		RootCause []struct {
			Type   string `json:"type"`
			Reason string `json:"reason"`
		} `json:"root_cause"`
		Type     string `json:"type"`
		Reason   string `json:"reason"`
		CausedBy struct {
			Type   string `json:"type"`
			Reason string `json:"reason"`
		} `json:"caused_by"`
	} `json:"error"`
	Status int `json:"status"`
}

ResponseError is the structure of failed Elasticsearch API call.

Jump to

Keyboard shortcuts

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