fleet/server/service/mock/service_osquery.go
Victor Lyuboslavsky 835eedae42
Performance stats for live queries (#15440)
📺 Loom explaining the PR:
https://www.loom.com/share/8c6ec0c362014910931f183d68307525?sid=7de51e6f-a59d-4d8f-b06b-f703f1692f17

#467 
Live Queries now collect stats. Stats are collected for saved queries
present in the Queries tab.
- After running a live query, user will see updated stats in Queries
tab.
- Query stats on Host Details page will no longer be cleared after
host/agent reboots.
- Query stats are now deleted when query is deleted.

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2023-12-13 14:46:59 -06:00

102 lines
3.5 KiB
Go

// Automatically generated by mockimpl. DO NOT EDIT!
package mock
import (
"context"
"encoding/json"
"sync"
"github.com/fleetdm/fleet/v4/server/fleet"
)
var _ fleet.OsqueryService = (*TLSService)(nil)
type EnrollAgentFunc func(ctx context.Context, enrollSecret string, hostIdentifier string, hostDetails map[string](map[string]string)) (nodeKey string, err error)
type AuthenticateHostFunc func(ctx context.Context, nodeKey string) (host *fleet.Host, debug bool, err error)
type GetClientConfigFunc func(ctx context.Context) (config map[string]interface{}, err error)
type GetDistributedQueriesFunc func(ctx context.Context) (queries map[string]string, discovery map[string]string, accelerate uint, err error)
type SubmitDistributedQueryResultsFunc func(ctx context.Context, results fleet.OsqueryDistributedQueryResults, statuses map[string]fleet.OsqueryStatus, messages map[string]string, stats map[string]*fleet.Stats) (err error)
type SubmitStatusLogsFunc func(ctx context.Context, logs []json.RawMessage) (err error)
type SubmitResultLogsFunc func(ctx context.Context, logs []json.RawMessage) (err error)
type TLSService struct {
EnrollAgentFunc EnrollAgentFunc
EnrollAgentFuncInvoked bool
AuthenticateHostFunc AuthenticateHostFunc
AuthenticateHostFuncInvoked bool
GetClientConfigFunc GetClientConfigFunc
GetClientConfigFuncInvoked bool
GetDistributedQueriesFunc GetDistributedQueriesFunc
GetDistributedQueriesFuncInvoked bool
SubmitDistributedQueryResultsFunc SubmitDistributedQueryResultsFunc
SubmitDistributedQueryResultsFuncInvoked bool
SubmitStatusLogsFunc SubmitStatusLogsFunc
SubmitStatusLogsFuncInvoked bool
SubmitResultLogsFunc SubmitResultLogsFunc
SubmitResultLogsFuncInvoked bool
mu sync.Mutex
}
func (s *TLSService) EnrollAgent(ctx context.Context, enrollSecret string, hostIdentifier string, hostDetails map[string](map[string]string)) (nodeKey string, err error) {
s.mu.Lock()
s.EnrollAgentFuncInvoked = true
s.mu.Unlock()
return s.EnrollAgentFunc(ctx, enrollSecret, hostIdentifier, hostDetails)
}
func (s *TLSService) AuthenticateHost(ctx context.Context, nodeKey string) (host *fleet.Host, debug bool, err error) {
s.mu.Lock()
s.AuthenticateHostFuncInvoked = true
s.mu.Unlock()
return s.AuthenticateHostFunc(ctx, nodeKey)
}
func (s *TLSService) GetClientConfig(ctx context.Context) (config map[string]interface{}, err error) {
s.mu.Lock()
s.GetClientConfigFuncInvoked = true
s.mu.Unlock()
return s.GetClientConfigFunc(ctx)
}
func (s *TLSService) GetDistributedQueries(ctx context.Context) (queries map[string]string, discovery map[string]string, accelerate uint, err error) {
s.mu.Lock()
s.GetDistributedQueriesFuncInvoked = true
s.mu.Unlock()
return s.GetDistributedQueriesFunc(ctx)
}
func (s *TLSService) SubmitDistributedQueryResults(ctx context.Context, results fleet.OsqueryDistributedQueryResults, statuses map[string]fleet.OsqueryStatus, messages map[string]string, stats map[string]*fleet.Stats) (err error) {
s.mu.Lock()
s.SubmitDistributedQueryResultsFuncInvoked = true
s.mu.Unlock()
return s.SubmitDistributedQueryResultsFunc(ctx, results, statuses, messages, stats)
}
func (s *TLSService) SubmitStatusLogs(ctx context.Context, logs []json.RawMessage) (err error) {
s.mu.Lock()
s.SubmitStatusLogsFuncInvoked = true
s.mu.Unlock()
return s.SubmitStatusLogsFunc(ctx, logs)
}
func (s *TLSService) SubmitResultLogs(ctx context.Context, logs []json.RawMessage) (err error) {
s.mu.Lock()
s.SubmitResultLogsFuncInvoked = true
s.mu.Unlock()
return s.SubmitResultLogsFunc(ctx, logs)
}