instance

package
Version: v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 9 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 {
	Time      string `json:"time"`
	Documents int64  `json:"documents"`
}

Bucket is the transformed result from a Elasticsearch API response. It only contains the formatted time and the number of documents for this time. We use a capitalized key for the JSON representation of the documents field, because the name of this field is also shown in the UI as label.

type Config

type Config struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	Description string `json:"description"`
	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 {
	ScrollID  string                   `json:"scrollID"`
	Took      int64                    `json:"took"`
	Hits      int64                    `json:"hits"`
	Documents []map[string]interface{} `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 scrollID, the time a request took, the number of hits, the documents and the buckets.

type Instance

type Instance struct {
	Name string
	// contains filtered or unexported fields
}

Instance represents a single Elasticsearch instance, which can be added via the configuration file.

func New

func New(config Config) (*Instance, error)

New returns a new Elasticsearch instance for the given configuration.

func (*Instance) GetLogs

func (i *Instance) GetLogs(ctx context.Context, query, scrollID string, timeStart, timeEnd int64) (*Data, error)

GetLogs returns the raw log documents and the buckets for the distribution of the logs accross the selected time range. We have to pass a query, start and end time to the function. The scrollID can be an empty string to start a new query. If a scrollID is provided it will be used for pagination.

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]interface{} `json:"hits"`
	} `json:"hits"`
	Aggregations struct {
		LogCount struct {
			Buckets []struct {
				KeyAsString string `json:"key_as_string"`
				Key         int64  `json:"key"`
				DocCount    int64  `json:"doc_count"`
			} `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