-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing issue where deleted profiles were being sent to devices. (#25095…
…) (#25177) Cherry pick. For #24804 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Added/updated tests - [x] If database migrations are included, checked table schema to confirm autoupdate - [x] Manual QA for all new/changed functionality (cherry picked from commit 7e1a808)
- Loading branch information
Showing
17 changed files
with
415 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed issue where deleted Apple config profiles were installing on devices because devices were offline when the profile was added. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package common_mysql | ||
|
||
// BatchProcessSimple is a simple utility function to batch process a slice of payloads. | ||
// Provide a slice of payloads, a batch size, and a function to execute on each batch. | ||
func BatchProcessSimple[T any]( | ||
payloads []T, | ||
batchSize int, | ||
executeBatch func(payloadsInThisBatch []T) error, | ||
) error { | ||
if len(payloads) == 0 || batchSize <= 0 || executeBatch == nil { | ||
return nil | ||
} | ||
|
||
for i := 0; i < len(payloads); i += batchSize { | ||
start := i | ||
end := i + batchSize | ||
if end > len(payloads) { | ||
end = len(payloads) | ||
} | ||
if err := executeBatch(payloads[start:end]); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package common_mysql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBatchProcessSimple(t *testing.T) { | ||
payloads := []int{1, 2, 3, 4, 5} | ||
executeBatch := func(payloadsInThisBatch []int) error { | ||
t.Fatal("executeBatch should not be called") | ||
return nil | ||
} | ||
|
||
// No payloads | ||
err := BatchProcessSimple(nil, 10, executeBatch) | ||
assert.NoError(t, err) | ||
|
||
// No batch size | ||
err = BatchProcessSimple(payloads, 0, executeBatch) | ||
assert.NoError(t, err) | ||
|
||
// No executeBatch | ||
err = BatchProcessSimple(payloads, 10, nil) | ||
assert.NoError(t, err) | ||
|
||
// Large batch size -- all payloads executed in one batch | ||
executeBatch = func(payloadsInThisBatch []int) error { | ||
assert.Equal(t, payloads, payloadsInThisBatch) | ||
return nil | ||
} | ||
err = BatchProcessSimple(payloads, 10, executeBatch) | ||
assert.NoError(t, err) | ||
|
||
// Small batch size | ||
numCalls := 0 | ||
executeBatch = func(payloadsInThisBatch []int) error { | ||
numCalls++ | ||
switch numCalls { | ||
case 1: | ||
assert.Equal(t, []int{1, 2, 3}, payloadsInThisBatch) | ||
case 2: | ||
assert.Equal(t, []int{4, 5}, payloadsInThisBatch) | ||
default: | ||
t.Errorf("Unexpected number of calls to executeBatch: %d", numCalls) | ||
} | ||
return nil | ||
} | ||
err = BatchProcessSimple(payloads, 3, executeBatch) | ||
assert.NoError(t, err) | ||
} |
23 changes: 23 additions & 0 deletions
23
server/datastore/mysql/migrations/tables/20250102121439_AddIgnoreErrorToHostProfiles.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tables | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
) | ||
|
||
func init() { | ||
MigrationClient.AddMigration(Up_20250102121439, Down_20250102121439) | ||
} | ||
|
||
func Up_20250102121439(tx *sql.Tx) error { | ||
_, err := tx.Exec(`ALTER TABLE host_mdm_apple_profiles | ||
ADD COLUMN ignore_error TINYINT(1) NOT NULL DEFAULT 0`) | ||
if err != nil { | ||
return fmt.Errorf("failed to add ignore_error to host_mdm_apple_profiles table: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func Down_20250102121439(_ *sql.Tx) error { | ||
return nil | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.