Skip to content
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

feat: upgrade dev develop #200

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ appveyor.yml
server/config.json
!dashboard.service.js
!webserver.js
!startWebserver.js
4 changes: 2 additions & 2 deletions dashboard.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function updateGatewayConfig() {
if (err) {
return INFO(err);
}
let result = data.replace(/httpport = \S*/g, `httpport = ${gatewayConfig.ip}`);
let result = data.replace(/httpport = \S*/g, `httpport = ${gatewayConfig.port}`);
result = result.replace(/runmode = \S*/g, `runmode = ${gatewayConfig.runmode}`);
fs.writeFileSync(gatewayPath, result, 'utf8');
});
Expand Down Expand Up @@ -186,7 +186,7 @@ function startService(type) {
case COMPONETS.STATS_EXPORTER:
cwd = path.resolve(process.cwd(), 'vendors/nebula-stats-exporter');
mainCmd = `${cwd}/nebula-stats-exporter`;
command = `nohup ${mainCmd} --listen-address=":${config['stats-exporter'].port}" --bare-metal --bare-metal-config=${cwd}/config.yaml > ${LOG_DIR}/start-exporter.log 2>&1 &`
command = `nohup ${mainCmd} --listen-address=":${config['stats-exporter'].port}" --bare-metal --bare-metal-config=${cwd}/config.yaml > ${LOG_DIR}/stats-exporter.log 2>&1 &`
break;
case COMPONETS.PROMETHEUS:
cwd = path.resolve(process.cwd(), 'vendors/prometheus');
Expand Down
21 changes: 0 additions & 21 deletions server/config.json

This file was deleted.

39 changes: 39 additions & 0 deletions server/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
port: 7001 ## webserver port, which you can access in web
gateway:
ip: 192.168.8.44
port: 8090
https: false
runmode: dev
stats-exporter:
ip: 192.168.8.44
port: 9200
https: false
node-exporter:
- ip: 192.168.8.143
port: 9100
https: false
prometheus:
ip: 192.168.8.44
port: 9090
https: false
scrape_interval: 5s
evaluation_interval: 5s
# the cluster node info
nebula-cluster:
name: 'default' # cluster name
metad:
- name: metad0
endpointIP: 192.168.8.143
port: 9559
endpointPort: 19559
graphd:
- name: graphd0
endpointIP: 192.168.8.143
port: 9669
endpointPort: 19669
storaged:
- name: storaged0
endpointIP: 192.168.8.143
port: 9779
endpointPort: 19779

92 changes: 15 additions & 77 deletions server/dev-server.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,32 @@
import express from 'express';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import { createProxyMiddleware } from 'http-proxy-middleware';
import history from 'connect-history-api-fallback';
import config from '../config/webpack.config.dev';
import webpackConfig from '../config/webpack.config.dev';
import yaml from 'js-yaml';
import fs from 'fs';
import path from 'path';
import startWebserver from '../startWebserver';
import pkg from '../package.json';

const path = require('path');
// change node config dir
// process.env.NODE_CONFIG_DIR = path.resolve('./server') ;
// process.env.NODE_ENV= "config";
// import _config from "config";
// _config
// const port = _config.get('port');
// const nebulaServer = _config.get('nebulaServer');
// const proxy = _config.get('proxy');
const compiler = webpack(webpackConfig);

const app = express();
const compiler = webpack(config);

const getTargetUrl =(target)=> {
return target.startsWith('http') ? target : `http://${target}`
function loadYamlConfig() {
const doc = yaml.load(fs.readFileSync(path.resolve(__dirname, 'config.yaml'), 'utf8'));
return doc;
}

const config = loadYamlConfig();

const app = express();

app.use(history());

app.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
publicPath: webpackConfig.output.publicPath,
index: 'index.html',
})
);

app.use('/api-metrics/*', createProxyMiddleware({
target: getTargetUrl(proxy.prometheus.target),
pathRewrite: {
'/api-metrics': '/api/v1',
},
changeOrigin: true,
}))

app.use('/api-nebula/*', createProxyMiddleware({
target: getTargetUrl(proxy.gateway.target),
pathRewrite: {
'/api-nebula': '/api',
},
changeOrigin: true,
}));

app.use('/api-graph/*', createProxyMiddleware({
target: getTargetUrl(proxy.graph.target),
pathRewrite: {
'/api-graph': '/',
},
changeOrigin: true,
}));

app.use('/api-storage/*', createProxyMiddleware({
target: getTargetUrl(proxy.storage.target),
pathRewrite: {
'/api-storage': '/',
},
changeOrigin: true,
}));

app.get('/api/app', (_req, res) => {
res.send({
version: pkg.version,
})
});

app.get('/api/config/custom', async (_req, res) => {
if (nebulaServer) {
res.send({
code: 0,
data: {
connection: nebulaServer,
alias: {
"ip:port": "instance1"
},
}
});
} else {
res.send({
code: -1,
data: null
});
}
});

app.listen(port, function () {
console.log(`Example app listening on port ${port}!\n`);
});
startWebserver(app, config, pkg.version);
6 changes: 2 additions & 4 deletions src/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const getAppInfo = get('/api/app');
const getCustomConfig = get('/api/config/custom');
const getAnnotationLineConfig = get('/api/config/annotation_line');

const getGraphConfig = get(`/api-graph/flags`);
const getStorageConfig = get(`/api-storage/flags`);
const getConfigInfo = (component) => get(`/api-${component}/flags`);

export default {
execNGQL,
Expand All @@ -31,7 +30,6 @@ export default {
execPromQL,
execPromQLByRange,
getCustomConfig,
getGraphConfig,
getStorageConfig,
getConfigInfo,
getAnnotationLineConfig,
};
1 change: 1 addition & 0 deletions src/pages/ServiceManage/ConfigInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const NebulaConfig: React.FC<IProps> = (props: IProps) => {
className="service-radio"
onChange={handleModuleChange}
>
<Radio.Button value="meta">Meta</Radio.Button>
<Radio.Button value="storage">Storage</Radio.Button>
<Radio.Button value="graph">Graph</Radio.Button>
{/* TODO: Nebula 2.0.1 does not support meta modifications, support can be released in later versions
Expand Down
3 changes: 2 additions & 1 deletion src/store/models/nebula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export function NebulaModelWrapper(serviceApi, state, _effects) {
return { code,data };
},
async asyncGetServiceConfigs(module) {
const data = module === 'graph' ? await serviceApi.getGraphConfig() : await serviceApi.getStorageConfig() as any;

const data = await serviceApi.getConfigInfo(module)() ;

if (data) {
this.update({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/HttpServiceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class HttpSeriveManager {
static get _axiosInstance(): AxiosInstance {
if (!HttpSeriveManager.axiosInstance) {
HttpSeriveManager.axiosInstance = axios.create({
timeout: 10000
timeout: 100000
});
}
return HttpSeriveManager.axiosInstance
Expand Down
93 changes: 93 additions & 0 deletions startWebserver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const { createProxyMiddleware } = require('http-proxy-middleware');
const chalk = require('chalk');

function INFO(...info) {
console.log(chalk.green(info.join(' ')))
}

function getFullUrl({ https, ip, port }) {
const protocol = https ? 'https' : 'http';
return `${protocol}://${ip}:${port}`;
}

function getServiceTarget(type, config) {
const service = config['nebula-cluster'];
if (!service) {
throw new Error(`nebula cluster should have at least one ${type} service`);
}
const { endpointIP, endpointPort } = service[type][0];
if (endpointIP.startsWith('http')) {
throw new Error(`endpointIP should not start with http, got ${endpointIP}`);
}
return `http://${endpointIP}:${endpointPort}`;
}

function startWebserver(app, config, version) {

app.use('/api-metrics/*', createProxyMiddleware({
target: getFullUrl(config.prometheus),
pathRewrite: {
'/api-metrics': '/api/v1',
},
changeOrigin: true,
}))

app.use('/api-nebula/*', createProxyMiddleware({
target: getFullUrl(config.gateway),
pathRewrite: {
'/api-nebula': '/api',
},
changeOrigin: true,
}));

app.get('/api/app', (_req, res) => {
res.send({
version,
})
});

app.use('/api-graph/*', createProxyMiddleware({
target: getServiceTarget('graphd', config),
pathRewrite: {
'/api-graph': '/',
},
changeOrigin: true,
}));

app.use('/api-storage/*', createProxyMiddleware({
target: getServiceTarget('storaged', config),
pathRewrite: {
'/api-storage': '/',
},
changeOrigin: true,
}));

app.use('/api-meta/*', createProxyMiddleware({
target: getServiceTarget('metad', config),
pathRewrite: {
'/api-meta': '/',
},
changeOrigin: true,
}));

app.get('/api/config/custom', async (_req, res) => {
res.send({
code: 0,
data: {
connection: {
ip: config['nebula-cluster'].graphd[0].endpointIP,
port: config['nebula-cluster'].graphd[0].port
},
alias: {
"ip:port": getServiceTarget('graphd', config)
},
}
});
});

app.listen(config.port, function () {
INFO(`Welcome to Nebula Dashboard!\r\nthe app is listening on port ${config.port}!\n`);
});
}

module.exports = startWebserver;
16 changes: 8 additions & 8 deletions vendors/config-release.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
port: 7001 ## webserver port, which you can access in web
port: 7003 ## webserver port, which you can access in web
gateway:
ip: 192.168.8.44
ip: hostIP
port: 8090
https: false
runmode: dev
stats-exporter:
ip: 192.168.8.44
ip: hostIP
port: 9200
https: false
node-exporter:
- ip: 192.168.8.134
- ip: hostIP
port: 9100
https: false
prometheus:
ip: 192.168.8.44
ip: hostIP
port: 9090
https: false
scrape_interval: 5s
Expand All @@ -23,17 +23,17 @@ nebula-cluster:
name: 'default' # cluster name
metad:
- name: metad0
endpointIP: 192.168.8.134
endpointIP: nebulaMetadIP
port: 9559
endpointPort: 19559
graphd:
- name: graphd0
endpointIP: 192.168.8.134
endpointIP: nebulaGraphdIP
port: 9669
endpointPort: 19669
storaged:
- name: storaged0
endpointIP: 192.168.8.143
endpointIP: nebulaStoragedIP
port: 9779
endpointPort: 19779

Loading