Skip to content

Commit ceff112

Browse files
adds support for mongodb caching
1 parent 77d9fab commit ceff112

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

plugins/backend/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ cloudCarbonFootprint:
6565
tenantId: tenant id,
6666
```
6767

68+
### Caching
69+
70+
See [here](https://www.cloudcarbonfootprint.org/docs/data-persistence-and-caching) for more detailed documentation on data persistence and caching.
71+
72+
To use MongoDB (recommended and supported caching mode), here is an example of the configuration:
73+
74+
```yaml
75+
# app-config.local.yaml
76+
cloudCarbonFootprint:
77+
optional:
78+
cacheMode: MONGODB
79+
mongoDbUri: mongodb://localhost:27017
80+
mongoDbCredentials: ~/keys/mongodb-certificate.pem
81+
```
82+
6883
---
6984

7085
© 2022 Thoughtworks, Inc.

plugins/backend/config.d.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,25 @@ export interface Config {
217217

218218
optional?: {
219219
/**
220-
* Set with 'GCS' to store cache file in Google Cloud Storage or leave it empty to use the default.
220+
* Set with 'GCS' or 'MONGODB' to store cache file in Google Cloud Storage or Mongo Database respectively, or leave it empty to use the default.
221221
* @visibility backend
222222
*/
223-
cacheMode?: 'GCP';
223+
cacheMode?: 'GCP' | 'MONGODB';
224224
/**
225-
* Is the name of you Google Cloud Storage bucket where the cache file will be stored.
225+
* If cacheMode is set to 'GCS', you need to provide a Google Cloud Storage bucket where the cache file will be stored.
226226
* @visibility backend
227227
*/
228228
gcsCacheBucketName?: string;
229+
/**
230+
* If cacheMode is set to 'MONGODB', you need to provide a URI to your db.
231+
* @visibility backend
232+
*/
233+
mongoDbUri?: string;
234+
/**
235+
* If cacheMode is set to 'MONGODB', you need to provide a file path to your credentials file.
236+
* @visibility backend
237+
*/
238+
mongoDbCredentials?: string;
229239
/**
230240
* Value to set how the cloud provider queries should return data (e.g. day/week/month/quarter/year). Default to 'day'.
231241
* @visibility backend

plugins/backend/src/service/convertConfig.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const convertConfig = (appConfig?: BackstageConfig): CCFConfig => {
1919
const awsConfig = backstageConfig.getOptionalConfig('aws');
2020
const azureConfig = backstageConfig.getOptionalConfig('azure');
2121
const onPremiseConfig = backstageConfig.getOptionalConfig('onPremise');
22+
const mongoDbConfig = backstageConfig.getOptionalConfig('mongoDb');
2223
const optionalConfig = backstageConfig.getOptionalConfig('optional');
2324

2425
return {
@@ -163,6 +164,18 @@ export const convertConfig = (appConfig?: BackstageConfig): CCFConfig => {
163164
ccfDefaults.ON_PREMISE!.DESKTOP!.AVERAGE_WATTS,
164165
},
165166
},
167+
MONGODB:
168+
mongoDbConfig === undefined
169+
? ccfDefaults.MONGODB
170+
: {
171+
...ccfDefaults.MONGODB,
172+
URI:
173+
optionalConfig?.getOptionalString('mongoDbUri') ??
174+
ccfDefaults.MONGODB?.URI,
175+
CREDENTIALS:
176+
optionalConfig?.getOptionalString('mongoDbCredentials') ??
177+
ccfDefaults.MONGODB?.CREDENTIALS,
178+
},
166179
CACHE_MODE:
167180
optionalConfig?.getOptionalString('cacheMode') ?? ccfDefaults.CACHE_MODE,
168181
};

0 commit comments

Comments
 (0)