Documentation
¶
Index ¶
- Variables
- func EvaluateQueryFilter(filter any, filterable map[string]string) (bool, error)
- func ParseQueryFilter(qs string) (any, error)
- func StreamJsonResults[T any](ctx context.Context, rw http.ResponseWriter, inCh <-chan T, errCh <-chan error, ...) error
- type Listener
- func (l *Listener) DumpConfig(w http.ResponseWriter, r *http.Request)
- func (l *Listener) DumpIncidents(w http.ResponseWriter, r *http.Request)
- func (l *Listener) DumpRules(w http.ResponseWriter, r *http.Request)
- func (l *Listener) DumpSchedules(w http.ResponseWriter, r *http.Request)
- func (l *Listener) IncidentsHandler(w http.ResponseWriter, r *http.Request)
- func (l *Listener) NotificationHistoryHandler(w http.ResponseWriter, r *http.Request)
- func (l *Listener) ProcessEvent(w http.ResponseWriter, r *http.Request)
- func (l *Listener) Run(ctx context.Context) error
- func (l *Listener) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- type OnErrFunc
- type StreamOpt
- type StreamOpts
Constants ¶
This section is empty.
Variables ¶
var ErrFilterEval = stderrors.New("filter evaluation error")
ErrFilterEval is returned when an error occurs during the evaluation of a filter.
Functions ¶
func EvaluateQueryFilter ¶ added in v1.0.0
EvaluateQueryFilter evaluates the given filter against the provided filterable map.
It returns true if the filter matches, false otherwise, along with any error encountered during evaluation. The filter syntax is based on JSON objects and arrays, where: - JSON objects are evaluated as AND conditions (all key-value pairs must match). - JSON arrays are evaluated as OR conditions (at least one element must match).
The JSON object keys can be set to null to express a "NOT EXISTS" condition, meaning that the key must not exist in the filterable map for the filter to match. For example, given the following JSON filter:
{"key1":"value1","key2":null}
It will match if "key1" exists in the filterable map with the value "value1" and "key2" is not present at all.
func ParseQueryFilter ¶ added in v1.0.0
ParseQueryFilter parses the given JSON query string filter and returns a filter.Filter object that can be used to evaluate events against the filter criteria.
func StreamJsonResults ¶ added in v1.0.0
func StreamJsonResults[T any](ctx context.Context, rw http.ResponseWriter, inCh <-chan T, errCh <-chan error, opts ...StreamOpt[T]) error
StreamJsonResults streams JSON results from a result channel to an HTTP response writer.
The function listens for results and errors, encodes the results as JSON, and writes them to the response writer in NDJSON format. If an error occurs, it calls the OnError callback and terminates the streaming. The WithOnError and WithOnResult options must be provided to handle errors and process results, respectively.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func NewListener ¶
func (*Listener) DumpConfig ¶
func (l *Listener) DumpConfig(w http.ResponseWriter, r *http.Request)
DumpConfig is used as /debug prefixed endpoint to dump the current live configuration of the daemon. The authorization has to be done beforehand.
func (*Listener) DumpIncidents ¶
func (l *Listener) DumpIncidents(w http.ResponseWriter, r *http.Request)
DumpIncidents is used as /debug prefixed endpoint to dump all incidents. The authorization has to be done beforehand.
func (*Listener) DumpRules ¶ added in v0.2.0
func (l *Listener) DumpRules(w http.ResponseWriter, r *http.Request)
DumpRules is used as /debug prefixed endpoint to dump all rules. The authorization has to be done beforehand.
func (*Listener) DumpSchedules ¶
func (l *Listener) DumpSchedules(w http.ResponseWriter, r *http.Request)
DumpSchedules is used as /debug prefixed endpoint to dump all schedules. The authorization has to be done beforehand.
func (*Listener) IncidentsHandler ¶ added in v1.0.0
func (l *Listener) IncidentsHandler(w http.ResponseWriter, r *http.Request)
IncidentsHandler handles GET and POST requests to the /v1/incidents endpoint.
It performs authentication using HTTP Basic Auth and delegates the actual handling to [Listener.getIncidents] for GET requests and [Listener.modifyIncident] for POST requests. If the request method is neither GET nor POST, it responds with a 405 Method Not Allowed status.
func (*Listener) NotificationHistoryHandler ¶ added in v1.0.0
func (l *Listener) NotificationHistoryHandler(w http.ResponseWriter, r *http.Request)
NotificationHistoryHandler handles GET requests to the /v1/notification-history endpoint.
func (*Listener) ProcessEvent ¶
func (l *Listener) ProcessEvent(w http.ResponseWriter, r *http.Request)
func (*Listener) Run ¶
Run starts the HTTP listener and blocks until the server finishes.
An error is returned in all cases except for a graceful shutdown triggered by the context being done within a hardcoded time limit.
func (*Listener) ServeHTTP ¶
func (l *Listener) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface for the Listener, allowing it to be used as an actual HTTP handler.
It just sets a Server header and then delegates the request handling to the internal http.ServeMux. The status code of the response is captured and logged together with other request information after the request has been handled.
type OnErrFunc ¶ added in v1.0.0
OnErrFunc is a function type that defines the signature for the error callback function.
type StreamOpt ¶ added in v1.0.0
type StreamOpt[T any] func(*StreamOpts[T])
StreamOpt is a type safe option function that modifies the StreamOpts configuration for streaming JSON results.
func WithOnError ¶ added in v1.0.0
WithOnError sets the callback function to be called when an error occurs during streaming.
The callback function receives the JSON encoder, a boolean indicating whether the HTTP header has already been sent, and the error that occurred. It can be used to log the error, send an error response to the client, or perform any other necessary actions. Once the callback is called, the streaming will be terminated with that error.
func WithOnResult ¶ added in v1.0.0
WithOnResult sets the callback function to be called for each input consumed from the result channel.
The callback function should return the value to be sent to the client and an error if any occurred during processing. If an error is returned, it will be passed to the OnError callback, and the streaming will be terminated with that error. If no error and a nil value is returned, nothing will be sent to the client for that input, and the streaming will continue with the next input from the result channel.
func WithSendHeaderEarly ¶ added in v1.0.0
WithSendHeaderEarly sets the option to send the HTTP header early before streaming results.
This can be useful when the client needs to know that the request has been accepted and is being processed, even if no results have been sent yet. When this option is set, the HTTP header will be sent immediately without waiting for the first result to be available. If this option is not set, the header will be sent only when the first success result is ready to be sent to the client.
Note that if an error occurs before any results are sent, OnError will be called, and the header must be sent with the appropriate error status code and message. If the header has already been sent, OnError will be called with wroteHeader set to true, and the error response should be sent in the body of the response.
type StreamOpts ¶ added in v1.0.0
type StreamOpts[T any] struct { // contains filtered or unexported fields }
StreamOpts is a type safe struct that holds the configuration options for streaming JSON results.