-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Introduce date histogram time base configuration to EditorConfig #22344
Changes from 6 commits
7823369
585622d
0a2b9c5
1da037b
7464096
6a70583
4346edb
97d0318
551f945
415c573
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,6 @@ | |
position="'right'" | ||
content="'Interval will be automatically scaled in the event that the provided value creates more buckets than specified by Advanced Setting\'s histogram:maxBars'" | ||
></icon-tip> | ||
|
||
<icon-tip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we changing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ppisljar I changed the previous |
||
ng-if="editorConfig.interval.warning" | ||
position="'right'" | ||
content="editorConfig.interval.warning" | ||
type="'alert'" | ||
color="'warning'" | ||
style="float: right" | ||
></icon-tip> | ||
</label> | ||
<input | ||
id="visEditorInterval{{agg.id}}" | ||
|
@@ -27,4 +18,11 @@ | |
step="{{editorConfig.interval.base}}" | ||
input-number | ||
> | ||
<div | ||
ng-if="editorConfig.interval.help" | ||
class="kuiSubText kuiSubduedText kuiVerticalRhythmSmall" | ||
style="margin-top: 5px" | ||
> | ||
<span>{{editorConfig.interval.help}}</span> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { parseEsInterval } from '../parse_es_interval'; | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
import expect from 'expect.js'; | ||
|
||
describe('parseEsInterval', function () { | ||
it('should correctly parse an interval containing unit and single value', function () { | ||
expect(parseEsInterval('1ms')).to.eql({ value: 1, unit: 'ms', type: 'fixed' }); | ||
expect(parseEsInterval('1s')).to.eql({ value: 1, unit: 's', type: 'fixed' }); | ||
expect(parseEsInterval('1m')).to.eql({ value: 1, unit: 'm', type: 'calendar' }); | ||
expect(parseEsInterval('1h')).to.eql({ value: 1, unit: 'h', type: 'calendar' }); | ||
expect(parseEsInterval('1d')).to.eql({ value: 1, unit: 'd', type: 'calendar' }); | ||
expect(parseEsInterval('1w')).to.eql({ value: 1, unit: 'w', type: 'calendar' }); | ||
expect(parseEsInterval('1M')).to.eql({ value: 1, unit: 'M', type: 'calendar' }); | ||
expect(parseEsInterval('1y')).to.eql({ value: 1, unit: 'y', type: 'calendar' }); | ||
}); | ||
|
||
it('should correctly parse an interval containing unit and multiple value', function () { | ||
expect(parseEsInterval('250ms')).to.eql({ value: 250, unit: 'ms', type: 'fixed' }); | ||
expect(parseEsInterval('90s')).to.eql({ value: 90, unit: 's', type: 'fixed' }); | ||
expect(parseEsInterval('60m')).to.eql({ value: 60, unit: 'm', type: 'fixed' }); | ||
expect(parseEsInterval('12h')).to.eql({ value: 12, unit: 'h', type: 'fixed' }); | ||
expect(parseEsInterval('7d')).to.eql({ value: 7, unit: 'd', type: 'fixed' }); | ||
}); | ||
|
||
it('should throw an error for intervals containing calendar unit and multiple value', function () { | ||
expect(parseEsInterval).withArgs('4w').to.throwError(); | ||
expect(parseEsInterval).withArgs('12M').to.throwError(); | ||
expect(parseEsInterval).withArgs('10y').to.throwError(); | ||
}); | ||
|
||
it('should throw an error for invalid interval formats', function () { | ||
expect(parseEsInterval).withArgs('1').to.throwError(); | ||
expect(parseEsInterval).withArgs('h').to.throwError(); | ||
expect(parseEsInterval).withArgs('0m').to.throwError(); | ||
expect(parseEsInterval).withArgs('0.5h').to.throwError(); | ||
expect(parseEsInterval).withArgs().to.throwError(); | ||
expect(parseEsInterval).withArgs({}).to.throwError(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import dateMath from '@kbn/datemath'; | ||
|
||
const ES_INTERVAL_STRING_RE = new RegExp('^([1-9][0-9]*)\\s*(' + dateMath.units.join('|') + ')$'); | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
|
||
/** | ||
* Strict version of parseInterval(), enforces ES interval format, and disallows fractional values | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
* | ||
* @param interval | ||
* @returns {{amount: (RegExpMatchArray | null) | number, unit: (RegExpMatchArray | null) | string, type: string}} | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
*/ | ||
export function parseEsInterval(interval = '') { | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
const matches = String(interval) | ||
.trim() | ||
.match(ES_INTERVAL_STRING_RE); | ||
|
||
if (!matches) { | ||
throw Error(`Invalid interval format: ${interval}`); | ||
} | ||
|
||
const value = matches && parseFloat(matches[1]); | ||
const unit = matches && matches[2]; | ||
const type = unit && dateMath.unitsMap[unit].type; | ||
|
||
if (type === 'calendar' && value !== 1) { | ||
throw Error(`Invalid calendar interval: ${interval}, value must be 1`); | ||
} | ||
|
||
return { | ||
value, | ||
unit, | ||
type: (type === 'mixed' && value === 1) || type === 'calendar' ? 'calendar' : 'fixed', | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
import { parseInterval } from './utils/parse_interval'; | ||
import { uiModules } from './modules'; | ||
import { leastCommonInterval } from './vis/lib/least_common_interval'; | ||
|
||
uiModules | ||
.get('kibana') | ||
|
@@ -27,14 +28,31 @@ uiModules | |
restrict: 'A', | ||
require: 'ngModel', | ||
link: function ($scope, $el, attrs, ngModelCntrl) { | ||
const baseInterval = attrs.validateDateInterval || null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we are trying to get anyway rid of Angular, but could we use an |
||
|
||
ngModelCntrl.$parsers.push(check); | ||
ngModelCntrl.$formatters.push(check); | ||
|
||
function check(value) { | ||
ngModelCntrl.$setValidity('dateInterval', parseInterval(value) != null); | ||
if(baseInterval) { | ||
ngModelCntrl.$setValidity('dateInterval', parseWithBase(value) === true); | ||
} else { | ||
ngModelCntrl.$setValidity('dateInterval', parseInterval(value) != null); | ||
} | ||
return value; | ||
} | ||
|
||
// When base interval is set, check for least common interval and allow | ||
// input the value is the same. This means that the input interval is a | ||
// multiple of the base interval. | ||
function parseWithBase(value) { | ||
try { | ||
const lci = leastCommonInterval(baseInterval, value); | ||
return lci === value.replace(/\s/g, ''); | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
} catch(e) { | ||
return false; | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding
q
to this list introduces all sorts of problems later down the stack due to moment duration's lack of support for this unit