Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 11bdc9f

Browse files
authored
Merge pull request #15 from scale8/configurable-databases
Configurable databases
2 parents 1341d63 + f4633fb commit 11bdc9f

File tree

99 files changed

+2642
-857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2642
-857
lines changed

api/src/Types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ValidationType } from '../../common/enums/ValidationType';
22
import { InputType } from '../../common/enums/InputType';
33
import { TypeIcon } from '../../common/enums/TypeIcon';
4+
import { AwsRegion } from './enums/AwsRegion';
5+
import { JWTInput } from 'google-auth-library/build/src/auth/credentials';
46

57
export interface PlatformEventConfig {
68
persistence_id: string;
@@ -47,3 +49,21 @@ export interface PlatformRevisionConfig {
4749
events?: PlatformEventConfig[];
4850
data_containers?: PlatformDataContainerConfig[];
4951
}
52+
export interface AwsConfig {
53+
access_key_id: string;
54+
secret_access_key: string;
55+
region: AwsRegion;
56+
path_prefix: string;
57+
bucket_name: string;
58+
}
59+
export interface GCBigQueryStreamConfig {
60+
service_account_json: JWTInput;
61+
data_set_name: string;
62+
data_set_location: 'EU' | 'US';
63+
require_partition_filter_in_queries: boolean;
64+
}
65+
export interface MongoDbPushConfig {
66+
use_api_mongo_server: boolean;
67+
connection_string: string;
68+
database_name: string;
69+
}

api/src/UpdateUsage.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { AccountType } from './enums/AccountType';
1515
import { getUsageCycle } from './utils/UsageUtils';
1616
import BaseDatabase from './backends/databases/abstractions/BaseDatabase';
1717
import BaseLogger from './backends/logging/abstractions/BaseLogger';
18+
import { StorageProvider } from './enums/StorageProvider';
1819

1920
//register .env as soon as possible...
2021
dotenv.config();
@@ -23,7 +24,8 @@ dotenv.config();
2324
class UpdateUsage {
2425
@inject(TYPES.RepoFromModelFactory) protected readonly repoFactory!: RepoFromModelFactory;
2526
@inject(TYPES.BackendLogger) protected readonly logger!: BaseLogger;
26-
@inject(TYPES.BackendDatabase) protected readonly backendDatabase!: BaseDatabase;
27+
@inject(TYPES.BackendDatabaseFactory)
28+
protected readonly backendDatabaseFactory!: (storage_provider: StorageProvider) => BaseDatabase;
2729

2830
public async updateTagManagerUsage() {
2931
const accounts = await this.repoFactory(TagManagerAccount).find({});
@@ -39,14 +41,17 @@ class UpdateUsage {
3941
const dayUsage = (
4042
await Promise.all(
4143
apps.map((app) =>
42-
this.backendDatabase.eventRequests(app, {
43-
time_slice: 'DAY',
44-
filter_options: {
45-
from: startOfDay(usageCycle.start).getTime(),
46-
to: endOfDay(usageCycle.end).getTime(),
44+
this.backendDatabaseFactory(app.storageProvider).eventRequests(
45+
app,
46+
{
47+
time_slice: 'DAY',
48+
filter_options: {
49+
from: startOfDay(usageCycle.start).getTime(),
50+
to: endOfDay(usageCycle.end).getTime(),
51+
},
52+
limit: 1000,
4753
},
48-
limit: 1000,
49-
}),
54+
),
5055
),
5156
)
5257
).reduce((v: { [k: string]: number }, appDayUsage) => {
@@ -104,14 +109,17 @@ class UpdateUsage {
104109
const dayUsage = (
105110
await Promise.all(
106111
ingestEndpoints.map((ingestEndpoint) =>
107-
this.backendDatabase.usage(ingestEndpoint, {
108-
time_slice: 'DAY',
109-
filter_options: {
110-
from: startOfDay(usageCycle.start).getTime(),
111-
to: endOfDay(usageCycle.end).getTime(),
112+
this.backendDatabaseFactory(ingestEndpoint.storageProvider).usage(
113+
ingestEndpoint,
114+
{
115+
time_slice: 'DAY',
116+
filter_options: {
117+
from: startOfDay(usageCycle.start).getTime(),
118+
to: endOfDay(usageCycle.end).getTime(),
119+
},
120+
limit: 1000,
112121
},
113-
limit: 1000,
114-
}),
122+
),
115123
),
116124
)
117125
).reduce(

api/src/backends/configuration/abstractions/BaseConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export default abstract class BaseConfig {
3333
}
3434
}
3535

36+
public getStorageBackend(): string {
37+
return BaseConfig.getFromEnvVarOrElse('STORAGE_BACKEND', 'mongodb');
38+
}
39+
3640
public getMode(): Mode {
3741
const mode = BaseConfig.getFromEnvVarOrElse('SERVER_MODE', Mode.SELF_HOSTED);
3842
return mode === Mode.COMMERCIAL ? Mode.COMMERCIAL : Mode.SELF_HOSTED;
@@ -128,10 +132,6 @@ export default abstract class BaseConfig {
128132
return await this.getConfigEntryThrows('GC_KEY_FILE');
129133
}
130134

131-
public async getGCProjectId(): Promise<string> {
132-
return await this.getConfigEntryThrows('GC_PROJECT_ID');
133-
}
134-
135135
public async getAssetBucket(): Promise<string> {
136136
return await this.getConfigEntryOrElse(
137137
'ASSET_BUCKET',

0 commit comments

Comments
 (0)