notifier

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package notifier - Status notification subsystem. The notifier subsystem watches the status for all consumer groups and uses the configured modules to send information about the status of those groups to outside systems, such as via email or calls to HTTP endpoints. The message bodies are built using templates, and notifications can be sent for both active problems as well as when those problems close.

Modules

Currently, the following modules are provided:

* email - Send an email

* http - Call a remote HTTP endpoint

* null - This is a no-op notifier that is used for testing only

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

type Coordinator struct {
	// App is a pointer to the application context. This stores the channel to the storage subsystem
	App *protocol.ApplicationContext

	// Log is a logger that has been configured for this module to use. Normally, this means it has been set up with
	// fields that are appropriate to identify this coordinator
	Log *zap.Logger
	// contains filtered or unexported fields
}

Coordinator manages all notifier modules, making sure they are configured, started, and stopped at the appropriate time. Unlike other coordinators, it also performs a significant amount of ongoing work.

func (*Coordinator) Configure

func (nc *Coordinator) Configure()

Configure is called to create each of the configured notifier modules and call their Configure funcs to validate their individual configurations and set them up. If there are any problems, it is expected that these funcs will panic with a descriptive error message, as configuration failures are not recoverable errors.

func (*Coordinator) Start

func (nc *Coordinator) Start() error

Start calls each of the configured notifier modules' underlying Start funcs. If any module Start returns an error, this func stops immediately and returns that error to the caller. No further modules will be loaded after that.

We also start a timer to periodically update the list of known clusters and consumer groups, as well as the goroutine which manages whether or not we are performing group evaluation requests. We also start the responseLoop func that handles all evaluation replies and calls the module Notify methods as appropriate.

func (*Coordinator) Stop

func (nc *Coordinator) Stop() error

Stop stops the group refresh ticker, and causes the evaluation response handler and the evaluation request manager to both stop. It then calls each of the configured notifier modules' underlying Stop funcs. It is expected that the module Stop will not return until the module has been completely stopped. While an error can be returned, this func always returns no error, as a failure during stopping is not a critical failure

type EmailNotifier

type EmailNotifier struct {
	// App is a pointer to the application context. This stores the channel to the storage subsystem
	App *protocol.ApplicationContext

	// Log is a logger that has been configured for this module to use. Normally, this means it has been set up with
	// fields that are appropriate to identify this coordinator
	Log *zap.Logger
	// contains filtered or unexported fields
}

EmailNotifier is a module which can be used to send notifications of consumer group status via email messages. One email is sent for each consumer group that matches the whitelist/blacklist and the status threshold.

func (*EmailNotifier) AcceptConsumerGroup

func (module *EmailNotifier) AcceptConsumerGroup(status *protocol.ConsumerGroupStatus) bool

AcceptConsumerGroup has no additional function for the email notifier, and so always returns true

func (*EmailNotifier) Configure

func (module *EmailNotifier) Configure(name string, configRoot string)

Configure validates the configuration of the email notifier. At minimum, there must be a valid server, port, from address, and to address. If any of these are missing or incorrect, this func will panic with an explanatory message. It is also possible to specify an auth-type of either "plain" or "crammd5", along with a username and password.

func (*EmailNotifier) GetGroupBlacklist

func (module *EmailNotifier) GetGroupBlacklist() *regexp.Regexp

GetGroupBlacklist returns the compiled group blacklist (or nil, if there is not one)

func (*EmailNotifier) GetGroupWhitelist

func (module *EmailNotifier) GetGroupWhitelist() *regexp.Regexp

GetGroupWhitelist returns the compiled group whitelist (or nil, if there is not one)

func (*EmailNotifier) GetLogger

func (module *EmailNotifier) GetLogger() *zap.Logger

GetLogger returns the configured zap.Logger for this notifier

func (*EmailNotifier) GetName

func (module *EmailNotifier) GetName() string

GetName returns the configured name of this module

func (*EmailNotifier) Notify

func (module *EmailNotifier) Notify(status *protocol.ConsumerGroupStatus, eventID string, startTime time.Time, stateGood bool)

Notify sends a single email message, with the from and to set to the configured addresses for the notifier. The status, eventID, and startTime are all passed to the template for compiling the message. If stateGood is true, the "close" template is used. Otherwise, the "open" template is used.

func (*EmailNotifier) Start

func (module *EmailNotifier) Start() error

Start is a no-op for the email notifier. It always returns no error

func (*EmailNotifier) Stop

func (module *EmailNotifier) Stop() error

Stop is a no-op for the email notifier. It always returns no error

type HTTPNotifier

type HTTPNotifier struct {
	// App is a pointer to the application context. This stores the channel to the storage subsystem
	App *protocol.ApplicationContext

	// Log is a logger that has been configured for this module to use. Normally, this means it has been set up with
	// fields that are appropriate to identify this coordinator
	Log *zap.Logger
	// contains filtered or unexported fields
}

HTTPNotifier is a module which can be used to send notifications of consumer group status via outbound HTTP calls to another server. This is useful for informing another system, such as an alert system, when there is a problem. One HTTP call is made for each consumer group that matches the whitelist/blacklist and the status threshold (though keepalive connections will be used if configured).

func (*HTTPNotifier) AcceptConsumerGroup

func (module *HTTPNotifier) AcceptConsumerGroup(status *protocol.ConsumerGroupStatus) bool

AcceptConsumerGroup has no additional function for the http notifier, and so always returns true

func (*HTTPNotifier) Configure

func (module *HTTPNotifier) Configure(name string, configRoot string)

Configure validates the configuration of the http notifier. At minimum, there must be a url-open specified, and if send-close is set to true there must also be a url-close. If these are missing or incorrect, this func will panic with an explanatory message. It is also possible to configure a specific method (such as POST or DELETE) to be used with these URLs, as well as a timeout and keepalive for the HTTP client.

func (*HTTPNotifier) GetGroupBlacklist

func (module *HTTPNotifier) GetGroupBlacklist() *regexp.Regexp

GetGroupBlacklist returns the compiled group blacklist (or nil, if there is not one)

func (*HTTPNotifier) GetGroupWhitelist

func (module *HTTPNotifier) GetGroupWhitelist() *regexp.Regexp

GetGroupWhitelist returns the compiled group whitelist (or nil, if there is not one)

func (*HTTPNotifier) GetLogger

func (module *HTTPNotifier) GetLogger() *zap.Logger

GetLogger returns the configured zap.Logger for this notifier

func (*HTTPNotifier) GetName

func (module *HTTPNotifier) GetName() string

GetName returns the configured name of this module

func (*HTTPNotifier) Notify

func (module *HTTPNotifier) Notify(status *protocol.ConsumerGroupStatus, eventID string, startTime time.Time, stateGood bool)

Notify makes a single outbound HTTP request. The status, eventID, and startTime are all passed to the template for compiling the request body. If stateGood is true, the "close" template and URL are used. Otherwise, the "open" template and URL are used.

func (*HTTPNotifier) Start

func (module *HTTPNotifier) Start() error

Start is a no-op for the http notifier. It always returns no error

func (*HTTPNotifier) Stop

func (module *HTTPNotifier) Stop() error

Stop is a no-op for the http notifier. It always returns no error

type Module

type Module interface {
	protocol.Module
	GetName() string
	GetGroupWhitelist() *regexp.Regexp
	GetGroupBlacklist() *regexp.Regexp
	GetLogger() *zap.Logger
	AcceptConsumerGroup(*protocol.ConsumerGroupStatus) bool
	Notify(*protocol.ConsumerGroupStatus, string, time.Time, bool)
}

Module defines a means of sending out notifications of consumer group status (such as email), as well as regular expressions describing what groups to notify for. The module itself only provides the logic for how to send a notification in the Notify func - timing loops, and handling requests for group evaluation, are handled in the coordinator centrally.

type NullNotifier

type NullNotifier struct {
	// App is a pointer to the application context. This stores the channel to the storage subsystem
	App *protocol.ApplicationContext

	// Log is a logger that has been configured for this module to use. Normally, this means it has been set up with
	// fields that are appropriate to identify this coordinator
	Log *zap.Logger

	// CalledConfigure is set to true if the Configure method is called
	CalledConfigure bool

	// CalledStart is set to true if the Start method is called
	CalledStart bool

	// CalledStop is set to true if the Stop method is called
	CalledStop bool

	// CalledNotify is set to true if the Notify method is called
	CalledNotify bool

	// CalledAcceptConsumerGroup is set to true if the AcceptConsumerGroup method is called
	CalledAcceptConsumerGroup bool
	// contains filtered or unexported fields
}

NullNotifier is a no-op notifier that can be used for testing purposes in place of a mock. It does not make any external calls, and will record if specific funcs are called.

func (*NullNotifier) AcceptConsumerGroup

func (module *NullNotifier) AcceptConsumerGroup(status *protocol.ConsumerGroupStatus) bool

AcceptConsumerGroup has no additional function for the null notifier, and so always returns true

func (*NullNotifier) Configure

func (module *NullNotifier) Configure(name string, configRoot string)

Configure sets the module name, but performs no other functions for the null notifier

func (*NullNotifier) GetGroupBlacklist

func (module *NullNotifier) GetGroupBlacklist() *regexp.Regexp

GetGroupBlacklist returns the compiled group blacklist (or nil, if there is not one)

func (*NullNotifier) GetGroupWhitelist

func (module *NullNotifier) GetGroupWhitelist() *regexp.Regexp

GetGroupWhitelist returns the compiled group whitelist (or nil, if there is not one)

func (*NullNotifier) GetLogger

func (module *NullNotifier) GetLogger() *zap.Logger

GetLogger returns the configured zap.Logger for this notifier

func (*NullNotifier) GetName

func (module *NullNotifier) GetName() string

GetName returns the configured name of this module

func (*NullNotifier) Notify

func (module *NullNotifier) Notify(status *protocol.ConsumerGroupStatus, eventID string, startTime time.Time, stateGood bool)

Notify is a no-op for the null notifier

func (*NullNotifier) Start

func (module *NullNotifier) Start() error

Start is a no-op for the null notifier. It always returns no error

func (*NullNotifier) Stop

func (module *NullNotifier) Stop() error

Stop is a no-op for the null notifier. It always returns no error

Jump to

Keyboard shortcuts

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