-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Converting indexPattern to indexList is now async #5173
Changes from all commits
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,7 +6,7 @@ define(function (require) { | |
|
||
require('ui/modules') | ||
.get('kibana') | ||
.directive('validateQuery', function (es, $compile, timefilter, kbnIndex, debounce, Private) { | ||
.directive('validateQuery', function (es, $compile, timefilter, kbnIndex, debounce, Promise, Private) { | ||
var fromUser = Private(require('ui/validate_query/lib/from_user')); | ||
var toUser = require('ui/validate_query/lib/to_user'); | ||
|
||
|
@@ -32,40 +32,37 @@ define(function (require) { | |
}; | ||
|
||
function validator(query) { | ||
var index; | ||
var type; | ||
if (request.abort) request.abort(); | ||
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. In order for request.abort to exist it needs to be the exact promise that was returned by the es client. These changes set request on line 39 instead, so 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. Hmm... I'm not sure if this ever worked then. The promise that was set on This is what existed before: So If that was indeed a bug already, this PR has a bit of urgency to it since it's needed for other PRs, so I'd rather address the bug in a subsequent PR. 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. Agreed |
||
|
||
if ($scope.queryInput) { | ||
useSearchSource(); | ||
} else { | ||
useDefaults(); | ||
} | ||
var prepare = $scope.queryInput ? useSearchSource : useDefaults; | ||
|
||
return sendRequest(); | ||
request = prepare().then(sendRequest); | ||
|
||
function useSearchSource() { | ||
var pattern = $scope.queryInput.get('index'); | ||
if (!pattern) return useDefaults(); | ||
|
||
if (_.isString(pattern)) { | ||
index = pattern; | ||
} else if (_.isFunction(pattern.toIndexList)) { | ||
index = pattern.toIndexList(); | ||
return Promise.resolve({ index: pattern }); | ||
} else if (_.isFunction(_.get(pattern, 'toIndexList'))) { | ||
return pattern.toIndexList().then(function (indexList) { | ||
return { index: indexList }; | ||
}); | ||
} else { | ||
useDefaults(); | ||
return useDefaults(); | ||
} | ||
} | ||
|
||
function useDefaults() { | ||
index = kbnIndex; | ||
type = '__kibanaQueryValidator'; | ||
return Promise.resolve({ | ||
index: kbnIndex, | ||
type: '__kibanaQueryValidator' | ||
}); | ||
} | ||
|
||
function sendRequest() { | ||
request = es.indices.validateQuery({ | ||
index: index, | ||
type: type, | ||
function sendRequest(config) { | ||
return es.indices.validateQuery({ | ||
index: config.index, | ||
type: config.type, | ||
explain: true, | ||
ignoreUnavailable: true, | ||
body: { | ||
|
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.
I feel like we should be setting
this._queueCreated = false;
here, andthis._queueCreated = true;
below byself._queue = ...
;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.
I agree that we should flag the queue as created inside createQueue itself. Good catch.
I still think it makes sense to default _queueCreated to false during instantiation though since it can technically be leveraged (via reportStatus) prior to start() being invoked.
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.
👍