1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: project last seen at metrics (#7988)

Read `last_seen_at` from correct table `last_seen_at_metrics`, instead
of deprecated `feature.last_seen_at`
This commit is contained in:
Tymoteusz Czech 2024-08-27 12:17:19 +02:00 committed by GitHub
parent fc86f5b2fe
commit 427c43e123
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import type { IFeatureToggleStore } from '../feature-toggle/types/feature-toggle
import type {
IEventStore,
IFlagResolver,
ILastSeenStore,
IProjectReadModel,
IProjectStore,
} from '../../types';
@ -15,6 +16,7 @@ let flagStore: IFeatureToggleStore;
let projectStore: IProjectStore;
let eventStore: IEventStore;
let projectReadModel: IProjectReadModel;
let lastSeenStore: ILastSeenStore;
const alwaysOnFlagResolver = {
isEnabled() {
@ -32,6 +34,7 @@ beforeAll(async () => {
projectStore = db.stores.projectStore;
eventStore = db.stores.eventStore;
flagStore = db.stores.featureToggleStore;
lastSeenStore = db.stores.lastSeenStore;
});
afterAll(async () => {
@ -148,12 +151,10 @@ test('it uses the last flag metrics received for lastReportedFlagUsage', async (
await flagStore.create(projectId, { name: flagName, createdByUserId: 1 });
await flagStore.setLastSeen([
await lastSeenStore.setLastSeen([
{ featureName: flagName, environment: 'development' },
]);
const flag = await flagStore.get(flagName);
const result = await projectReadModel.getProjectsForAdminUi();
expect(result[0].lastReportedFlagUsage).toEqual(flag.lastSeenAt);
expect(result[0].lastReportedFlagUsage).not.toBeNull();
});

View File

@ -69,6 +69,11 @@ export class ProjectReadModel implements IProjectReadModel {
const projectTimer = this.timer('getProjectsForAdminUi');
let projects = this.db(TABLE)
.leftJoin('features', 'features.project', 'projects.id')
.leftJoin(
'last_seen_at_metrics',
'features.name',
'last_seen_at_metrics.feature_name',
)
.leftJoin(
'project_settings',
'project_settings.project',
@ -99,7 +104,7 @@ export class ProjectReadModel implements IProjectReadModel {
this.db.raw(
'projects.id, projects.name, projects.description, projects.health, projects.created_at, ' +
'count(DISTINCT features.name) FILTER (WHERE features.archived_at is null) AS number_of_features, ' +
'MAX(features.last_seen_at) AS last_usage,' +
'MAX(last_seen_at_metrics.last_seen_at) AS last_usage, ' +
'MAX(events.created_at) AS last_updated',
),
'project_settings.project_mode',