-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6493 from Bargs/ingest/filebeatVerify
Implements a pattern checker directive for use in the Add Data UI
- Loading branch information
Showing
7 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/plugins/kibana/public/settings/sections/indices/add_data_steps/install_filebeat_step.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/ui/public/pattern_checker/__tests__/pattern_checker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import ngMock from 'ng_mock'; | ||
import expect from 'expect.js'; | ||
import _ from 'lodash'; | ||
import sinon from 'auto-release-sinon'; | ||
|
||
describe('pattern checker', function () { | ||
let $httpBackend; | ||
let $compile; | ||
let $rootScope; | ||
let apiResponse; | ||
let $timeout; | ||
const notifyFatalStub = sinon.stub(); | ||
|
||
beforeEach(ngMock.module('kibana')); | ||
|
||
beforeEach(ngMock.module(function ($provide) { | ||
notifyFatalStub.reset(); | ||
|
||
$provide.value('Notifier', function () { | ||
this.fatal = notifyFatalStub; | ||
}); | ||
})); | ||
|
||
beforeEach(ngMock.inject(function ($injector, Private) { | ||
$httpBackend = $injector.get('$httpBackend'); | ||
$compile = $injector.get('$compile'); | ||
$rootScope = $injector.get('$rootScope'); | ||
$timeout = $injector.get('$timeout'); | ||
|
||
apiResponse = $httpBackend.when('POST', /\/api\/kibana\/.*\/_count/); | ||
})); | ||
|
||
it('should display the number of documents in a given index pattern', function () { | ||
apiResponse.respond(200, {count: 1}); | ||
|
||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope); | ||
|
||
$httpBackend.flush(); | ||
$rootScope.$digest(); | ||
expect(_.contains(element.html(), `1 results`)).to.be.ok(); | ||
}); | ||
|
||
it('should poll the api for changes to the document count and update the ui', function () { | ||
apiResponse.respond(200, {count: 1}); | ||
|
||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope); | ||
|
||
$httpBackend.flush(); | ||
$rootScope.$digest(); | ||
expect(_.contains(element.html(), `1 results`)).to.be.ok(); | ||
|
||
apiResponse.respond(200, {count: 2}); | ||
$timeout.flush(); | ||
$httpBackend.flush(); | ||
$rootScope.$digest(); | ||
expect(_.contains(element.html(), `2 results`)).to.be.ok(); | ||
}); | ||
|
||
it('should display 0 results when API responds with 404', function () { | ||
apiResponse.respond(404); | ||
|
||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope); | ||
|
||
$httpBackend.flush(); | ||
$rootScope.$digest(); | ||
expect(_.contains(element.html(), `0 results`)).to.be.ok(); | ||
}); | ||
|
||
it('should throw a fatal notificaiton for any error other than a 404', function () { | ||
apiResponse.respond(500, 'Bad things happened'); | ||
|
||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope); | ||
|
||
$httpBackend.flush(); | ||
$rootScope.$digest(); | ||
|
||
expect(notifyFatalStub.called).to.be.ok(); | ||
}); | ||
|
||
it('should stop polling when the scope is destroyed', function () { | ||
apiResponse.respond(200, {count: 1}); | ||
|
||
const element = $compile('<pattern-checker pattern="logstash"></pattern-checker>')($rootScope); | ||
const scope = element.scope(); | ||
|
||
$httpBackend.flush(); | ||
$rootScope.$digest(); | ||
expect(_.contains(element.html(), `1 results`)).to.be.ok(); | ||
|
||
scope.$destroy(); | ||
$timeout.flush(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<span class="spinner"></span> | ||
Querying {{checker.pattern}}... {{checker.resultCount}} results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import uiModules from 'ui/modules'; | ||
import template from './pattern_checker.html'; | ||
import './pattern_checker.less'; | ||
import chrome from 'ui/chrome'; | ||
|
||
const module = uiModules.get('kibana'); | ||
|
||
module.directive('patternChecker', function () { | ||
return { | ||
restrict: 'E', | ||
template: template, | ||
controllerAs: 'checker', | ||
bindToController: true, | ||
scope: { | ||
pattern: '=' | ||
}, | ||
controller: function (Notifier, $scope, $timeout, $http) { | ||
let validationTimeout; | ||
|
||
var notify = new Notifier({ | ||
location: 'Add Data' | ||
}); | ||
|
||
this.validateInstall = () => { | ||
$http.post(chrome.addBasePath(`/api/kibana/${this.pattern}/_count`)) | ||
.then( | ||
(response) => { | ||
this.resultCount = response.data.count; | ||
}, | ||
(error) => { | ||
if (error.status === 404) { | ||
this.resultCount = 0; | ||
} | ||
else { | ||
notify.fatal(error); | ||
} | ||
} | ||
) | ||
.then(() => { | ||
validationTimeout = $timeout(this.validateInstall, 5000); | ||
}); | ||
}; | ||
|
||
$scope.$on('$destroy', () => { | ||
$timeout.cancel(validationTimeout); | ||
}); | ||
|
||
this.validateInstall(); | ||
} | ||
}; | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pattern-checker .spinner { | ||
padding: 0 1em; | ||
} |