Reporting functionality with opt in/out

This commit is contained in:
Rashid Khan 2014-01-02 13:54:33 -07:00
parent 386de6ec1b
commit a33e146a65
4 changed files with 59 additions and 9 deletions

View file

@ -12,7 +12,11 @@
<div class="section">
<div class="editor-option">
<label class="small">Usage Data <tip>Help make Elasticsearch better by sharing anonymous usage data.</tip></label>
<input type="checkbox" ng-model="panel.optin"/>
<input type="checkbox" ng-model="cookies.marvelOptIn" ng-true-value="IN" ng-false-value="OUT" />
</div>
<div ng-show="kbnVersion == '@REV@'" class="editor-option">
<label class="small">Clear Marvel Cookies <tip>Only shown in unbuilt versions, clear optin and version cookies</tip></label>
<button class="btn btn-danger" ng-click="clearMarvelCookies()">Clear</button>
</div>
</div>
</div>

View file

@ -5,7 +5,7 @@
}
</style>
<ul class="inline" ng-if="!_.isUndefined(panel.optin)">
<ul class="inline">
<li><strong>Name:</strong> {{data.cluster_name}}</li>
<li><strong>Status:</strong> <span ng-class="healthClass(data.status)">{{data.status}}</span></li>
<li><strong>Nodes:</strong> {{data.nodes.count.total}}</li>

View file

@ -21,7 +21,8 @@ function (angular, app, _, kbn) {
var module = angular.module('kibana.panels.marvel.cluster', []);
app.useModule(module);
module.controller('marvel.cluster', function($scope, $modal, $q, querySrv, dashboard, filterSrv) {
module.controller('marvel.cluster', function($scope, $modal, $q, $cookies, $http,
querySrv, dashboard, filterSrv, kbnVersion) {
$scope.panelMeta = {
modals : [],
editorTabs : [],
@ -32,13 +33,18 @@ function (angular, app, _, kbn) {
// Set and populate defaults
var _d = {
title: 'Cluster Status',
optin: undefined,
};
_.defaults($scope.panel,_d);
var reportInterval = 10000;
$scope.init = function () {
// So we can access the cookies object from the view
$scope.cookies = $cookies;
$scope.kbnVersion = kbnVersion;
// If the user hasn't opted in or out, ask them to.
if(_.isUndefined($scope.panel.optin)) {
if(_.isUndefined($cookies.marvelOptIn) || $cookies.marvelVersion !== kbnVersion) {
$scope.optInModal();
}
@ -92,6 +98,10 @@ function (angular, app, _, kbn) {
$scope.data = _.isArray(results.hits.hits) ? results.hits.hits[0]._source : undefined;
if(checkReport()) {
sendReport($scope.data);
}
// Did we find anything in that index? No? Try the next one.
if (_.isUndefined($scope.data) && _segment+1 < dashboard.indices.length) {
$scope.get_data(_segment+1,$scope.query_id);
@ -119,7 +129,14 @@ function (angular, app, _, kbn) {
};
$scope.setOptIn = function(c) {
$scope.panel.optin = c;
$cookies.marvelVersion = kbnVersion;
$cookies.marvelOptIn = c;
};
$scope.clearMarvelCookies = function() {
delete $cookies.marvelOptIn;
delete $cookies.marvelVersion;
delete $cookies.marvelLastReport;
};
$scope.optInModal = function() {
@ -137,9 +154,37 @@ function (angular, app, _, kbn) {
});
};
// Checks if we should send a report
var checkReport = function() {
if($cookies.marvelOptIn === 'IN') {
if(_.isUndefined($cookies.marvelLastReport)) {
console.log('undefined');
return true;
} else if (new Date().getTime() - parseInt($cookies.marvelLastReport,10) > reportInterval) {
return true;
} else {
return false;
}
} else {
return false;
}
};
var sendReport = function(data) {
var thisReport = new Date().getTime().toString();
// TODO: Replace this URL with the actual data sink
$http.post(
$scope.config.elasticsearch+'/'+$scope.config.kibana_index+'/report/'+thisReport,
data
).success(function() {
console.log('reported');
$cookies.marvelLastReport = thisReport;
});
};
});
// WIP
module.filter('marvelBytes', function(){
return function(text) {
if(_.isUndefined(text)) {

View file

@ -14,6 +14,7 @@
</div>
<div class="modal-footer">
<button ng-click="setOptIn(true);dismiss();" class="btn btn-success">Sure!</button>
<span ng-click="setOptIn(false);dismiss();" class="pointer small">No Thanks</span>
<!-- these set strings since cookies don't deal with boolean -->
<button ng-click="setOptIn('IN');dismiss();" class="btn btn-success">Sure!</button>
<span ng-click="setOptIn('OUT');dismiss();" class="pointer small">No Thanks</span>
</div>