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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 12 additions & 12 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/components/GlobalHeader/index.js

Lines changed: 1 addition & 7 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 4 deletions
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}

0 commit comments

Comments
 (0)