Skip to content
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

Implements a pattern checker directive for use in the Add Data UI #6493

Merged
merged 6 commits into from
Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h3>Follow these instructions to install Filebeat</h3>
Now that you've got a fresh pipeline and index pattern, let's throw some data at it!
</div>

<div>
<div class="install-filebeat">
<ol>
<li>Install Filebeat on all servers on which you want to tail logs
(<a target="_blank" href="https://www.elastic.co/guide/en/beats/filebeat/master/filebeat-installation.html">
Expand Down Expand Up @@ -43,5 +43,10 @@ <h3>Follow these instructions to install Filebeat</h3>
instructions
</a>)
</li>
<li>Verify your filebeat installation below. We'll poll your new index pattern for documents and let you know when
they show up. If you'd like to skip this step, simply click Done now.
</li>
</ol>
</div>

<pattern-checker pattern="installStep.results.indexPattern.id"/>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import modules from 'ui/modules';
import template from 'plugins/kibana/settings/sections/indices/add_data_steps/install_filebeat_step.html';
import 'ui/pattern_checker';
import { patternToIngest } from '../../../../../common/lib/convert_pattern_and_ingest_name';

modules.get('apps/settings')
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/kibana/public/settings/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ kbn-settings-indices {
.time-and-pattern > div {}
}

filebeat-wizard {
.nav-buttons {
float: right;
}
}

.wizard-step-headings{
margin-top: 1em;

Expand Down Expand Up @@ -238,3 +244,6 @@ kbn-settings-indices {
}
}

.install-filebeat {
padding-bottom: 1em;
}
95 changes: 95 additions & 0 deletions src/ui/public/pattern_checker/__tests__/pattern_checker.js
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();
});

});
2 changes: 2 additions & 0 deletions src/ui/public/pattern_checker/pattern_checker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span class="spinner"></span>
Querying {{checker.pattern}}... {{checker.resultCount}} results
52 changes: 52 additions & 0 deletions src/ui/public/pattern_checker/pattern_checker.js
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();
}
};
});

3 changes: 3 additions & 0 deletions src/ui/public/pattern_checker/pattern_checker.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pattern-checker .spinner {
padding: 0 1em;
}