-
-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instance stats service composition root #6029
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
import { InstanceStatsService } from './instance-stats-service'; | ||
import { | ||
createFakeGetActiveUsers, | ||
createGetActiveUsers, | ||
} from './getActiveUsers'; | ||
import { | ||
createFakeGetProductionChanges, | ||
createGetProductionChanges, | ||
} from './getProductionChanges'; | ||
import { IUnleashConfig } from '../../types'; | ||
import { Db } from '../../db/db'; | ||
import FeatureToggleStore from '../feature-toggle/feature-toggle-store'; | ||
import UserStore from '../../db/user-store'; | ||
import ProjectStore from '../../db/project-store'; | ||
import EnvironmentStore from '../project-environments/environment-store'; | ||
import StrategyStore from '../../db/strategy-store'; | ||
import ContextFieldStore from '../../db/context-field-store'; | ||
import GroupStore from '../../db/group-store'; | ||
import SegmentStore from '../../db/segment-store'; | ||
import RoleStore from '../../db/role-store'; | ||
import SettingStore from '../../db/setting-store'; | ||
import ClientInstanceStore from '../../db/client-instance-store'; | ||
import EventStore from '../events/event-store'; | ||
import { ApiTokenStore } from '../../db/api-token-store'; | ||
import { ClientMetricsStoreV2 } from '../metrics/client-metrics/client-metrics-store-v2'; | ||
import VersionService from '../../services/version-service'; | ||
import FeatureStrategyStore from '../feature-toggle/feature-toggle-strategies-store'; | ||
import FakeUserStore from '../../../test/fixtures/fake-user-store'; | ||
import FakeFeatureToggleStore from '../feature-toggle/fakes/fake-feature-toggle-store'; | ||
import FakeProjectStore from '../../../test/fixtures/fake-project-store'; | ||
import FakeEnvironmentStore from '../project-environments/fake-environment-store'; | ||
import FakeGroupStore from '../../../test/fixtures/fake-group-store'; | ||
import FakeContextFieldStore from '../../../test/fixtures/fake-context-field-store'; | ||
import FakeRoleStore from '../../../test/fixtures/fake-role-store'; | ||
import FakeClientInstanceStore from '../../../test/fixtures/fake-client-instance-store'; | ||
import FakeClientMetricsStoreV2 from '../metrics/client-metrics/fake-client-metrics-store-v2'; | ||
import FakeApiTokenStore from '../../../test/fixtures/fake-api-token-store'; | ||
import FakeEventStore from '../../../test/fixtures/fake-event-store'; | ||
import FakeSettingStore from '../../../test/fixtures/fake-setting-store'; | ||
import FakeSegmentStore from '../../../test/fixtures/fake-segment-store'; | ||
import FakeStrategiesStore from '../../../test/fixtures/fake-strategies-store'; | ||
import FakeFeatureStrategiesStore from '../feature-toggle/fakes/fake-feature-strategies-store'; | ||
|
||
export const createInstanceStatsService = (db: Db, config: IUnleashConfig) => { | ||
const { eventBus, getLogger, flagResolver } = config; | ||
const featureToggleStore = new FeatureToggleStore( | ||
db, | ||
eventBus, | ||
getLogger, | ||
flagResolver, | ||
); | ||
const userStore = new UserStore(db, getLogger); | ||
const projectStore = new ProjectStore( | ||
db, | ||
eventBus, | ||
getLogger, | ||
flagResolver, | ||
); | ||
const environmentStore = new EnvironmentStore(db, eventBus, getLogger); | ||
const strategyStore = new StrategyStore(db, getLogger); | ||
const contextFieldStore = new ContextFieldStore( | ||
db, | ||
getLogger, | ||
flagResolver, | ||
); | ||
const groupStore = new GroupStore(db); | ||
const segmentStore = new SegmentStore( | ||
db, | ||
eventBus, | ||
getLogger, | ||
flagResolver, | ||
); | ||
const roleStore = new RoleStore(db, eventBus, getLogger); | ||
const settingStore = new SettingStore(db, getLogger); | ||
const clientInstanceStore = new ClientInstanceStore( | ||
db, | ||
eventBus, | ||
getLogger, | ||
); | ||
const eventStore = new EventStore(db, getLogger); | ||
const apiTokenStore = new ApiTokenStore(db, eventBus, getLogger); | ||
const clientMetricsStoreV2 = new ClientMetricsStoreV2( | ||
db, | ||
getLogger, | ||
flagResolver, | ||
); | ||
const instanceStatsServiceStores = { | ||
featureToggleStore, | ||
userStore, | ||
projectStore, | ||
environmentStore, | ||
strategyStore, | ||
contextFieldStore, | ||
groupStore, | ||
segmentStore, | ||
roleStore, | ||
settingStore, | ||
clientInstanceStore, | ||
eventStore, | ||
apiTokenStore, | ||
clientMetricsStoreV2, | ||
}; | ||
const featureStrategiesStore = new FeatureStrategyStore( | ||
db, | ||
eventBus, | ||
getLogger, | ||
flagResolver, | ||
); | ||
const versionServiceStores = { | ||
...instanceStatsServiceStores, | ||
featureStrategiesStore, | ||
}; | ||
const getActiveUsers = createGetActiveUsers(db); | ||
const getProductionChanges = createGetProductionChanges(db); | ||
const versionService = new VersionService( | ||
versionServiceStores, | ||
config, | ||
getActiveUsers, | ||
getProductionChanges, | ||
); | ||
|
||
const instanceStatsService = new InstanceStatsService( | ||
instanceStatsServiceStores, | ||
config, | ||
versionService, | ||
getActiveUsers, | ||
getProductionChanges, | ||
); | ||
|
||
return instanceStatsService; | ||
}; | ||
|
||
export const createFakeInstanceStatsService = (config: IUnleashConfig) => { | ||
const { eventBus, getLogger, flagResolver } = config; | ||
const featureToggleStore = new FakeFeatureToggleStore(); | ||
const userStore = new FakeUserStore(); | ||
const projectStore = new FakeProjectStore(); | ||
const environmentStore = new FakeEnvironmentStore(); | ||
const strategyStore = new FakeStrategiesStore(); | ||
const contextFieldStore = new FakeContextFieldStore(); | ||
const groupStore = new FakeGroupStore(); | ||
const segmentStore = new FakeSegmentStore(); | ||
const roleStore = new FakeRoleStore(); | ||
const settingStore = new FakeSettingStore(); | ||
const clientInstanceStore = new FakeClientInstanceStore(); | ||
const eventStore = new FakeEventStore(); | ||
const apiTokenStore = new FakeApiTokenStore(); | ||
const clientMetricsStoreV2 = new FakeClientMetricsStoreV2(); | ||
const instanceStatsServiceStores = { | ||
featureToggleStore, | ||
userStore, | ||
projectStore, | ||
environmentStore, | ||
strategyStore, | ||
contextFieldStore, | ||
groupStore, | ||
segmentStore, | ||
roleStore, | ||
settingStore, | ||
clientInstanceStore, | ||
eventStore, | ||
apiTokenStore, | ||
clientMetricsStoreV2, | ||
}; | ||
const featureStrategiesStore = new FakeFeatureStrategiesStore(); | ||
const versionServiceStores = { | ||
...instanceStatsServiceStores, | ||
featureStrategiesStore, | ||
}; | ||
const getActiveUsers = createFakeGetActiveUsers(); | ||
const getProductionChanges = createFakeGetProductionChanges(); | ||
const versionService = new VersionService( | ||
versionServiceStores, | ||
config, | ||
getActiveUsers, | ||
getProductionChanges, | ||
); | ||
|
||
const instanceStatsService = new InstanceStatsService( | ||
instanceStatsServiceStores, | ||
config, | ||
versionService, | ||
getActiveUsers, | ||
getProductionChanges, | ||
); | ||
|
||
return instanceStatsService; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import dbInit, { ITestDb } from '../../helpers/database-init'; | ||
import { IUnleashTest, setupApp } from '../../helpers/test-helper'; | ||
import { | ||
IUnleashTest, | ||
setupAppWithCustomConfig, | ||
} from '../../helpers/test-helper'; | ||
import getLogger from '../../../fixtures/no-logger'; | ||
import { IUnleashStores } from '../../../../lib/types'; | ||
|
||
|
@@ -11,7 +14,17 @@ beforeAll(async () => { | |
db = await dbInit('instance_admin_api_serial', getLogger); | ||
stores = db.stores; | ||
await stores.settingStore.insert('instanceInfo', { id: 'test-static' }); | ||
app = await setupApp(stores); | ||
app = await setupAppWithCustomConfig( | ||
stores, | ||
{ | ||
experimental: { | ||
flags: { | ||
strictSchemaValidation: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing schema validation |
||
}, | ||
}, | ||
}, | ||
db.rawDatabase, | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
|
@@ -20,7 +33,7 @@ afterAll(async () => { | |
}); | ||
|
||
test('should return instance statistics', async () => { | ||
stores.featureToggleStore.create('default', { | ||
await stores.featureToggleStore.create('default', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing await |
||
name: 'TestStats1', | ||
createdByUserId: 9999, | ||
}); | ||
|
@@ -65,11 +78,11 @@ test('should return signed instance statistics', async () => { | |
}); | ||
|
||
test('should return instance statistics as CVS', async () => { | ||
stores.featureToggleStore.create('default', { | ||
await stores.featureToggleStore.create('default', { | ||
name: 'TestStats2', | ||
createdByUserId: 9999, | ||
}); | ||
stores.featureToggleStore.create('default', { | ||
await stores.featureToggleStore.create('default', { | ||
name: 'TestStats3', | ||
createdByUserId: 9999, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { log } from 'db-migrate-shared'; | ||
import { migrateDb } from '../../../migrator'; | ||
import { createStores } from '../../../lib/db'; | ||
import { createDb } from '../../../lib/db/db-pool'; | ||
|
@@ -97,6 +98,7 @@ export default async function init( | |
getLogger, | ||
}); | ||
|
||
log.setLogLevel('error'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stop logging db migration messages in all tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! This was something I was planning to do yesterday 🥇 |
||
const db = createDb(config); | ||
|
||
await db.raw(`DROP SCHEMA IF EXISTS ${config.db.schema} CASCADE`); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!