elasticsearch

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 11 Imported by: 1

README

dp-elasticsearch

Elastic search client with healthcheck. It wraps a dp-net/http client to make requests against elasticsearch service.

health package

Using elasticsearch checker function currently performs a GET request against elasticsearch 'cluster health' API (/_cluster/health")

The healthcheck will only succeed if the request can be performend and the cluster is in green state. If the cluster is in yellow state, a Checker in WARNING status will be returned. In any other case, a CRITICAL Checker will be returned.

Read the Health Check Specification for details.

More information about elasticsearch cluster health API

Instantiate an elasticsearch client

import "github.com/ONSdigital/dp-elasticsearch/elasticsearch"

...
    cli := elasticsearch.NewClient(<url>, <signRequests>, <maxRetries>)
...

Call elasticsearch health checker with cli.Checker(context.Background()) and this will return a check object like so:

{
    "name": "string",
    "status": "string",
    "message": "string",
    "status_code": "int",
    "last_checked": "ISO8601 - UTC date time",
    "last_success": "ISO8601 - UTC date time",
    "last_failure": "ISO8601 - UTC date time"
}
Contributing

See CONTRIBUTING for details.

License

Copyright © 2020, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see LICENSE for details.

Documentation

Index

Constants

View Source
const (
	HealthGreen = iota
	HealthYellow
	HealthRed
)

Possible values for the HealthStatus

View Source
const MsgHealthy = "elasticsearch is healthy and the required indexes exist"

MsgHealthy Check message returned when elasticsearch is healthy and the required indexes exist

View Source
const ServiceName = "elasticsearch"

ServiceName elasticsearch

Variables

View Source
var (
	ErrorUnexpectedStatusCode   = errors.New("unexpected status code from api")
	ErrorParsingBody            = errors.New("error parsing cluster health response body")
	ErrorClusterAtRisk          = errors.New("error cluster state yellow. Data might be at risk, check your replica shards")
	ErrorUnhealthyClusterStatus = errors.New("error cluster health red. Cluster is unhealthy")
	ErrorInvalidHealthStatus    = errors.New("error invalid health status returned")
	ErrorIndexDoesNotExist      = errors.New("error index does not exist in cluster")
)

List of errors

Functions

This section is empty.

Types

type Client

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

Client is an ElasticSearch client containing an HTTP client to contact the elasticsearch API.

func NewClient

func NewClient(url string, signRequests bool, maxRetries int, indexes ...string) *Client

NewClient returns a new initialised elasticsearch client with the default dp-net/http client

func NewClientWithHTTPClient

func NewClientWithHTTPClient(url string, signRequests bool, httpCli dphttp.Clienter, indexes ...string) *Client

NewClientWithHTTPClient returns a new initialised elasticsearch client with the provided HTTP client

func (*Client) Checker

func (cli *Client) Checker(ctx context.Context, state *health.CheckState) error

Checker checks health of Elasticsearch, if the required indexes exist and updates the provided CheckState accordingly.

type ClusterHealth

type ClusterHealth struct {
	Status string `json:"status"`
}

ClusterHealth represents the response from the elasticsearch cluster health check

type HealthStatus

type HealthStatus int

HealthStatus - iota enum of possible health states returned by Elasticsearch API

func (HealthStatus) String

func (hs HealthStatus) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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