-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/last seen at by environment (#4939)
Initial architecture for last seen at by environment.
- Loading branch information
1 parent
34fc171
commit d896dbd
Showing
44 changed files
with
649 additions
and
144 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
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 was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/lib/services/client-metrics/last-seen/createLastSeenService.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,34 @@ | ||
import FakeFeatureToggleStore from '../../../../test/fixtures/fake-feature-toggle-store'; | ||
import FeatureToggleStore from '../../../db/feature-toggle-store'; | ||
import { Db, IUnleashConfig } from '../../../server-impl'; | ||
import { FakeLastSeenStore } from './fake-last-seen-store'; | ||
import { LastSeenService } from './last-seen-service'; | ||
import LastSeenStore from './last-seen-store'; | ||
|
||
export const createLastSeenService = ( | ||
db: Db, | ||
config: IUnleashConfig, | ||
): LastSeenService => { | ||
const lastSeenStore = new LastSeenStore( | ||
db, | ||
config.eventBus, | ||
config.getLogger, | ||
); | ||
|
||
const featureToggleStore = new FeatureToggleStore( | ||
db, | ||
config.eventBus, | ||
config.getLogger, | ||
); | ||
|
||
return new LastSeenService({ lastSeenStore, featureToggleStore }, config); | ||
}; | ||
|
||
export const createFakeLastSeenService = ( | ||
config: IUnleashConfig, | ||
): LastSeenService => { | ||
const lastSeenStore = new FakeLastSeenStore(); | ||
const featureToggleStore = new FakeFeatureToggleStore(); | ||
|
||
return new LastSeenService({ lastSeenStore, featureToggleStore }, config); | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/lib/services/client-metrics/last-seen/fake-last-seen-read-model.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,9 @@ | ||
import { IFeatureLastSeenResults } from './last-seen-read-model'; | ||
import { ILastSeenReadModel } from './types/last-seen-read-model-type'; | ||
|
||
export class FakeLastSeenReadModel implements ILastSeenReadModel { | ||
// eslint-disable-next-line | ||
getForFeature(features: string[]): Promise<IFeatureLastSeenResults> { | ||
return Promise.resolve({}); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/lib/services/client-metrics/last-seen/fake-last-seen-store.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,9 @@ | ||
import { LastSeenInput } from './last-seen-service'; | ||
import { ILastSeenStore } from './types/last-seen-store-type'; | ||
|
||
export class FakeLastSeenStore implements ILastSeenStore { | ||
setLastSeen(data: LastSeenInput[]): Promise<void> { | ||
data.map((lastSeen) => lastSeen); | ||
return Promise.resolve(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/lib/services/client-metrics/last-seen/last-seen-mapper.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,39 @@ | ||
import { Logger } from '../../../logger'; | ||
import { IFeatureOverview } from '../../../types'; | ||
import { IFeatureLastSeenResults } from './last-seen-read-model'; | ||
|
||
export class LastSeenMapper { | ||
mapToFeatures( | ||
features: IFeatureOverview[], | ||
lastSeenAtPerEnvironment: IFeatureLastSeenResults, | ||
logger: Logger, | ||
): IFeatureOverview[] { | ||
return features.map((feature) => { | ||
if (!feature.environments) { | ||
logger.warn('Feature without environments:', feature); | ||
return feature; | ||
} | ||
|
||
feature.environments = feature.environments.map((environment) => { | ||
const noData = | ||
!lastSeenAtPerEnvironment[feature.name] || | ||
!lastSeenAtPerEnvironment[feature.name][environment.name]; | ||
|
||
if (noData) { | ||
logger.warn( | ||
'No last seen data for environment:', | ||
environment, | ||
); | ||
return environment; | ||
} | ||
|
||
environment.lastSeenAt = new Date( | ||
lastSeenAtPerEnvironment[feature.name][environment.name] | ||
.lastSeen, | ||
); | ||
return environment; | ||
}); | ||
return feature; | ||
}); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/lib/services/client-metrics/last-seen/last-seen-read-model.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,41 @@ | ||
import { Db } from '../../../db/db'; | ||
import { ILastSeenReadModel } from './types/last-seen-read-model-type'; | ||
|
||
const TABLE = 'last_seen_at_metrics'; | ||
|
||
export interface IFeatureLastSeenResults { | ||
[featureName: string]: { | ||
[environment: string]: { | ||
lastSeen: string; | ||
}; | ||
}; | ||
} | ||
export class LastSeenAtReadModel implements ILastSeenReadModel { | ||
private db: Db; | ||
|
||
constructor(db: Db) { | ||
this.db = db; | ||
} | ||
|
||
async getForFeature(features: string[]): Promise<IFeatureLastSeenResults> { | ||
const rows = await this.db(TABLE).whereIn('feature_name', features); | ||
|
||
const result = rows.reduce((acc, curr) => { | ||
if (!acc[curr.feature_name]) { | ||
acc[curr.feature_name] = {}; | ||
|
||
acc[curr.feature_name][curr.environment] = { | ||
lastSeen: curr.last_seen_at, | ||
}; | ||
} else { | ||
acc[curr.feature_name][curr.environment] = { | ||
lastSeen: curr.last_seen_at, | ||
}; | ||
} | ||
|
||
return acc; | ||
}, {}); | ||
|
||
return result; | ||
} | ||
} |
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.