Skip to content

Commit

Permalink
Adding time offset
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Jan 12, 2017
1 parent a6e91ba commit 5ee12ac
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export default React.createClass({
);
}

const disableSeperateYaxis = model.seperate_axis ? false : true;

return (
<div>
<div className="vis_editor__series_config-container">
Expand All @@ -121,41 +123,52 @@ export default React.createClass({
</div>
{ type }
<div className="vis_editor__series_config-row">
<div className="vis_editor__label">Offset series time by (1m, 1h, 1w, 1d)</div>
<input
className="vis_editor__input-grows"
type="text"
ref="offset_time"
onChange={handleTextChange('offset_time')}
defaultValue={model.offset_time}/>
<div className="vis_editor__label">Hide in Legend</div>
<YesNo
value={model.hide_in_legend}
name="hide_in_legend"
onChange={this.props.onChange}/>
<div className="vis_editor__label">Axis Max</div>
<div className="vis_editor__label">Separate Axis</div>
<YesNo
value={model.seperate_axis}
name="seperate_axis"
onChange={this.props.onChange}/>
<div className="vis_editor__label" style={{ marginLeft: 10 }}>Axis Min</div>
<input
className="vis_editor__input-grows"
type="text"
ref="axis_min"
disabled={disableSeperateYaxis}
onChange={handleTextChange('axis_min')}
defaultValue={model.axis_min}/>
<div className="vis_editor__label">Axis Max</div>
<input
className="vis_editor__input-grows"
type="text"
disabled={disableSeperateYaxis}
ref="axis_max"
onChange={handleTextChange('axis_max')}
defaultValue={model.axis_max}/>
<div className="vis_editor__label">Axis Position</div>
<div className="vis_editor__row_item">
<Select
clearable={false}
disabled={disableSeperateYaxis}
options={positionOptions}
value={model.axis_position}
onChange={handleSelectChange('axis_position')}/>
</div>
</div>
{ model.seperate_axis ? (
<div className="vis_editor__row" style={{ fontSize: 12 }}>
<div className="vis_editor__label" style={{ marginLeft: 10 }}>Axis Min</div>
<input
className="vis_editor__input-grows"
type="text"
ref="axis_min"
onChange={handleTextChange('axis_min')}
defaultValue={model.axis_min}/>
<div className="vis_editor__label">Axis Max</div>
<input
className="vis_editor__input-grows"
type="text"
ref="axis_max"
onChange={handleTextChange('axis_max')}
defaultValue={model.axis_max}/>
<div className="vis_editor__label">Axis Position</div>
<div className="vis_editor__row_item">
<Select
clearable={false}
options={positionOptions}
value={model.axis_position}
onChange={handleSelectChange('axis_position')}/>
</div>
</div>
) : (<div style={{ display:'none' }}/>) }
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Chart = React.createClass({
if (props.yaxes && this.props.yaxes) {
// We need to rerender if the axis change
const valuesChanged = props.yaxes.some((axis, i) => {
return axis.tickFormatter !== this.props.yaxes[i].tickFormatter &&
return this.props.yaxes[i] && axis.tickFormatter !== this.props.yaxes[i].tickFormatter &&
axis.position !== this.props.yaxes[i].position;
});
if (props.yaxes.length !== this.props.yaxes.length || valuesChanged) {
Expand Down
15 changes: 13 additions & 2 deletions src/core_plugins/metrics/server/lib/get_vis_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ function getPanelData(req) {
const { index_pattern, time_field } = panel;
return calculateIndices(req, index_pattern, time_field).then(indices => {
const params = getRequestParams(req, panel, indices);
return callWithRequest(req, 'search', params)
.then(handleResponse(panel))
return callWithRequest(req, 'msearch', params)
.then(resp => {
const result = {};
result[panel.id] = {
id: panel.id,
series: resp.responses
.map(handleResponse(panel))
.reduce((acc, data) => {
return acc.concat(data);
}, [])
};
return result;
})
.catch(handleErrorResponse(panel));
});
};
Expand Down
110 changes: 63 additions & 47 deletions src/core_plugins/metrics/server/lib/vis_data/get_request_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,64 @@ import getBucketSize from './get_bucket_size';
import getBucketsPath from '../get_buckets_path';
import basicAggs from '../../../public/lib/basic_aggs';
import bucketTransform from '../bucket_transform';
import unitToSeconds from '../unit_to_seconds';

export default (req, panel, indices) => {
const { bucketSize, intervalString } = getBucketSize(req, panel);
const globalFilters = req.payload.filters;
const from = moment.utc(req.payload.timerange.min);
const to = moment.utc(req.payload.timerange.max);
const { index_pattern, time_field, interval } = panel;
const params = {
index: indices,
ignore: [404],
timeout: '90s',
requestTimeout: 90000,
ignoreUnavailable: true,
body: {
size: 0,
query: {
bool: {
must: [],
should: [],
must_not: []
}
},
aggs: {}
const bodies = [];
panel.series.forEach(series => {
const { bucketSize, intervalString } = getBucketSize(req, panel);
const globalFilters = req.payload.filters;
const from = moment.utc(req.payload.timerange.min);
const to = moment.utc(req.payload.timerange.max);

if (/^([\d]+)([shmdwMy]|ms)$/.test(series.offset_time)) {
const matches = series.offset_time.match(/^([\d]+)([shmdwMy]|ms)$/);
if (matches) {
const offsetSeconds = Number(matches[1]) * unitToSeconds(matches[2]);
from.subtract(offsetSeconds, 's');
to.subtract(offsetSeconds, 's');
}
}
};

const timerange = { range: {} };
timerange.range[time_field] = {
gte: from.valueOf(),
lte: to.valueOf() - (bucketSize * 1000),
format: 'epoch_millis',
};
params.body.query.bool.must.push(timerange);

if (globalFilters && !panel.ignore_global_filter) {
params.body.query.bool.must = params.body.query.bool.must.concat(globalFilters);
}

if (panel.filter) {
params.body.query.bool.must.push({
query_string: {
query: panel.filter,
analyze_wildcard: true


const { index_pattern, time_field, interval } = panel;
const params = {
index: indices,
body: {
size: 0,
query: {
bool: {
must: [],
should: [],
must_not: []
}
},
aggs: {}
}
});
}
};

const aggs = params.body.aggs;
const timerange = { range: {} };
timerange.range[time_field] = {
gte: from.valueOf(),
lte: to.valueOf() - (bucketSize * 1000),
format: 'epoch_millis',
};
params.body.query.bool.must.push(timerange);

panel.series.forEach(series => {
if (globalFilters && !panel.ignore_global_filter) {
params.body.query.bool.must = params.body.query.bool.must.concat(globalFilters);
}

if (panel.filter) {
params.body.query.bool.must.push({
query_string: {
query: panel.filter,
analyze_wildcard: true
}
});
}

const aggs = params.body.aggs;
aggs[series.id] = {};
const seriesAgg = aggs[series.id];

Expand All @@ -67,8 +75,8 @@ export default (req, panel, indices) => {
analyze_wildcard: true
}
};
// if it's a terms group by then we need to add the terms agg along
// with a metric agg for sorting
// if it's a terms group by then we need to add the terms agg along
// with a metric agg for sorting
} else if (series.split_mode === 'terms' && series.terms_field) {
seriesAgg.terms = {
field: series.terms_field,
Expand Down Expand Up @@ -148,9 +156,17 @@ export default (req, panel, indices) => {
}
});

bodies.push({
index: params.index,
ignore: [404],
timeout: '90s',
requestTimeout: 90000,
ignoreUnavailable: true,
});
bodies.push(params.body);
});

return params;
return { body: bodies };


};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default panel => error => {
result[panel.id] = {
id: panel.id,
statusCode: error.statusCode,
error: errorResponse,
error: errorResponse || error,
series: []
};
return result;
Expand Down
Loading

0 comments on commit 5ee12ac

Please sign in to comment.