Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit 1f51ae4

Browse files
committed
Reference API endpoints via environment variables
Move datastoreConfig.js to config/endpoints.js and loaded with umi config to expose environment variables globally once Node.js process boots up.
1 parent 4445243 commit 1f51ae4

File tree

27 files changed

+126
-284
lines changed

27 files changed

+126
-284
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ _roadhog-api-doc
1717
.DS_Store
1818
npm-debug.log*
1919
yarn-error.log
20-
/mock/datastoreConfig.js
2120

2221
/coverage
2322
.idea
@@ -30,3 +29,6 @@ package-lock.json
3029

3130
# jest tests
3231
__snapshots__
32+
33+
# config
34+
/config/endpoints.js

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ Pbench Dashboard is a web-based platform for consuming indexed performance bench
88
├── public
99
│ └── favicon.ico # favicon
1010
├── mock
11-
│ └── datastoreConfig.js.example # datastore configuration
11+
│ ├── api.js # mocked api
12+
│ └── user.js # mocked user api
1213
├── config
1314
│ ├── config.js # webpack configuration
14-
│ └── router.config.js # webpack routing configuration
15+
│ ├── router.config.js # webpack routing configuration
16+
│ └── endpoints.js # api endpoint configuration
1517
├── src
1618
│ ├── assets # local static files
1719
│ ├── common # common configurations (navigation, menu, etc.)
@@ -66,20 +68,18 @@ This will automatically open the application on [http://localhost:8000](http://l
6668

6769
## Local Development
6870

69-
Both the production and development builds of the dashboard require specific configurations in order to run on their respective environment.
71+
Both the production and development builds of the dashboard require API endpoint configurations in order to query data from specific datastores.
7072

71-
Copy the `datastoreConfig.js.example` file in the `mock/` directory to `datastoreConfig.js` and modify the configuration fields within the route definition. Please reference the following example for required configuration fields.
73+
`endpoints.js` in the `config/` directory contains references to datastores required to visualize data in the dashboard. Please reference the following example for required configuration fields.
7274

7375
```JavaScript
7476
export default {
75-
'/dev/datastoreConfig': {
76-
"elasticsearch": "http://elasticsearch.example.com",
77-
"results": "http://results.example.com",
78-
"graphql": "http://graphql.example.com",
79-
"prefix": "example.prefix",
80-
"run_index": "example.index",
81-
"result_index": "example.index"
82-
},
77+
"elasticsearch": "http://elasticsearch.example.com",
78+
"results": "http://results.example.com",
79+
"graphql": "http://graphql.example.com",
80+
"prefix": "example.prefix",
81+
"run_index": "example.index",
82+
"result_index": "example.index"
8383
}
8484
```
8585

config/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import pageRoutes from './router.config';
2+
import endpoints from './endpoints';
23

34
export default {
45
define: {
5-
'process.env': process.env.NODE_ENV,
6+
'process.env.endpoints': endpoints,
67
},
78
dynamicImport: undefined,
89
base: '/dashboard/',

config/endpoints.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
elasticsearch: 'http://test_domain.com',
3+
results: 'http://test_domain.com',
4+
graphql: 'http://test_domain.com',
5+
prefix: 'test_prefix.',
6+
result_index: 'test_index.',
7+
run_index: 'test_index.',
8+
};

e2etests

-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55
# directory.
66
cd $(dirname ${0})
77

8-
# Setup the mock'd data store configuration.
9-
cat > mock/datastoreConfig.js <<EOF
10-
export default {
11-
'/dev/datastoreConfig': {
12-
elasticsearch: 'http://test_domain.com',
13-
results: 'http://test_domain.com',
14-
graphql: 'http://test_domain.com',
15-
prefix: 'test_prefix.',
16-
run_index: 'test_index.',
17-
},
18-
};
19-
EOF
208
# Make sure the yarn environment is all up-to-date, or perform the
219
# install ahead of actually running the tests.
2210
printf -- "Running \"yarn install\" command ...\n"

mock/api.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line import/no-unresolved
2-
import config from './datastoreConfig';
2+
import endpoints from '../config/endpoints';
33
import constants from '../config/constants';
44

55
// Generate controllers as per max page size options
@@ -22,8 +22,7 @@ export const generateMockControllerAggregation = {
2222
},
2323
};
2424

25-
const datastoreConfig = config['/dev/datastoreConfig'];
26-
const prefix = datastoreConfig.prefix + datastoreConfig.run_index.slice(0, -1);
25+
const prefix = endpoints.prefix + endpoints.run_index.slice(0, -1);
2726
export const mockIndices = {
2827
[`${prefix}.2019-08-01`]: {},
2928
[`${prefix}.2019-09-01`]: {},

mock/datastoreConfig.js.example

-9
This file was deleted.

src/components/GlobalHeader/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class GlobalHeader extends Component {
7373

7474
render() {
7575
const {
76-
datastoreConfig,
7776
savingSession,
7877
sessionBannerVisible,
7978
sessionDescription,
@@ -102,12 +101,7 @@ class GlobalHeader extends Component {
102101
banner
103102
/>
104103
)}
105-
<SessionModal
106-
datastoreConfig={datastoreConfig}
107-
savingSession={savingSession}
108-
sessionConfig={store}
109-
dispatch={dispatch}
110-
/>
104+
<SessionModal savingSession={savingSession} sessionConfig={store} dispatch={dispatch} />
111105
<PageHeaderToolsGroup>
112106
<PageHeaderToolsItem>
113107
<Button

src/components/SessionModal/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SessionModal extends Component {
4848
};
4949

5050
onGenerate = () => {
51-
const { dispatch, datastoreConfig } = this.props;
51+
const { dispatch } = this.props;
5252
let { sessionConfig } = this.props;
5353
const { description } = this.state;
5454
sessionConfig = JSON.stringify(sessionConfig);
@@ -58,7 +58,6 @@ class SessionModal extends Component {
5858
payload: {
5959
sessionConfig,
6060
description,
61-
datastoreConfig,
6261
},
6362
}).then(result => {
6463
this.setState({

src/layouts/BasicLayout.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ const getBreadcrumbNameMap = memoizeOne(menu => {
4444
return routerMap;
4545
}, deepEqual);
4646

47-
@connect(({ global, datastore, loading, auth }) => ({
48-
datastoreConfig: datastore.datastoreConfig,
47+
@connect(({ global, loading, auth }) => ({
4948
sessionBannerVisible: global.sessionBannerVisible,
5049
sessionDescription: global.sessionDescription,
5150
sessionId: global.sessionId,
@@ -94,7 +93,6 @@ class BasicLayout extends React.PureComponent {
9493

9594
render() {
9695
const {
97-
datastoreConfig,
9896
savingSession,
9997
sessionBannerVisible,
10098
sessionDescription,
@@ -110,7 +108,6 @@ class BasicLayout extends React.PureComponent {
110108
<Page
111109
header={
112110
<GlobalHeader
113-
datastoreConfig={datastoreConfig}
114111
savingSession={savingSession}
115112
sessionBannerVisible={sessionBannerVisible}
116113
sessionDescription={sessionDescription}

src/models/datastore.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
import getDefaultDateRange from '../utils/moment_constants';
2-
import { queryDatastoreConfig, queryMonthIndices } from '../services/datastore';
2+
import queryMonthIndices from '../services/datastore';
33

44
export default {
55
namespace: 'datastore',
66

77
state: {
8-
datastoreConfig: {},
98
indices: [],
109
},
1110

1211
effects: {
13-
*fetchDatastoreConfig({ payload }, { call, put }) {
14-
const response = yield call(queryDatastoreConfig, payload);
15-
16-
// Remove the trailing slashes if present, we'll take care of adding
17-
// them back in the proper context.
18-
response.elasticsearch = response.elasticsearch.replace(/\/+$/, '');
19-
response.results = response.results.replace(/\/+$/, '');
20-
21-
yield put({
22-
type: 'getDatastoreConfig',
23-
payload: response,
24-
});
25-
},
2612
*fetchMonthIndices({ payload }, { call, put }) {
2713
const response = yield call(queryMonthIndices, payload);
28-
const { datastoreConfig } = payload;
14+
const { endpoints } = process.env;
2915
const indices = [];
3016

31-
const prefix = datastoreConfig.prefix + datastoreConfig.run_index.slice(0, -1);
17+
const prefix = endpoints.prefix + endpoints.run_index.slice(0, -1);
3218
Object.keys(response).forEach(index => {
3319
if (index.includes(prefix)) {
3420
indices.push(index.split('.').pop());
@@ -49,12 +35,6 @@ export default {
4935
},
5036

5137
reducers: {
52-
getDatastoreConfig(state, { payload }) {
53-
return {
54-
...state,
55-
datastoreConfig: payload,
56-
};
57-
},
5838
getMonthIndices(state, { payload }) {
5939
return {
6040
...state,

src/models/search.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export default {
1919
},
2020
*fetchIndexMapping({ payload }, { call, put }) {
2121
const response = yield call(queryIndexMapping, payload);
22-
const { datastoreConfig, indices } = payload;
22+
const { indices } = payload;
23+
const { endpoints } = process.env;
2324

24-
const index = datastoreConfig.prefix + datastoreConfig.run_index + indices[0];
25+
const index = endpoints.prefix + endpoints.run_index + indices[0];
2526
const mapping = response[index].mappings['pbench-run'].properties;
2627
const fields = [];
2728
const filters = {};

src/pages/ComparisonSelect/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ import Button from '@/components/Button';
2323
import Table from '@/components/Table';
2424
import { filterIterations } from '../../utils/parse';
2525

26-
@connect(({ datastore, global, dashboard, loading }) => ({
26+
@connect(({ global, dashboard, loading }) => ({
2727
iterations: dashboard.iterations,
2828
iterationParams: dashboard.iterationParams,
2929
results: dashboard.results,
3030
controllers: dashboard.controllers,
31-
datastoreConfig: datastore.datastoreConfig,
3231
selectedControllers: global.selectedControllers,
3332
selectedResults: global.selectedResults,
3433
selectedDateRange: global.selectedDateRange,
@@ -47,11 +46,11 @@ class ComparisonSelect extends React.Component {
4746
}
4847

4948
componentDidMount() {
50-
const { selectedResults, selectedDateRange, datastoreConfig, dispatch } = this.props;
49+
const { selectedResults, selectedDateRange, dispatch } = this.props;
5150

5251
dispatch({
5352
type: 'dashboard/fetchIterationSamples',
54-
payload: { selectedResults, selectedDateRange, datastoreConfig },
53+
payload: { selectedResults, selectedDateRange },
5554
});
5655
}
5756

src/pages/Controllers/index.js

+5-19
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ const { TabPane } = Tabs;
2525
controllers: dashboard.controllers,
2626
indices: datastore.indices,
2727
selectedDateRange: global.selectedDateRange,
28-
datastoreConfig: datastore.datastoreConfig,
2928
favoriteControllers: user.favoriteControllers,
3029
loadingControllers:
31-
loading.effects['dashboard/fetchControllers'] ||
32-
loading.effects['datastore/fetchMonthIndices'] ||
33-
loading.effects['datastore/fetchDatastoreConfig'],
30+
loading.effects['dashboard/fetchControllers'] || loading.effects['datastore/fetchMonthIndices'],
3431
}))
3532
class Controllers extends Component {
3633
constructor(props) {
@@ -51,7 +48,7 @@ class Controllers extends Component {
5148
selectedDateRange.start === '' ||
5249
selectedDateRange.end === ''
5350
) {
54-
this.queryDatastoreConfig();
51+
this.fetchMonthIndices();
5552
}
5653
}
5754

@@ -63,32 +60,21 @@ class Controllers extends Component {
6360
}
6461
}
6562

66-
queryDatastoreConfig = async () => {
67-
const { dispatch } = this.props;
68-
69-
dispatch({
70-
type: 'datastore/fetchDatastoreConfig',
71-
}).then(() => {
72-
this.fetchMonthIndices();
73-
});
74-
};
75-
7663
fetchMonthIndices = async () => {
77-
const { dispatch, datastoreConfig } = this.props;
64+
const { dispatch } = this.props;
7865

7966
dispatch({
8067
type: 'datastore/fetchMonthIndices',
81-
payload: { datastoreConfig },
8268
}).then(() => {
8369
this.fetchControllers();
8470
});
8571
};
8672

8773
fetchControllers = () => {
88-
const { dispatch, datastoreConfig, selectedDateRange } = this.props;
74+
const { dispatch, selectedDateRange } = this.props;
8975
dispatch({
9076
type: 'dashboard/fetchControllers',
91-
payload: { datastoreConfig, selectedDateRange },
77+
payload: { selectedDateRange },
9278
});
9379
};
9480

0 commit comments

Comments
 (0)