Skip to content

Commit

Permalink
Feature/translate monitoring server (elastic#25195)
Browse files Browse the repository at this point in the history
* Translate monitoring server(without metrics folder)

* Fix issue

* Fix issues

* Fix issues

* Remove eslint rule disabling
  • Loading branch information
Nox911 authored and maryia-lapata committed Nov 21, 2018
1 parent cd9802e commit 7d4466e
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { get } from 'lodash';
import moment from 'moment';
import { verifyMonitoringLicense } from './verify_monitoring_license';
import { i18n } from '@kbn/i18n';

/**
* Retrieve any statically defined cluster alerts (not indexed) for the {@code cluster}.
Expand All @@ -32,8 +33,12 @@ export function staticAlertForCluster(cluster) {
},
update_timestamp: cluster.timestamp,
timestamp: get(cluster, 'license.issue_date', cluster.timestamp),
prefix: 'Configuring TLS will be required to apply a Gold or Platinum license when security is enabled.',
message: 'See documentation for details.'
prefix: i18n.translate('xpack.monitoring.clusterAlerts.clusterNeedsTSLEnabledDescription', {
defaultMessage: 'Configuring TLS will be required to apply a Gold or Platinum license when security is enabled.'
}),
message: i18n.translate('xpack.monitoring.clusterAlerts.seeDocumentationDescription', {
defaultMessage: 'See documentation for details.'
})
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { get, find } from 'lodash';
import { verifyMonitoringLicense } from './verify_monitoring_license';
import { i18n } from '@kbn/i18n';

export function alertsClustersAggregation(req, alertsIndex, clusters, checkLicense) {
const verification = verifyMonitoringLicense(req.server);
Expand Down Expand Up @@ -105,7 +106,14 @@ export function alertsClustersAggregation(req, alertsIndex, clusters, checkLicen
alerts = {
clusterMeta: {
enabled: false,
message: `Cluster [${cluster.cluster_name}] license type [${license.type}] does not support Cluster Alerts` }
message: i18n.translate('xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription', {
defaultMessage: 'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
values: {
clusterName: cluster.cluster_name,
licenseType: `${license.type}`
}
})
}
};
}

Expand Down
29 changes: 25 additions & 4 deletions x-pack/plugins/monitoring/server/cluster_alerts/check_license.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { includes } from 'lodash';
import { i18n } from '@kbn/i18n';

/**
* Function to do the work of checking license for cluster alerts feature support
Expand All @@ -24,27 +25,47 @@ export function checkLicense(type, active, clusterSource, watcher = true) {
// Disabled because there is no license
if (!type) {
return Object.assign(licenseInfo, {
message: `Cluster Alerts are not displayed because the [${clusterSource}] cluster's license could not be determined.`
message: i18n.translate('xpack.monitoring.clusterAlerts.checkLicense.licenseNotDeterminedDescription', {
defaultMessage: `Cluster Alerts are not displayed because the [{clusterSource}] cluster's license could not be determined.`,
values: {
clusterSource
}
})
});
}

// Disabled because the license type is not valid (basic)
if (!includes([ 'trial', 'standard', 'gold', 'platinum' ], type)) {
return Object.assign(licenseInfo, {
message: `Cluster Alerts are not displayed if Watcher is disabled or the [${clusterSource}] cluster's current license is basic.`
message: i18n.translate('xpack.monitoring.clusterAlerts.checkLicense.licenseIsBasicDescription', {
defaultMessage:
`Cluster Alerts are not displayed if Watcher is disabled or the [{clusterSource}] cluster's current license is basic.`,
values: {
clusterSource
}
})
});
}

// Disabled because the license is inactive
if (!active) {
return Object.assign(licenseInfo, {
message: `Cluster Alerts are not displayed because the [${clusterSource}] cluster's current license [${type}] is not active.`
message: i18n.translate('xpack.monitoring.clusterAlerts.checkLicense.licenseNotActiveDescription', {
defaultMessage: `Cluster Alerts are not displayed because the [{clusterSource}] cluster's current license [{type}] is not active.`,
values: {
clusterSource,
type
}
})
});
}

// Disabled because Watcher is not enabled (it may or may not be available)
if (!watcher) {
return Object.assign(licenseInfo, { message: 'Cluster alerts is not enabled because Watcher is disabled.' });
return Object.assign(licenseInfo, {
message: i18n.translate('xpack.monitoring.clusterAlerts.checkLicense.watcherIsDisabledDescription', {
defaultMessage: 'Cluster alerts is not enabled because Watcher is disabled.' })
});
}

return Object.assign(licenseInfo, { clusterAlerts: { enabled: true } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { get } from 'lodash';
import { i18n } from '@kbn/i18n';

/**
* Determine if an API for Cluster Alerts should respond based on the license and configuration of the monitoring cluster.
Expand All @@ -31,12 +32,14 @@ export function verifyMonitoringLicense(server) {

return {
enabled: false,
message: 'Status of Cluster Alerts feature could not be determined.'
message: i18n.translate('xpack.monitoring.clusterAlerts.notDeterminedLicenseDescription', {
defaultMessage: 'Status of Cluster Alerts feature could not be determined.' })
};
}

return {
enabled: false,
message: 'Cluster Alerts feature is disabled.'
message: i18n.translate('xpack.monitoring.clusterAlerts.disabledLicenseDescription', {
defaultMessage: 'Cluster Alerts feature is disabled.' })
};
}
13 changes: 11 additions & 2 deletions x-pack/plugins/monitoring/server/lib/cluster/get_cluster_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { badRequest, notFound } from 'boom';
import { getClustersStats } from './get_clusters_stats';
import { i18n } from '@kbn/i18n';

/**
* This will fetch the cluster stats and cluster state as a single object for the cluster specified by the {@code req}.
Expand All @@ -17,14 +18,22 @@ import { getClustersStats } from './get_clusters_stats';
*/
export function getClusterStats(req, esIndexPattern, clusterUuid) {
if (!clusterUuid) {
throw badRequest('clusterUuid not specified');
throw badRequest(i18n.translate('xpack.monitoring.clusterStats.uuidNotSpecifiedErrorMessage', {
defaultMessage: '{clusterUuid} not specified',
values: { clusterUuid: 'clusterUuid' }
}));
}

// passing clusterUuid so `get_clusters` will filter for single cluster
return getClustersStats(req, esIndexPattern, clusterUuid)
.then(clusters => {
if (!clusters || clusters.length === 0) {
throw notFound(`Unable to find the cluster in the selected time range. UUID: ${clusterUuid}`);
throw notFound(i18n.translate('xpack.monitoring.clusterStats.uuidNotFoundErrorMessage', {
defaultMessage: 'Unable to find the cluster in the selected time range. UUID: {clusterUuid}',
values: {
clusterUuid
}
}));
}

return clusters[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { checkLicense as checkLicenseForAlerts } from '../../cluster_alerts/chec
import { getClustersSummary } from './get_clusters_summary';
import { CLUSTER_ALERTS_SEARCH_SIZE } from '../../../common/constants';
import { getApmsForClusters } from '../apm/get_apms_for_clusters';
import { i18n } from '@kbn/i18n';

/**
* Get all clusters or the cluster associated with {@code clusterUuid} when it is defined.
Expand All @@ -39,7 +40,12 @@ export async function getClustersFromRequest(req, indexPatterns, { clusterUuid,
// TODO: this handling logic should be two different functions
if (clusterUuid) { // if is defined, get specific cluster (no need for license checking)
if (!clusters || clusters.length === 0) {
throw notFound(`Unable to find the cluster in the selected time range. UUID: ${clusterUuid}`);
throw notFound(i18n.translate('xpack.monitoring.requestedClusters.uuidNotFoundErrorMessage', {
defaultMessage: 'Unable to find the cluster in the selected time range. UUID: {clusterUuid}',
values: {
clusterUuid
}
}));
}

const cluster = clusters[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { get } from 'lodash';
import { checkParam } from '../../error_missing_required';
import { createQuery } from '../../create_query';
import { ElasticsearchMetric } from '../../metrics';
import { i18n } from '@kbn/i18n';

export function handleResponse(shardStats, indexUuid) {
return response => {
Expand All @@ -31,10 +32,13 @@ export function handleResponse(shardStats, indexUuid) {
indexSummary = {
unassignedShards,
totalShards: get(_shardStats, 'primary', 0) + get(_shardStats, 'replica', 0) + unassignedShards,
status: _shardStats.status || 'Unknown',
status: _shardStats.status || i18n.translate('xpack.monitoring.es.indices.unknownStatusLabel', {
defaultMessage: 'Unknown' })
};
} else {
indexSummary = { status: 'Not Available', };
indexSummary = { status: i18n.translate('xpack.monitoring.es.indices.notAvailableStatusLabel', {
defaultMessage: 'Not Available' })
};
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ElasticsearchMetric } from '../../metrics';
import { createQuery } from '../../create_query';
import { calculateRate } from '../../calculate_rate';
import { getUnassignedShards } from '../shards';
import { i18n } from '@kbn/i18n';

export function handleResponse(resp, min, max, shardStats) {
// map the hits
Expand Down Expand Up @@ -57,7 +58,8 @@ export function handleResponse(resp, min, max, shardStats) {
statusSort = 3;
}
} else {
status = 'Deleted / Closed';
status = i18n.translate('xpack.monitoring.es.indices.deletedClosedStatusLabel', {
defaultMessage: 'Deleted / Closed' });
statusSort = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ElasticsearchMetric } from '../../metrics';
import { getDefaultNodeFromId } from './get_default_node_from_id';
import { calculateNodeType } from './calculate_node_type';
import { getNodeTypeClassLabel } from './get_node_type_class_label';
import { i18n } from '@kbn/i18n';

export function handleResponse(clusterState, shardStats, nodeUuid) {
return response => {
Expand Down Expand Up @@ -44,13 +45,16 @@ export function handleResponse(clusterState, shardStats, nodeUuid) {
dataSize: get(sourceStats, 'indices.store.size_in_bytes'),
freeSpace: get(sourceStats, 'fs.total.available_in_bytes'),
usedHeap: get(sourceStats, 'jvm.mem.heap_used_percent'),
status: 'Online',
status: i18n.translate('xpack.monitoring.es.nodes.onlineStatusLabel', {
defaultMessage: 'Online' }),
isOnline: true,
};
} else {
nodeSummary = {
nodeTypeLabel: 'Offline Node',
status: 'Offline',
nodeTypeLabel: i18n.translate('xpack.monitoring.es.nodes.offlineNodeStatusLabel', {
defaultMessage: 'Offline Node' }),
status: i18n.translate('xpack.monitoring.es.nodes.offlineStatusLabel', {
defaultMessage: 'Offline' }),
isOnline: false,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Note: currently only `node` and `master` are supported due to
* https://github.com/elastic/x-pack-kibana/issues/608
*/

import { i18n } from '@kbn/i18n';

export const nodeTypeClass = {
invalid: 'fa-exclamation-triangle',
node: 'fa-server',
Expand All @@ -18,10 +21,16 @@ export const nodeTypeClass = {
};

export const nodeTypeLabel = {
invalid: 'Invalid Node',
node: 'Node',
master: 'Master Node',
master_only: 'Master Only Node',
data: 'Data Only Node',
client: 'Client Node'
invalid: i18n.translate('xpack.monitoring.es.nodeType.invalidNodeLabel', {
defaultMessage: 'Invalid Node' }),
node: i18n.translate('xpack.monitoring.es.nodeType.nodeLabel', {
defaultMessage: 'Node' }),
master: i18n.translate('xpack.monitoring.es.nodeType.masterNodeLabel', {
defaultMessage: 'Master Node' }),
master_only: i18n.translate('xpack.monitoring.es.nodeType.masterOnlyNodeLabel', {
defaultMessage: 'Master Only Node' }),
data: i18n.translate('xpack.monitoring.es.nodeType.dataOnlyNodeLabel', {
defaultMessage: 'Data Only Node' }),
client: i18n.translate('xpack.monitoring.es.nodeType.clientNodeLabel', {
defaultMessage: 'Client Node' })
};
7 changes: 5 additions & 2 deletions x-pack/plugins/monitoring/server/lib/errors/auth_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { forbidden } from 'boom';
import { i18n } from '@kbn/i18n';

const getStatusCode = err => {
return err.isBoom ? err.output.statusCode : err.statusCode;
Expand All @@ -26,9 +27,11 @@ export function handleAuthError(err) {
* connection but not the monitoring connection
*/
if (statusCode === 401) {
message = 'Invalid authentication for monitoring cluster';
message = i18n.translate('xpack.monitoring.errors.invalidAuthErrorMessage', {
defaultMessage: 'Invalid authentication for monitoring cluster' });
} else {
message = 'Insufficient user permissions for monitoring data';
message = i18n.translate('xpack.monitoring.errors.insufficientUserErrorMessage', {
defaultMessage: 'Insufficient user permissions for monitoring data' });
}

return forbidden(message);
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/monitoring/server/lib/errors/known_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { boomify } from 'boom';

import { i18n } from '@kbn/i18n';
/*
* Check if the given error message is a known "safe" type of error
* in which case we want to give the status as 503 and show the error message.
Expand All @@ -17,9 +17,12 @@ import { boomify } from 'boom';
const KNOWN_ERROR_STATUS_CODE = 503;

const mapTypeMessage = {
ConnectionFault: 'Check the Elasticsearch Monitoring cluster network connection and refer to the Kibana logs for more information.',
NoConnections: 'Check the Elasticsearch Monitoring cluster network connection and refer to the Kibana logs for more information.',
StatusCodeError: 'Check the Elasticsearch Monitoring cluster network connection or the load level of the nodes.'
ConnectionFault: i18n.translate('xpack.monitoring.errors.connectionFaultErrorMessage', {
defaultMessage: 'Check the Elasticsearch Monitoring cluster network connection and refer to the Kibana logs for more information.' }),
NoConnections: i18n.translate('xpack.monitoring.errors.noConnectionsErrorMessage', {
defaultMessage: 'Check the Elasticsearch Monitoring cluster network connection and refer to the Kibana logs for more information.' }),
StatusCodeError: i18n.translate('xpack.monitoring.errors.statusCodeErrorMessage', {
defaultMessage: 'Check the Elasticsearch Monitoring cluster network connection or the load level of the nodes.' })
};

export function isKnownError(err) {
Expand Down

0 comments on commit 7d4466e

Please sign in to comment.