From 15606aaf2199a618f1321bf5e638c46c8949e786 Mon Sep 17 00:00:00 2001 From: tibmt Date: Tue, 6 Nov 2018 18:16:56 +0300 Subject: [PATCH 1/6] translate InfraOps visualization component (Part 4 - server part) --- .../kibana_configuration_adapter.ts | 17 ++++++++++-- .../adapters/framework/apollo_server_hapi.ts | 13 +++++++-- .../framework/kibana_framework_adapter.ts | 7 ++++- .../metrics/kibana_metrics_adapter.ts | 19 +++++++++++-- .../extract_group_by_and_node_from_path.ts | 27 ++++++++++++++++--- .../adapters/nodes/lib/create_node_item.ts | 7 ++++- .../nodes/lib/get_bucket_size_in_seconds.ts | 8 +++++- x-pack/plugins/infra/server/lib/sources.ts | 10 ++++++- .../infra/server/utils/serialized_query.ts | 23 ++++++++++++---- 9 files changed, 113 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts index 62b01b3eac2a3..014fbccf31e12 100644 --- a/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import Joi from 'joi'; import { InfraConfigurationAdapter } from './adapter_types'; @@ -14,7 +15,15 @@ export class InfraKibanaConfigurationAdapter constructor(server: any) { if (!isServerWithConfig(server)) { - throw new Error('Failed to find configuration on server.'); + throw new Error( + i18n.translate( + 'xpack.infra.infraKibanaConfigurationAdapter.failedToFindConfigurationErrorTitle', + { + defaultMessage: 'Failed to find configuration on server.', + } + ) + ); + throw new Error(''); } this.server = server; @@ -24,7 +33,11 @@ export class InfraKibanaConfigurationAdapter const config = this.server.config(); if (!isKibanaConfiguration(config)) { - throw new Error('Failed to access configuration of server.'); + throw new Error( + i18n.translate('xpack.infra.infraKibanaConfigurationAdapter.failedToAccessErrorTitle', { + defaultMessage: 'Failed to access configuration of server.', + }) + ); } const configuration = config.get('xpack.infra') || {}; diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts b/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts index da858217468f1..912b879ad4167 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import * as GraphiQL from 'apollo-server-module-graphiql'; import Boom from 'boom'; import { Plugin, Request, ResponseToolkit, RouteOptions, Server } from 'hapi'; @@ -23,7 +24,11 @@ export const graphqlHapi: Plugin = { name: 'graphql', register: (server: Server, options: HapiGraphQLPluginOptions) => { if (!options || !options.graphqlOptions) { - throw new Error('Apollo Server requires options.'); + throw new Error( + i18n.translate('xpack.infra.graphqlHapi.apolloServerRequiresOptionsErrorTitle', { + defaultMessage: 'Apollo Server requires options.', + }) + ); } server.route({ @@ -96,7 +101,11 @@ export const graphiqlHapi: Plugin = { name: 'graphiql', register: (server: Server, options: HapiGraphiQLPluginOptions) => { if (!options || !options.graphiqlOptions) { - throw new Error('Apollo Server GraphiQL requires options.'); + throw new Error( + i18n.translate('xpack.infra.graphqlHapi.apolloServerGraphiQLRequiresOptionsErrorTitle', { + defaultMessage: 'Apollo Server GraphiQL requires options.', + }) + ); } server.route({ diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts index 034ce7f66a768..9b3546449fbb0 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { GraphQLSchema } from 'graphql'; import { Request, ResponseToolkit, Server } from 'hapi'; @@ -103,7 +104,11 @@ export class InfraKibanaBackendFrameworkAdapter implements InfraBackendFramework request: InfraFrameworkRequest ): InfraFrameworkIndexPatternsService { if (!isServerWithIndexPatternsServiceFactory(this.server)) { - throw new Error('Failed to access indexPatternsService for the request'); + throw new Error( + i18n.translate('xpack.infra.infraKibanaBackendFrameworkAdapter.failedToAccessErrorTitle', { + defaultMessage: 'Failed to access indexPatternsService for the request', + }) + ); } return this.server.indexPatternsServiceFactory({ callCluster: async (method: string, args: [object], ...rest: any[]) => { diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index bb7f7f6d2dc93..2d312c3723b33 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { flatten } from 'lodash'; import { InfraMetric, InfraMetricData, InfraNodeType } from '../../../../common/graphql/types'; import { InfraBackendFrameworkAdapter, InfraFrameworkRequest } from '../framework'; @@ -44,7 +45,14 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { const validNode = await checkValidNode(search, indexPattern, nodeField, options.nodeId); if (!validNode) { - throw new Error(`${options.nodeId} does not exist.`); + throw new Error( + i18n.translate('xpack.infra.kibanaMetricsAdapter.idDoesNotExistErrorTitle', { + defaultMessage: '{nodeId} does not exist.', + values: { + nodeId: options.nodeId, + }, + }) + ); } const requests = options.metrics.map(metricId => { @@ -59,7 +67,14 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { return metricIds.map((id: string) => { const infraMetricId: InfraMetric = (InfraMetric as any)[id]; if (!infraMetricId) { - throw new Error(`${id} is not a valid InfraMetric`); + throw new Error( + i18n.translate('xpack.infra.kibanaMetricsAdapter.noValidInfraMetricIdErrorTitle', { + defaultMessage: '{id} is not a valid InfraMetric', + values: { + id, + }, + }) + ); } const panel = result[infraMetricId]; return { diff --git a/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts b/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts index 60fa22b4116e4..a89de3ad0cc6a 100644 --- a/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts +++ b/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts @@ -3,6 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { InfraPathInput, InfraPathType } from '../../../../common/graphql/types'; import { InfraNodeType } from './adapter_types'; @@ -39,15 +40,35 @@ const moreThenOneEntityType = (path: InfraPathInput[]) => { export function extractGroupByAndNodeFromPath(path: InfraPathInput[]) { if (moreThenOneEntityType(path)) { - throw new Error('There can be only one entity type in the path.'); + throw new Error( + i18n.translate( + 'xpack.infra.extractGroupByAndNodeFromPath.onlyOneEntityTypeInThePathErrorTitle', + { + defaultMessage: 'There can be only one entity type in the path.', + } + ) + ); } if (path.length > 3) { - throw new Error('The path can only have a maximum of 3 elements.'); + throw new Error( + i18n.translate( + 'xpack.infra.extractGroupByAndNodeFromPath.maxThreeElementsInThePathErrorTitle', + { + defaultMessage: 'The path can only have a maximum of 3 elements.', + } + ) + ); } const nodePart = path[path.length - 1]; if (!isEntityType(nodePart)) { throw new Error( - 'The last element in the path should be either a "hosts", "containers" or "pods" path type.' + i18n.translate( + 'xpack.infra.extractGroupByAndNodeFromPath.lastElementInPathContainErrorTitle', + { + defaultMessage: + 'The last element in the path should be either a "hosts", "containers" or "pods" path type.', + } + ) ); } const nodeType = getNodeType(nodePart.type); diff --git a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts index a2d072e0897d7..24646d88576a1 100644 --- a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts +++ b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { last } from 'lodash'; import { isNumber } from 'lodash'; import moment from 'moment'; @@ -41,7 +42,11 @@ function createNodeMetrics( const bucketSize = getBucketSizeInSeconds(timerange.interval); const lastBucket = findLastFullBucket(bucket, bucketSize, options); if (!lastBucket) { - throw new Error('Date histogram returned an empty set of buckets.'); + throw new Error( + i18n.translate('xpack.infra.createNodeMetrics.emptySetOfBucketsInDateHistogramErrorTitle', { + defaultMessage: 'Date histogram returned an empty set of buckets.', + }) + ); } const metricObj = lastBucket[metric.type]; const value = (metricObj && (metricObj.normalized_value || metricObj.value)) || 0; diff --git a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts index 667f2d2f35745..8c6c2f5e323f8 100644 --- a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts +++ b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; + const intervalUnits = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms']; const INTERVAL_STRING_RE = new RegExp('^([0-9\\.]*)\\s*(' + intervalUnits.join('|') + ')$'); @@ -27,5 +29,9 @@ export const getBucketSizeInSeconds = (interval: string): number => { if (matches) { return parseFloat(matches[1]) * units[matches[2]]; } - throw new Error('Invalid interval string format.'); + throw new Error( + i18n.translate('xpack.infra.getBucketSizeInSeconds.invalidInternalStringFormatErrorTitle', { + defaultMessage: 'Invalid interval string format.', + }) + ); }; diff --git a/x-pack/plugins/infra/server/lib/sources.ts b/x-pack/plugins/infra/server/lib/sources.ts index 4bf9ce6c61f0e..b1460b277b08d 100644 --- a/x-pack/plugins/infra/server/lib/sources.ts +++ b/x-pack/plugins/infra/server/lib/sources.ts @@ -3,6 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; export class InfraSources { constructor(private readonly adapter: InfraSourcesAdapter) {} @@ -12,7 +13,14 @@ export class InfraSources { const requestedSourceConfiguration = sourceConfigurations[sourceId]; if (!requestedSourceConfiguration) { - throw new Error(`Failed to find source '${sourceId}'`); + throw new Error( + i18n.translate('xpack.infra.infraSources.failedToFindSourceErrorTitle', { + defaultMessage: 'Failed to find source {sourceId}', + values: { + sourceId: "'" + sourceId + "'", + }, + }) + ); } return requestedSourceConfiguration; diff --git a/x-pack/plugins/infra/server/utils/serialized_query.ts b/x-pack/plugins/infra/server/utils/serialized_query.ts index 932df847e65d0..76dd9dc941c92 100644 --- a/x-pack/plugins/infra/server/utils/serialized_query.ts +++ b/x-pack/plugins/infra/server/utils/serialized_query.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { UserInputError } from 'apollo-server-errors'; import { JsonObject } from '../../common/typed_json'; @@ -19,16 +20,28 @@ export const parseFilterQuery = ( ['string', 'number', 'boolean'].includes(typeof parsedFilterQuery) || Array.isArray(parsedFilterQuery) ) { - throw new Error('expected value to be an object'); + throw new Error( + i18n.translate('xpack.infra.parseFilterQuery.needValueAsObjectErrorTitle', { + defaultMessage: 'expected value to be an object', + }) + ); } return parsedFilterQuery; } else { return undefined; } } catch (err) { - throw new UserInputError(`Failed to parse query: ${err}`, { - query: filterQuery, - originalError: err, - }); + throw new UserInputError( + i18n.translate('xpack.infra.parseFilterQuery.failedToParseQueryErrorTitle', { + defaultMessage: 'Failed to parse query: {err}', + values: { + err, + }, + }), + { + query: filterQuery, + originalError: err, + } + ); } }; From e0fc4426eeb2648cc23fcc291d987e793eb9dfb6 Mon Sep 17 00:00:00 2001 From: tibmt Date: Fri, 9 Nov 2018 17:41:40 +0300 Subject: [PATCH 2/6] update translation of Infra Ops vizualization component (Part 4) --- .i18nrc.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.i18nrc.json b/.i18nrc.json index de532fdb60984..c55d4a809d0e5 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -15,6 +15,7 @@ "tagCloud": "src/core_plugins/tagcloud", "xpack.grokDebugger": "x-pack/plugins/grokdebugger", "xpack.idxMgmt": "x-pack/plugins/index_management", + "xpack.infra": "x-pack/plugins/infra", "xpack.licenseMgmt": "x-pack/plugins/license_management", "xpack.rollupJobs": "x-pack/plugins/rollup", "xpack.searchProfiler": "x-pack/plugins/searchprofiler", @@ -25,6 +26,8 @@ "src/ui/ui_render/bootstrap/app_bootstrap.js", "src/ui/ui_render/ui_render_mixin.js", "x-pack/plugins/monitoring/public/components/cluster/overview/alerts_panel.js", - "x-pack/plugins/monitoring/public/directives/alerts/index.js" + "x-pack/plugins/monitoring/public/directives/alerts/index.js", + "x-pack/plugins/infra/public/utils/loading_state/loading_result.ts", + "x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts" ] } From 94010dc2ab8759048d63f05c3e19a417e59b986f Mon Sep 17 00:00:00 2001 From: tibmt Date: Tue, 13 Nov 2018 12:09:39 +0300 Subject: [PATCH 3/6] remove unnessesary translations --- .../kibana_configuration_adapter.ts | 17 ++---------- .../adapters/framework/apollo_server_hapi.ts | 13 ++------- .../framework/kibana_framework_adapter.ts | 7 +---- .../extract_group_by_and_node_from_path.ts | 27 +++---------------- .../adapters/nodes/lib/create_node_item.ts | 7 +---- .../nodes/lib/get_bucket_size_in_seconds.ts | 8 +----- x-pack/plugins/infra/server/lib/sources.ts | 2 +- .../infra/server/utils/serialized_query.ts | 23 ++++------------ 8 files changed, 16 insertions(+), 88 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts index 014fbccf31e12..62b01b3eac2a3 100644 --- a/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/configuration/kibana_configuration_adapter.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import Joi from 'joi'; import { InfraConfigurationAdapter } from './adapter_types'; @@ -15,15 +14,7 @@ export class InfraKibanaConfigurationAdapter constructor(server: any) { if (!isServerWithConfig(server)) { - throw new Error( - i18n.translate( - 'xpack.infra.infraKibanaConfigurationAdapter.failedToFindConfigurationErrorTitle', - { - defaultMessage: 'Failed to find configuration on server.', - } - ) - ); - throw new Error(''); + throw new Error('Failed to find configuration on server.'); } this.server = server; @@ -33,11 +24,7 @@ export class InfraKibanaConfigurationAdapter const config = this.server.config(); if (!isKibanaConfiguration(config)) { - throw new Error( - i18n.translate('xpack.infra.infraKibanaConfigurationAdapter.failedToAccessErrorTitle', { - defaultMessage: 'Failed to access configuration of server.', - }) - ); + throw new Error('Failed to access configuration of server.'); } const configuration = config.get('xpack.infra') || {}; diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts b/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts index 912b879ad4167..da858217468f1 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/apollo_server_hapi.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import * as GraphiQL from 'apollo-server-module-graphiql'; import Boom from 'boom'; import { Plugin, Request, ResponseToolkit, RouteOptions, Server } from 'hapi'; @@ -24,11 +23,7 @@ export const graphqlHapi: Plugin = { name: 'graphql', register: (server: Server, options: HapiGraphQLPluginOptions) => { if (!options || !options.graphqlOptions) { - throw new Error( - i18n.translate('xpack.infra.graphqlHapi.apolloServerRequiresOptionsErrorTitle', { - defaultMessage: 'Apollo Server requires options.', - }) - ); + throw new Error('Apollo Server requires options.'); } server.route({ @@ -101,11 +96,7 @@ export const graphiqlHapi: Plugin = { name: 'graphiql', register: (server: Server, options: HapiGraphiQLPluginOptions) => { if (!options || !options.graphiqlOptions) { - throw new Error( - i18n.translate('xpack.infra.graphqlHapi.apolloServerGraphiQLRequiresOptionsErrorTitle', { - defaultMessage: 'Apollo Server GraphiQL requires options.', - }) - ); + throw new Error('Apollo Server GraphiQL requires options.'); } server.route({ diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts index 9b3546449fbb0..034ce7f66a768 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import { GraphQLSchema } from 'graphql'; import { Request, ResponseToolkit, Server } from 'hapi'; @@ -104,11 +103,7 @@ export class InfraKibanaBackendFrameworkAdapter implements InfraBackendFramework request: InfraFrameworkRequest ): InfraFrameworkIndexPatternsService { if (!isServerWithIndexPatternsServiceFactory(this.server)) { - throw new Error( - i18n.translate('xpack.infra.infraKibanaBackendFrameworkAdapter.failedToAccessErrorTitle', { - defaultMessage: 'Failed to access indexPatternsService for the request', - }) - ); + throw new Error('Failed to access indexPatternsService for the request'); } return this.server.indexPatternsServiceFactory({ callCluster: async (method: string, args: [object], ...rest: any[]) => { diff --git a/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts b/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts index a89de3ad0cc6a..60fa22b4116e4 100644 --- a/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts +++ b/x-pack/plugins/infra/server/lib/adapters/nodes/extract_group_by_and_node_from_path.ts @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import { InfraPathInput, InfraPathType } from '../../../../common/graphql/types'; import { InfraNodeType } from './adapter_types'; @@ -40,35 +39,15 @@ const moreThenOneEntityType = (path: InfraPathInput[]) => { export function extractGroupByAndNodeFromPath(path: InfraPathInput[]) { if (moreThenOneEntityType(path)) { - throw new Error( - i18n.translate( - 'xpack.infra.extractGroupByAndNodeFromPath.onlyOneEntityTypeInThePathErrorTitle', - { - defaultMessage: 'There can be only one entity type in the path.', - } - ) - ); + throw new Error('There can be only one entity type in the path.'); } if (path.length > 3) { - throw new Error( - i18n.translate( - 'xpack.infra.extractGroupByAndNodeFromPath.maxThreeElementsInThePathErrorTitle', - { - defaultMessage: 'The path can only have a maximum of 3 elements.', - } - ) - ); + throw new Error('The path can only have a maximum of 3 elements.'); } const nodePart = path[path.length - 1]; if (!isEntityType(nodePart)) { throw new Error( - i18n.translate( - 'xpack.infra.extractGroupByAndNodeFromPath.lastElementInPathContainErrorTitle', - { - defaultMessage: - 'The last element in the path should be either a "hosts", "containers" or "pods" path type.', - } - ) + 'The last element in the path should be either a "hosts", "containers" or "pods" path type.' ); } const nodeType = getNodeType(nodePart.type); diff --git a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts index 24646d88576a1..a2d072e0897d7 100644 --- a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts +++ b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/create_node_item.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import { last } from 'lodash'; import { isNumber } from 'lodash'; import moment from 'moment'; @@ -42,11 +41,7 @@ function createNodeMetrics( const bucketSize = getBucketSizeInSeconds(timerange.interval); const lastBucket = findLastFullBucket(bucket, bucketSize, options); if (!lastBucket) { - throw new Error( - i18n.translate('xpack.infra.createNodeMetrics.emptySetOfBucketsInDateHistogramErrorTitle', { - defaultMessage: 'Date histogram returned an empty set of buckets.', - }) - ); + throw new Error('Date histogram returned an empty set of buckets.'); } const metricObj = lastBucket[metric.type]; const value = (metricObj && (metricObj.normalized_value || metricObj.value)) || 0; diff --git a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts index 8c6c2f5e323f8..667f2d2f35745 100644 --- a/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts +++ b/x-pack/plugins/infra/server/lib/adapters/nodes/lib/get_bucket_size_in_seconds.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; - const intervalUnits = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms']; const INTERVAL_STRING_RE = new RegExp('^([0-9\\.]*)\\s*(' + intervalUnits.join('|') + ')$'); @@ -29,9 +27,5 @@ export const getBucketSizeInSeconds = (interval: string): number => { if (matches) { return parseFloat(matches[1]) * units[matches[2]]; } - throw new Error( - i18n.translate('xpack.infra.getBucketSizeInSeconds.invalidInternalStringFormatErrorTitle', { - defaultMessage: 'Invalid interval string format.', - }) - ); + throw new Error('Invalid interval string format.'); }; diff --git a/x-pack/plugins/infra/server/lib/sources.ts b/x-pack/plugins/infra/server/lib/sources.ts index b1460b277b08d..a13a6ce43cc98 100644 --- a/x-pack/plugins/infra/server/lib/sources.ts +++ b/x-pack/plugins/infra/server/lib/sources.ts @@ -17,7 +17,7 @@ export class InfraSources { i18n.translate('xpack.infra.infraSources.failedToFindSourceErrorTitle', { defaultMessage: 'Failed to find source {sourceId}', values: { - sourceId: "'" + sourceId + "'", + sourceId: `'${sourceId}'`, }, }) ); diff --git a/x-pack/plugins/infra/server/utils/serialized_query.ts b/x-pack/plugins/infra/server/utils/serialized_query.ts index 76dd9dc941c92..932df847e65d0 100644 --- a/x-pack/plugins/infra/server/utils/serialized_query.ts +++ b/x-pack/plugins/infra/server/utils/serialized_query.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import { UserInputError } from 'apollo-server-errors'; import { JsonObject } from '../../common/typed_json'; @@ -20,28 +19,16 @@ export const parseFilterQuery = ( ['string', 'number', 'boolean'].includes(typeof parsedFilterQuery) || Array.isArray(parsedFilterQuery) ) { - throw new Error( - i18n.translate('xpack.infra.parseFilterQuery.needValueAsObjectErrorTitle', { - defaultMessage: 'expected value to be an object', - }) - ); + throw new Error('expected value to be an object'); } return parsedFilterQuery; } else { return undefined; } } catch (err) { - throw new UserInputError( - i18n.translate('xpack.infra.parseFilterQuery.failedToParseQueryErrorTitle', { - defaultMessage: 'Failed to parse query: {err}', - values: { - err, - }, - }), - { - query: filterQuery, - originalError: err, - } - ); + throw new UserInputError(`Failed to parse query: ${err}`, { + query: filterQuery, + originalError: err, + }); } }; From b39205c2fc46a962aa47d05b348d65456b1a7636 Mon Sep 17 00:00:00 2001 From: tibmt Date: Tue, 13 Nov 2018 14:24:24 +0300 Subject: [PATCH 4/6] change some ids --- .../server/lib/adapters/metrics/kibana_metrics_adapter.ts | 4 ++-- x-pack/plugins/infra/server/lib/sources.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index 2d312c3723b33..8c78ad65f7fc8 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -46,7 +46,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { const validNode = await checkValidNode(search, indexPattern, nodeField, options.nodeId); if (!validNode) { throw new Error( - i18n.translate('xpack.infra.kibanaMetricsAdapter.idDoesNotExistErrorTitle', { + i18n.translate('xpack.infra.kibanaMetrics.nodeDoesNotExistErrorMessage', { defaultMessage: '{nodeId} does not exist.', values: { nodeId: options.nodeId, @@ -68,7 +68,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { const infraMetricId: InfraMetric = (InfraMetric as any)[id]; if (!infraMetricId) { throw new Error( - i18n.translate('xpack.infra.kibanaMetricsAdapter.noValidInfraMetricIdErrorTitle', { + i18n.translate('xpack.infra.kibanaMetrics.nodeDoesNotExistErrorMessage', { defaultMessage: '{id} is not a valid InfraMetric', values: { id, diff --git a/x-pack/plugins/infra/server/lib/sources.ts b/x-pack/plugins/infra/server/lib/sources.ts index a13a6ce43cc98..43f066c9e3f30 100644 --- a/x-pack/plugins/infra/server/lib/sources.ts +++ b/x-pack/plugins/infra/server/lib/sources.ts @@ -14,7 +14,7 @@ export class InfraSources { if (!requestedSourceConfiguration) { throw new Error( - i18n.translate('xpack.infra.infraSources.failedToFindSourceErrorTitle', { + i18n.translate('xpack.infra.infraSources.failedToFindSourceErrorMessage', { defaultMessage: 'Failed to find source {sourceId}', values: { sourceId: `'${sourceId}'`, From 6b95273a0031936b7da9adc5058b3e95e234f4e4 Mon Sep 17 00:00:00 2001 From: tibmt Date: Tue, 13 Nov 2018 14:47:28 +0300 Subject: [PATCH 5/6] change some ids --- .../infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index 8c78ad65f7fc8..d6f6d386e38bc 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -68,7 +68,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { const infraMetricId: InfraMetric = (InfraMetric as any)[id]; if (!infraMetricId) { throw new Error( - i18n.translate('xpack.infra.kibanaMetrics.nodeDoesNotExistErrorMessage', { + i18n.translate('xpack.infra.kibanaMetrics.notValidInfraMetricErrorMessage', { defaultMessage: '{id} is not a valid InfraMetric', values: { id, From 86d44c70b7dce11999f775eff954fd9bd1cabbff Mon Sep 17 00:00:00 2001 From: tibmt Date: Thu, 22 Nov 2018 14:41:08 +0300 Subject: [PATCH 6/6] change one id --- .../infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index d6f6d386e38bc..3c596695e24fa 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -68,7 +68,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { const infraMetricId: InfraMetric = (InfraMetric as any)[id]; if (!infraMetricId) { throw new Error( - i18n.translate('xpack.infra.kibanaMetrics.notValidInfraMetricErrorMessage', { + i18n.translate('xpack.infra.kibanaMetrics.invalidInfraMetricErrorMessage', { defaultMessage: '{id} is not a valid InfraMetric', values: { id,