query

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryHandler

type QueryHandler struct {
	// StopCh terminates the Run() method when closed
	StopCh chan struct{}
	// contains filtered or unexported fields
}

QueryHandler performs the defined Elasticsearch query at the specified interval and sends results to the AlertHandler if there are any.

func NewQueryHandler

func NewQueryHandler(config *QueryHandlerConfig) (*QueryHandler, error)

NewQueryHandler creates a new *QueryHandler instance

func (*QueryHandler) PutTemplate added in v0.0.13

func (q *QueryHandler) PutTemplate(ctx context.Context) error

PutTemplate attempts to create a template in Elasticsearch which will serve as an alias for the state indices. The state indices will be named 'go-es-alerts-status-{date}'; therefore, this template enables searching all state indices via this alias

func (*QueryHandler) Run

func (q *QueryHandler) Run(ctx context.Context, outputCh chan *alert.Alert, wg *sync.WaitGroup, distLock *lock.Lock)

Run starts the QueryHandler. It first attempts to get the "state" document for this rule from Elasticsearch in order to schedule the next execution at the last scheduled time. If it does not find such a document, or if the next scheduled query is in the past, it will execute the query immediately. Afterwards, it will attempt to write a new state document to Elasticsearch in which the 'next_query' equals the next time the query shall be executed per the provided cron schedule. It will only execute the query if distLock.Acquired() is true.

func (*QueryHandler) StateAliasURL added in v0.0.13

func (q *QueryHandler) StateAliasURL() string

StateAliasURL returns the URL of the Elasticsearch alias used to search the state indices

func (*QueryHandler) StateIndexURL added in v0.0.13

func (q *QueryHandler) StateIndexURL() string

StateIndexURL returns the URL of the Elasticsearch index where state records are stored

func (*QueryHandler) TemplateName added in v0.0.13

func (q *QueryHandler) TemplateName() string

TemplateName returns the name of the Elasticsearch template used to search against all state indices

func (*QueryHandler) Transform

func (q *QueryHandler) Transform(respData map[string]interface{}) ([]*alert.Record, []map[string]interface{}, error)

Transform converts the raw response returned from Elasticsearch into a []*github.com/morningconsult/go-elasticsearch-alerts/command/alert.Record array and returns that array, the response fields grouped by *QueryHandler.bodyField (if any), and an error if there was an error. If Transform returns a non-nil error, the other returned values will be nil.

type QueryHandlerConfig

type QueryHandlerConfig struct {
	// Name is the name of the rule. This should come from
	// the 'name' field of the rule configuration file
	Name string

	// AlertMethods will be passed along with any results returned
	// by a query to the alert handler via the outputCh
	AlertMethods []alert.AlertMethod

	// Client is an *http.Client instance that will be used to
	// query Elasticsearch
	Client *http.Client

	// ESUrl is the URL of the Elasticsearch instance. This should
	// come from the 'elasticsearch.server.url' field of the main
	// configuration file
	ESUrl string

	// QueryData is the payload to be included in the query. This
	// should come from the 'body' field of the rule configuration
	// file
	QueryData map[string]interface{}

	// QueryIndex is the Elasticsearch index to be queried. This
	// should come from the 'index' field of the rule configuration
	// file
	QueryIndex string

	// Schedule is the interval at which the defined Elasticsearch
	// query should executed (in cron syntax)
	Schedule string

	// BodyField is the field of the JSON response returned by
	// Elasticsearch to be grouped on and subsequently sent to
	// the specified outputs. This should come from the 'body_field'
	// field of the rule configuration file
	BodyField string

	// Filters are the additional fields to be grouped on. These
	// should come from the 'filters' field of the rule configuration
	// file
	Filters []string

	Logger hclog.Logger
}

QueryHandlerConfig is passed as an argument to NewQueryHandler()

Jump to

Keyboard shortcuts

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