mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
0502412e15
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.
66 lines
2.1 KiB
Go
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
|
|
}
|