Skip to content

Commit

Permalink
Backport #28840 (#30002)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline authored Feb 5, 2019
1 parent 9eae769 commit fbe7667
Show file tree
Hide file tree
Showing 28 changed files with 2,374,879 additions and 5,085 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
i18n-default-message="Jobs"
></a>
<a
ng-if="!monitoringMain.instance"
ng-if="(monitoringMain.isCcrEnabled || monitoringMain.isActiveTab('ccr')) && !monitoringMain.instance"
kbn-href="#/elasticsearch/ccr"
class="kuiLocalTab"
ng-class="{'kuiLocalTab-isSelected': monitoringMain.isActiveTab('ccr')}"
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/monitoring/public/directives/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ uiModule.directive('monitoringMain', (breadcrumbs, license, kbnUrl, config) => {
tabIconLabel: attributes.tabIconLabel,
pipelineId: attributes.pipelineId,
pipelineHash: attributes.pipelineHash,
pipelineVersions: get(scope, 'pageData.versions')
pipelineVersions: get(scope, 'pageData.versions'),
isCcrEnabled: attributes.isCcrEnabled
},
clusterName: get(scope, 'cluster.cluster_name')
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<monitoring-main
product="elasticsearch"
name="indices"
is-ccr-enabled="{{ elasticsearchIndices.isCcrEnabled }}"
data-test-subj="elasticsearchIndicesListingPage"
>
<div id="elasticsearchIndicesReact"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ uiRoutes.when('/elasticsearch/indices', {
$injector
});

this.isCcrEnabled = $scope.cluster.isCcrEnabled;

// for binding
const toggleShowSystemIndices = isChecked => {
// flip the boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<monitoring-main
product="elasticsearch"
name="nodes"
is-ccr-enabled="{{ elasticsearchNodes.isCcrEnabled }}"
data-test-subj="elasticsearchNodesListingPage"
>
<div id="elasticsearchNodesReact"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ uiRoutes.when('/elasticsearch/nodes', {
$injector
});

this.isCcrEnabled = $scope.cluster.isCcrEnabled;

$scope.$watch(() => this.data, data => {
this.renderReact(data);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ElasticsearchOverviewController extends MonitoringViewBaseControlle
$injector
});

this.isCcrEnabled = $scope.cluster.isCcrEnabled;
this.showShardActivityHistory = false;
this.toggleShardActivityHistory = () => {
this.showShardActivityHistory = !this.showShardActivityHistory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<monitoring-main
product="elasticsearch"
name="overview"
is-ccr-enabled="{{ elasticsearchOverview.isCcrEnabled }}"
data-test-subj="elasticsearchOverviewPage"
>
<div id="elasticsearchOverviewReact"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Array [
"status": "green",
},
},
"isCcrEnabled": undefined,
"isPrimary": true,
"isSupported": true,
"kibana": Object {
Expand Down Expand Up @@ -176,6 +177,7 @@ Array [
"status": "green",
},
},
"isCcrEnabled": undefined,
"isPrimary": false,
"isSupported": true,
"kibana": Object {
Expand Down Expand Up @@ -283,6 +285,7 @@ Array [
"status": "green",
},
},
"isCcrEnabled": undefined,
"isPrimary": false,
"isSupported": true,
"kibana": Object {
Expand Down Expand Up @@ -385,6 +388,7 @@ Array [
"status": "green",
},
},
"isCcrEnabled": undefined,
"isPrimary": false,
"isSupported": true,
"kibana": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getClustersSummary } from './get_clusters_summary';
import { CLUSTER_ALERTS_SEARCH_SIZE, STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants';
import { getApmsForClusters } from '../apm/get_apms_for_clusters';
import { i18n } from '@kbn/i18n';
import { checkCcrEnabled } from '../elasticsearch/ccr';
import { standaloneClusterDefinition, hasStandaloneClusters } from '../standalone_clusters';

/**
Expand Down Expand Up @@ -149,7 +150,10 @@ export async function getClustersFromRequest(req, indexPatterns, { clusterUuid,
set(clusters[clusterIndex], 'apm', apm.stats);
});

// check ccr configuration
const isCcrEnabled = await checkCcrEnabled(req, esIndexPattern);

const config = req.server.config();
const kibanaUuid = config.get('server.uuid');
return getClustersSummary(clusters, kibanaUuid);
return getClustersSummary(clusters, kibanaUuid, isCcrEnabled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { pick, omit, get } from 'lodash';
import { calculateOverallStatus } from '../calculate_overall_status';

export function getClustersSummary(clusters, kibanaUuid) {
export function getClustersSummary(clusters, kibanaUuid, isCcrEnabled) {
return clusters.map(cluster => {
const {
isSupported,
Expand Down Expand Up @@ -78,6 +78,7 @@ export function getClustersSummary(clusters, kibanaUuid) {
status,
kibana && kibana.status || null
]),
isCcrEnabled
};
});
}
51 changes: 51 additions & 0 deletions x-pack/plugins/monitoring/server/lib/elasticsearch/ccr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { get } from 'lodash';
import moment from 'moment';
import { checkParam } from '../error_missing_required';
import { ElasticsearchMetric } from '../metrics';
import { createQuery } from '../create_query';

export function handleResponse(response) {
const isEnabled = get(response, 'hits.hits[0]._source.stack_stats.xpack.ccr.enabled');
const isAvailable = get(response, 'hits.hits[0]._source.stack_stats.xpack.ccr.available');
return isEnabled && isAvailable;
}

export async function checkCcrEnabled(req, esIndexPattern) {
checkParam(esIndexPattern, 'esIndexPattern in getNodes');

const start = moment.utc(req.payload.timeRange.min).valueOf();
const end = moment.utc(req.payload.timeRange.max).valueOf();

const clusterUuid = req.params.clusterUuid;
const metricFields = ElasticsearchMetric.getMetricFields();

const params = {
index: esIndexPattern,
size: 1,
terminate_after: 1,
ignoreUnavailable: true,
body: {
query: createQuery({
type: 'cluster_stats',
start,
end,
clusterUuid,
metric: metricFields
}),
sort: [ { timestamp: { order: 'desc' } } ]
},
filterPath: [
'hits.hits._source.stack_stats.xpack.ccr',
]
};

const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
const response = await callWithRequest(req, 'search', params);
return handleResponse(response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function esIndicesRoute(server) {

return {
clusterStatus: getClusterStatus(clusterStats, shardStats),
indices
indices,
};
} catch(err) {
throw handleError(err, req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function esNodesRoute(server) {
const clusterStatus = getClusterStatus(clusterStats, shardStats);
const nodes = await getNodes(req, esIndexPattern, clusterStats, shardStats);

return { clusterStatus, nodes, };
return { clusterStatus, nodes };
} catch(err) {
throw handleError(err, req);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function esOverviewRoute(server) {
return {
clusterStatus: getClusterStatus(clusterStats, shardStats),
metrics,
shardActivity
shardActivity,
};
} catch (err) {
throw handleError(err, req);
Expand Down
Loading

0 comments on commit fbe7667

Please sign in to comment.