Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Feature: Add serviceInstance Search Support (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyAllen authored and wu-sheng committed Feb 22, 2019
1 parent 5adaaec commit 8b5e69c
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .roadhogrc.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const schema = makeExecutableSchema({ typeDefs: [
"scalar Long",
fs.readFileSync('query-protocol/common.graphqls', 'utf8'),
fs.readFileSync('query-protocol/metadata.graphqls', 'utf8'),
fs.readFileSync('query-protocol/database.graphqls', 'utf8'),
fs.readFileSync('query-protocol/top-n-records.graphqls', 'utf8'),
fs.readFileSync('query-protocol/alarm.graphqls', 'utf8'),
fs.readFileSync('query-protocol/metric.graphqls', 'utf8'),
fs.readFileSync('query-protocol/aggregation.graphqls', 'utf8'),
Expand Down
7 changes: 7 additions & 0 deletions mock/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
import mockjs from 'mockjs';

export default {

getServiceInstances: () => {
const data = mockjs.mock({
'instanceId|20-50': [{ 'id|+1': 3, name: function() { return `service-${this.id}`; } }], // eslint-disable-line
});
return data.instanceId;
},
TraceBrief: () => {
let offset = 0;
return mockjs.mock({
Expand Down
27 changes: 27 additions & 0 deletions src/models/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const optionsQuery = `
}
`;

const serviceInstanceQuery = `
query ServiceInstanceOption($duration: Duration!, $serviceId: ID!) {
instanceId: getServiceInstances(duration: $duration, serviceId: $serviceId) {
key: id
label: name
}
}
`;

const dataQuery = `
query BasicTraces($condition: TraceQueryCondition) {
queryBasicTraces(condition: $condition) {
Expand Down Expand Up @@ -85,6 +94,7 @@ const spanQuery = `query Spans($traceId: ID!) {
export default base({
namespace: 'trace',
state: {
instances: [],
queryBasicTraces: {
traces: [],
total: 0,
Expand Down Expand Up @@ -116,6 +126,13 @@ export default base({
},
dataQuery,
effects: {
*fetchInstances({ payload }, { call, put }) {
const response = yield call(exec, { query: serviceInstanceQuery, variables: payload.variables });
yield put({
type: 'saveInstances',
payload: response,
});
},
*fetchSpans({ payload }, { call, put }) {
const response = yield call(exec, { query: spanQuery, variables: payload.variables });
yield put({
Expand All @@ -138,6 +155,16 @@ export default base({
},
};
},
saveInstances(state, { payload }) {
const { data } = state;
return {
...state,
data: {
...data,
instances: payload.data.instanceId,
},
};
},
hideTimeline(state) {
const { data } = state;
return {
Expand Down
92 changes: 79 additions & 13 deletions src/routes/Trace/TraceSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import React, { PureComponent } from 'react';
import React, { Component } from 'react';
import { Form, Input, Select, Button, Card, InputNumber, Row, Col, Pagination, DatePicker,notification } from 'antd';
import { Chart, Geom, Axis, Tooltip, Legend } from 'bizcharts';
import { DataSet } from '@antv/data-set';
Expand Down Expand Up @@ -51,7 +51,15 @@ const initPaging = {
return result;
},
})
export default class Trace extends PureComponent {
export default class Trace extends Component {
constructor(props){
super(props);
this.state = {
serviceId: '',
serviceInstanceId: '',
}
}

componentDidMount() {
this.timer = false;
const {...propsData} = this.props;
Expand Down Expand Up @@ -118,12 +126,20 @@ export default class Trace extends PureComponent {

fetchData = (queryCondition, paging = initPaging) => {
const {...propsData} = this.props;
const { serviceId, serviceInstanceId } = this.state;
const newData = {...queryCondition, serviceId, serviceInstanceId}
if (!serviceId) {
delete newData.serviceId;
}
if (!serviceInstanceId) {
delete newData.serviceInstanceId;
}
propsData.dispatch({
type: 'trace/fetchData',
payload: {
variables: {
condition: {
...queryCondition,
...newData,
paging,
},
},
Expand Down Expand Up @@ -161,6 +177,42 @@ export default class Trace extends PureComponent {
});
}

handleSelectInstance = (serviceInstanceId) => {
this.setState({ serviceInstanceId });
}

handleRefreshServiceInstances = () => {
const { dispatch } = this.props;
const { ...propsData } = this.props;
const { serviceId } = this.state;
propsData.form.validateFields((err, fieldsValue) => {
if (err || !serviceId) return;
const rangeTime = fieldsValue['range-time-picker'];
const duration = generateDuration({ from: () => rangeTime[0], to: () => rangeTime[1] }).input;
dispatch({
type: 'trace/fetchInstances',
payload: { variables: { duration, serviceId } },
});
});
return true;
}

handleShowServiceInstances = (serviceId) => {
const { dispatch } = this.props;
const { ...propsData } = this.props;
this.setState({ serviceId });
propsData.form.validateFields((err, fieldsValue) => {
if (err || !serviceId) return;
const rangeTime = fieldsValue['range-time-picker'];
const duration = generateDuration({ from: () => rangeTime[0], to: () => rangeTime[1] }).input;
dispatch({
type: 'trace/fetchInstances',
payload: { variables: { duration, serviceId } },
});
});
return true;
}

renderPointChart = (traces) => {
if (!traces) {
return null;
Expand Down Expand Up @@ -240,6 +292,7 @@ export default class Trace extends PureComponent {
}],
})(
<RangePicker
onCalendarChange={this.handleRefreshServiceInstances}
showTime
disabledDate={current => current && current.valueOf() >= Date.now()}
format="YYYY-MM-DD HH:mm"
Expand All @@ -248,16 +301,29 @@ export default class Trace extends PureComponent {
)}
</FormItem>
<FormItem label="Service">
{getFieldDecorator('serviceId')(
<Select placeholder="All service" style={{ width: '100%' }}>
{options.serviceId && options.serviceId.map((service) => {
return (
<Option key={service.key ? service.key : -1} value={service.key}>
{service.label}
</Option>);
})}
</Select>
)}
<Select placeholder="All services" onChange={this.handleShowServiceInstances} style={{ width: '100%' }}>
{options.serviceId && options.serviceId.map((service) => {
if (service.key) {
return (
<Option key={service.key ? service.key : -1} value={service.key? service.key : ''}>
{service.label}
</Option>);
}
return (
<Option value="">All Services</Option>
)})}
</Select>
</FormItem>
<FormItem label="ServiceInstance">
<Select placeholder="All Service Instances" onChange={this.handleSelectInstance} style={{ width: '100%' }}>
<Option value="">All Service Instances</Option>
{propsData.trace.data.instances && propsData.trace.data.instances.map((instance) => {
return (
<Option key={instance.key ? instance.key : -1} value={instance.key}>
{instance.label}
</Option>);
})}
</Select>
</FormItem>
<FormItem label="Trace State">
{getFieldDecorator('traceState')(
Expand Down

0 comments on commit 8b5e69c

Please sign in to comment.