-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add job that cleans last seen every 24 hours (#5114)
This PR adds a cleanup job that removes unknown feature flags from last_seen_at_metrics table every 24 hours since we no longer have a foreign key on the name column in the features table.
- Loading branch information
1 parent
ddcd7f4
commit 08a1d05
Showing
9 changed files
with
122 additions
and
10 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
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
82 changes: 82 additions & 0 deletions
82
src/lib/services/client-metrics/last-seen/tests/last-seen-service.e2e.test.ts
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,82 @@ | ||
import dbInit, { ITestDb } from '../../../../../test/e2e/helpers/database-init'; | ||
import { | ||
IUnleashTest, | ||
setupAppWithCustomConfig, | ||
} from '../../../../../test/e2e/helpers/test-helper'; | ||
import getLogger from '../../../../../test/fixtures/no-logger'; | ||
|
||
let app: IUnleashTest; | ||
let db: ITestDb; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('last_seen_at_service_e2e', getLogger); | ||
app = await setupAppWithCustomConfig( | ||
db.stores, | ||
{ | ||
experimental: { | ||
flags: { | ||
strictSchemaValidation: true, | ||
disableEnvsOnRevive: true, | ||
useLastSeenRefactor: true, | ||
}, | ||
}, | ||
}, | ||
db.rawDatabase, | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.destroy(); | ||
await db.destroy(); | ||
}); | ||
|
||
test('should clean unknown feature toggle names from last seen store', async () => { | ||
const { lastSeenService, featureToggleService } = app.services; | ||
|
||
const clean = ['clean1', 'clean2', 'clean3', 'clean4']; | ||
const dirty = ['dirty1', 'dirty2', 'dirty3', 'dirty4']; | ||
|
||
await Promise.all( | ||
clean.map((featureName) => | ||
featureToggleService.createFeatureToggle( | ||
'default', | ||
{ name: featureName }, | ||
'user', | ||
), | ||
), | ||
); | ||
|
||
const inserts = [...clean, ...dirty].map((feature) => { | ||
return { | ||
featureName: feature, | ||
environment: 'default', | ||
yes: 1, | ||
no: 0, | ||
appName: 'test', | ||
timestamp: new Date(), | ||
}; | ||
}); | ||
|
||
lastSeenService.updateLastSeen(inserts); | ||
await lastSeenService.store(); | ||
|
||
// We have no method to get these from the last seen service or any other service or store | ||
let stored = await db.rawDatabase.raw( | ||
'SELECT * FROM last_seen_at_metrics;', | ||
); | ||
|
||
expect(stored.rows.length).toBe(8); | ||
|
||
await lastSeenService.cleanLastSeen(); | ||
|
||
stored = await db.rawDatabase.raw('SELECT * FROM last_seen_at_metrics;'); | ||
|
||
expect(stored.rows.length).toBe(4); | ||
expect(stored.rows).toMatch; | ||
|
||
const notInDirty = stored.rows.filter( | ||
(row) => !dirty.includes(row.feature_name), | ||
); | ||
|
||
expect(notInDirty.length).toBe(4); | ||
}); |
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