fleet/server/kolide/targets.go
Zachary Wasserman 0502412e15 Move live query operations from MySQL to Redis
This change optimizes live queries by pushing the computation of query
targets to the creation time of the query, and efficiently caching the
targets in Redis. This results in a huge performance improvement at both
steady-state, and when running live queries.

- Live queries are stored using a bitfield in Redis, and takes
advantage of bitfield operations to be extremely efficient.

- Only run Redis live query test when REDIS_TEST is set in environment

- Ensure that live queries are only sent to hosts when there is a client
listening for results. Addresses an existing issue in Fleet along with
appropriate cleanup for the refactored live query backend.
2020-07-21 14:05:46 -07:00

66 lines
2.1 KiB
Go

package kolide
import (
"context"
"time"
)
type TargetSearchResults struct {
Hosts []Host
Labels []Label
}
// TargetMetrics contains information about the online status of a set of
// hosts.
type TargetMetrics struct {
// TotalHosts is the total hosts in any status. It should equal
// OnlineHosts + OfflineHosts + MissingInActionHosts.
TotalHosts uint `db:"total"`
// OnlineHosts is the count of hosts that have checked in within their
// expected checkin interval (based on the configuration interval
// values, see Host.Status()).
OnlineHosts uint `db:"online"`
// OfflineHosts is the count of hosts that have not checked in within
// their expected interval.
OfflineHosts uint `db:"offline"`
// MissingInActionHosts is the count of hosts that have not checked in
// within the last 30 days.
MissingInActionHosts uint `db:"mia"`
// NewHosts is the count of hosts that have enrolled in the last 24
// hours.
NewHosts uint `db:"new"`
}
type TargetService interface {
// SearchTargets will accept a search query, a slice of IDs of hosts to omit,
// and a slice of IDs of labels to omit, and it will return a set of targets
// (hosts and label) which match the supplied search query.
SearchTargets(ctx context.Context, query string, selectedHostIDs []uint, selectedLabelIDs []uint) (*TargetSearchResults, error)
// CountHostsInTargets returns the metrics of the hosts in the provided
// label and explicit host IDs.
CountHostsInTargets(ctx context.Context, hostIDs []uint, labelIDs []uint) (*TargetMetrics, error)
}
type TargetStore interface {
// CountHostsInTargets returns the metrics of the hosts in the provided
// label and explicit host IDs.
CountHostsInTargets(hostIDs, labelIDs []uint, now time.Time) (TargetMetrics, error)
// HostIDsInTargets returns the host IDs of the hosts in the provided label
// and explicit host IDs. The returned host IDs should be sorted in
// ascending order.
HostIDsInTargets(hostIDs, labelIDs []uint) ([]uint, error)
}
type TargetType int
const (
TargetLabel TargetType = iota
TargetHost
)
type Target struct {
Type TargetType
TargetID uint
}