Fix performance regression found in load testing (#12981)
This commit is contained in:
@@ -25,8 +25,6 @@ const (
|
||||
defaultTeamFeaturesExpiration = 1 * time.Minute
|
||||
teamMDMConfigKey = "TeamMDMConfig:team:%d"
|
||||
defaultTeamMDMConfigExpiration = 1 * time.Minute
|
||||
// scheduledQueriesForAgentsKey uses defaultScheduledQueriesExpiration for expiration.
|
||||
scheduledQueriesForAgentsKey = "ScheduledQueriesAgents:team:%d"
|
||||
)
|
||||
|
||||
// cloner represents any type that can clone itself. Used by types to provide a more efficient clone method.
|
||||
@@ -322,24 +320,3 @@ func (ds *cachedMysql) DeleteTeam(ctx context.Context, teamID uint) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *cachedMysql) ListScheduledQueriesForAgents(ctx context.Context, teamID *uint) ([]*fleet.Query, error) {
|
||||
var teamIDVal uint
|
||||
if teamID != nil {
|
||||
teamIDVal = *teamID
|
||||
}
|
||||
|
||||
key := fmt.Sprintf(scheduledQueriesForAgentsKey, teamIDVal)
|
||||
if x, found := ds.c.Get(key); found {
|
||||
if queries, ok := x.([]*fleet.Query); ok {
|
||||
return queries, nil
|
||||
}
|
||||
}
|
||||
|
||||
queries, err := ds.Datastore.ListScheduledQueriesForAgents(ctx, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ds.c.Set(key, queries, ds.scheduledQueriesExp)
|
||||
return queries, nil
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/fleetdm/fleet/v4/server/mock"
|
||||
"github.com/fleetdm/fleet/v4/server/ptr"
|
||||
"github.com/fleetdm/fleet/v4/server/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -538,37 +537,3 @@ func TestCachedTeamMDMConfig(t *testing.T) {
|
||||
_, err = ds.TeamMDMConfig(context.Background(), testTeam.ID)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestCachedListScheduledQueriesForAgents(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
mockedDS := new(mock.Store)
|
||||
ds := New(mockedDS, WithScheduledQueriesExpiration(100*time.Millisecond))
|
||||
|
||||
teamID := ptr.Uint(1)
|
||||
scheduledQueries := []*fleet.Query{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "test",
|
||||
Interval: 100,
|
||||
AutomationsEnabled: true,
|
||||
TeamID: teamID,
|
||||
},
|
||||
{
|
||||
ID: 2,
|
||||
Name: "test II",
|
||||
Interval: 100,
|
||||
AutomationsEnabled: true,
|
||||
TeamID: teamID,
|
||||
},
|
||||
}
|
||||
mockedDS.ListScheduledQueriesForAgentsFunc = func(ctx context.Context, teamID *uint) ([]*fleet.Query, error) {
|
||||
return scheduledQueries, nil
|
||||
}
|
||||
|
||||
result, err := ds.ListScheduledQueriesForAgents(ctx, teamID)
|
||||
require.NoError(t, err)
|
||||
test.QueryElementsMatch(t, result, scheduledQueries)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20230726115701, Down_20230726115701)
|
||||
}
|
||||
|
||||
func Up_20230726115701(tx *sql.Tx) error {
|
||||
if _, err := tx.Exec(`
|
||||
ALTER TABLE queries
|
||||
ADD UNIQUE INDEX idx_name_team_id_unq (name, team_id_char),
|
||||
ADD INDEX idx_team_id_saved_auto_interval (team_id, saved, automations_enabled, schedule_interval);
|
||||
`); err != nil {
|
||||
return errors.Wrap(err, "updating queries indices")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20230726115701(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user