From 3a396027f669803e1a3143237578973fb1ab20d0 Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Fri, 20 Mar 2020 14:02:15 -0400 Subject: [PATCH] [Monitoring] Migrate server to NP (#56675) * First pass * First pass * Add new routes * Getting closer * Remove legacy server code, and other fixes * Register the plugin with xpack * Pass a legacy client to telemetry * Suport callWithInternalUser * Remove this * More NP work * Fix some tests * Fix broken test * Move over new telemetry changes, and fix other issues * Fix TODO item * Reuse the same schema as elasticsearch module * Use a singular config definition here * Disable this for now * Use the right method * Use custom config again * Tweak the config to make this optional * Remove these * Remove these unnecessary files * Fix jest test * Fix some linting issues * Fix type issue * Fix localization issues * Use the elasticsearch config * Remove todos * Fix this check * Move kibana alerting over * PR feedback * Use new metrics core service * Change config for xpack_api_polling_frequency_millis * Make sure this is disabled for now * Disable both * Update this to the new function * Tighten up legacy api needs * Check for existence * Fix jest tests * Cleaning up the plugin definition * Create custom type in our plugin * Revert this change * Fix CI issues * Add these tests back * Just use a different collector type * Handle errors better * Use custom type * PR feedback * Fix type issues * PR feedback --- .../telemetry/server/collection_manager.ts | 12 +- src/legacy/server/status/constants.js | 2 +- x-pack/.i18nrc.json | 2 +- x-pack/legacy/plugins/monitoring/config.js | 8 +- x-pack/legacy/plugins/monitoring/index.js | 59 +++ x-pack/legacy/plugins/monitoring/index.ts | 141 ------- .../public/views/cluster/listing/index.js | 1 + .../server/__tests__/check_license.js | 87 ---- .../es_client/__tests__/fixture_read_file.txt | 1 - .../es_client/__tests__/instantiate_client.js | 145 ------- .../parse_elasticsearch_config.test.mocks.ts | 15 - .../parse_elasticsearch_config.test.ts | 181 --------- .../es_client/parse_elasticsearch_config.ts | 114 ------ .../server/init_monitoring_xpack_info.js | 44 -- .../collectors/get_ops_stats_collector.js | 95 ----- .../ops_buffer/__tests__/event_roller.js | 124 ------ .../ops_buffer/__tests__/map_requests.js | 43 -- .../__tests__/map_response_times.js | 57 --- .../collectors/ops_buffer/event_roller.js | 87 ---- .../collectors/ops_buffer/map_requests.js | 19 - .../ops_buffer/map_response_times.js | 25 -- .../collectors/ops_buffer/ops_buffer.js | 55 --- .../lib/get_kibana_info_for_stats.js | 33 -- .../shards/__tests__/fixtures/index.js | 10 - .../plugins/monitoring/server/plugin.js | 189 --------- .../register_monitoring_collection.ts | 21 - .../server/routes/api/v1/settings.js | 22 +- x-pack/plugins/infra/server/index.ts | 4 +- .../__tests__/format_timestamp_to_duration.js | 128 ++++++ .../monitoring/common/cancel_promise.ts | 70 ++++ x-pack/plugins/monitoring/common/constants.ts | 264 ++++++++++++ .../common/format_timestamp_to_duration.js | 54 +++ .../plugins/monitoring/common/formatting.js | 33 ++ .../monitoring/common}/index.js | 2 +- x-pack/plugins/monitoring/kibana.json | 10 + .../server}/__tests__/deprecations.js | 37 +- .../server/alerts/license_expiration.test.ts | 85 ++-- .../server/alerts/license_expiration.ts | 18 +- .../monitoring/server/alerts/types.d.ts | 2 +- .../monitoring/server/cloud/__tests__/aws.js | 0 .../server/cloud/__tests__/azure.js | 0 .../server/cloud/__tests__/cloud_detector.js | 0 .../server/cloud/__tests__/cloud_response.js | 0 .../server/cloud/__tests__/cloud_service.js | 0 .../server/cloud/__tests__/cloud_services.js | 0 .../monitoring/server/cloud/__tests__/gcp.js | 0 .../plugins/monitoring/server/cloud/aws.js | 0 .../plugins/monitoring/server/cloud/azure.js | 0 .../monitoring/server/cloud/cloud_detector.js | 0 .../monitoring/server/cloud/cloud_response.js | 0 .../monitoring/server/cloud/cloud_service.js | 0 .../monitoring/server/cloud/cloud_services.js | 0 .../plugins/monitoring/server/cloud/gcp.js | 0 .../plugins/monitoring/server/cloud/index.js | 0 .../__tests__/alerts_cluster_search.js | 1 + .../__tests__/alerts_clusters_aggregation.js | 0 .../cluster_alerts/__tests__/check_license.js | 0 .../__tests__/fixtures/create_stubs.js | 27 +- .../__tests__/verify_monitoring_license.js | 0 .../cluster_alerts/alerts_cluster_search.js | 0 .../alerts_clusters_aggregation.js | 0 .../server/cluster_alerts/check_license.js | 0 .../verify_monitoring_license.js | 7 +- x-pack/plugins/monitoring/server/config.ts | 230 +++++++++++ .../monitoring/server/deprecations.ts} | 49 +-- .../monitoring/server/es_client/README.md | 0 .../es_client/__tests__/instantiate_client.js | 125 ++++++ .../server/es_client/instantiate_client.ts} | 25 +- x-pack/plugins/monitoring/server/index.ts | 17 + .../__tests__/bulk_uploader.js | 0 .../server/kibana_monitoring/bulk_uploader.js | 63 ++- .../__tests__/check_for_email_value.js | 0 .../__tests__/get_default_admin_email.js | 0 .../collectors/get_kibana_usage_collector.ts} | 16 +- .../collectors/get_ops_stats_collector.ts | 37 ++ .../collectors/get_settings_collector.ts} | 27 +- .../kibana_monitoring/collectors/index.ts} | 17 +- .../server/kibana_monitoring/index.js | 0 .../server/kibana_monitoring/init.js | 2 +- .../server/kibana_monitoring/lib/index.js | 1 - .../kibana_monitoring/lib/monitoring_bulk.js | 0 .../lib/send_bulk_payload.js | 4 +- .../server/lib/__tests__/calculate_auto.js | 0 .../lib/__tests__/calculate_availabiilty.js | 0 .../lib/__tests__/calculate_overall_status.js | 0 .../server/lib/__tests__/calculate_rate.js | 0 .../calculate_timeseries_interval.js | 0 .../server/lib/__tests__/ccs_utils.js | 19 +- .../server/lib/__tests__/create_query.js | 0 .../server/lib/__tests__/helpers.js | 0 .../lib/__tests__/process_version_string.js | 0 .../lib/alerts/fetch_available_ccs.test.ts | 0 .../server/lib/alerts/fetch_available_ccs.ts | 0 .../server/lib/alerts/fetch_clusters.test.ts | 0 .../server/lib/alerts/fetch_clusters.ts | 0 .../fetch_default_email_address.test.ts | 2 +- .../lib/alerts/fetch_default_email_address.ts | 0 .../server/lib/alerts/fetch_licenses.test.ts | 0 .../server/lib/alerts/fetch_licenses.ts | 0 .../server/lib/alerts/fetch_status.ts | 0 .../lib/alerts/get_ccs_index_pattern.test.ts | 0 .../lib/alerts/get_ccs_index_pattern.ts | 0 .../lib/alerts/license_expiration.lib.test.ts | 0 .../lib/alerts/license_expiration.lib.ts | 2 +- .../server/lib/apm/__tests__/get_apms.js | 0 .../monitoring/server/lib/apm/_apm_stats.js | 0 .../server/lib/apm/_get_time_of_last_event.js | 0 .../server/lib/apm/create_apm_query.js | 0 .../monitoring/server/lib/apm/get_apm_info.js | 0 .../monitoring/server/lib/apm/get_apms.js | 0 .../server/lib/apm/get_apms_for_clusters.js | 0 .../monitoring/server/lib/apm/get_stats.js | 0 .../monitoring/server/lib/apm/index.js | 0 .../lib/beats/__tests__/create_beats_query.js | 0 .../fixtures/get_listing_response.js | 178 +++++---- .../lib/beats/__tests__/get_beat_summary.js | 0 .../server/lib/beats/__tests__/get_beats.js | 0 .../beats/__tests__/get_beats_for_clusters.js | 0 .../lib/beats/__tests__/get_latest_stats.js | 0 .../server/lib/beats/__tests__/get_stats.js | 0 .../server/lib/beats/_beats_stats.js | 0 .../server/lib/beats/create_beats_query.js | 0 .../server/lib/beats/get_beat_summary.js | 0 .../monitoring/server/lib/beats/get_beats.js | 0 .../lib/beats/get_beats_for_clusters.js | 0 .../server/lib/beats/get_latest_stats.js | 0 .../monitoring/server/lib/beats/get_stats.js | 0 .../monitoring/server/lib/beats/index.js | 0 .../monitoring/server/lib/calculate_auto.js | 0 .../server/lib/calculate_availability.js | 0 .../server/lib/calculate_overall_status.js | 0 .../monitoring/server/lib/calculate_rate.js | 0 .../lib/calculate_timeseries_interval.js | 0 .../monitoring/server/lib/ccs_utils.js | 10 +- .../get_clusters_summary.test.js.snap | 0 .../cluster/__test__/fixtures/clusters.json | 0 .../__test__/get_clusters_summary.test.js | 0 .../__tests__/flag_supported_clusters.js | 0 .../cluster/__tests__/get_cluster_status.js | 0 .../cluster/__tests__/get_clusters_state.js | 0 .../cluster/__tests__/get_clusters_stats.js | 0 .../lib/cluster/flag_supported_clusters.js | 4 +- .../server/lib/cluster/get_cluster_license.js | 0 .../server/lib/cluster/get_cluster_stats.js | 0 .../server/lib/cluster/get_cluster_status.js | 0 .../lib/cluster/get_clusters_from_request.js | 0 .../server/lib/cluster/get_clusters_state.js | 0 .../server/lib/cluster/get_clusters_stats.js | 0 .../lib/cluster/get_clusters_summary.js | 0 .../server/lib/cluster/get_index_patterns.js | 0 .../server/lib/cluster/is_in_code_path.js | 0 .../monitoring/server/lib/create_query.js | 0 .../__snapshots__/get_metrics.test.js.snap | 0 .../fixtures/agg_metrics_buckets.json | 0 .../fixtures/deriv_metrics_buckets.json | 0 .../fixtures/non_deriv_metrics_buckets.json | 0 .../lib/details/__test__/get_metrics.test.js | 0 .../server/lib/details/get_metrics.js | 0 .../server/lib/details/get_series.js | 0 .../__tests__/get_last_recovery.js | 0 .../elasticsearch/__tests__/get_ml_jobs.js | 0 .../server/lib/elasticsearch/ccr.js | 0 .../lib/elasticsearch/convert_metric_names.js | 0 .../lib/elasticsearch/get_last_recovery.js | 4 +- .../server/lib/elasticsearch/get_ml_jobs.js | 0 .../server/lib/elasticsearch/index.js | 0 .../indices/__tests__/get_index_summary.js | 0 .../indices/__tests__/get_indices.js | 0 .../indices/get_index_summary.js | 0 .../lib/elasticsearch/indices/get_indices.js | 0 .../server/lib/elasticsearch/indices/index.js | 0 .../nodes/__tests__/calculate_node_type.js | 0 .../nodes/__tests__/get_node_summary.js | 0 .../__tests__/get_node_type_class_label.js | 0 .../elasticsearch/nodes/__tests__/lookups.js | 0 .../nodes/calculate_node_type.js | 0 .../nodes/get_default_node_from_id.js | 0 .../elasticsearch/nodes/get_node_summary.js | 0 .../nodes/get_node_type_class_label.js | 0 .../get_metric_aggs.test.js.snap | 0 .../handle_response.test.js.snap | 0 .../__snapshots__/map_nodes_info.test.js.snap | 0 .../map_nodes_metrics.test.js.snap | 0 .../__test__/fixtures/cluster_data.json | 0 .../__test__/get_metric_aggs.test.js | 0 .../get_nodes/__test__/get_node_ids.test.js | 2 +- .../__test__/get_paginated_nodes.test.js | 0 .../__test__/handle_response.test.js | 0 .../get_nodes/__test__/map_nodes_info.test.js | 0 .../__test__/map_nodes_metrics.test.js | 0 .../nodes/get_nodes/get_live_nodes.js | 0 .../nodes/get_nodes/get_metric_aggs.js | 0 .../nodes/get_nodes/get_node_ids.js | 0 .../nodes/get_nodes/get_nodes.js | 0 .../nodes/get_nodes/get_paginated_nodes.js | 0 .../nodes/get_nodes/handle_response.js | 0 .../elasticsearch/nodes/get_nodes/index.js | 0 .../nodes/get_nodes/map_nodes_info.js | 0 .../nodes/get_nodes/map_nodes_metrics.js | 0 .../nodes/get_nodes/nodes_listing_metrics.js | 0 .../nodes/get_nodes/sort_nodes.js | 2 +- .../server/lib/elasticsearch/nodes/index.js | 0 .../server/lib/elasticsearch/nodes/lookups.js | 0 .../shards/__tests__/fixtures/cluster.json | 0 .../shards/__tests__/fixtures/index.js | 10 + .../__tests__/fixtures/shard_stats.json | 0 .../shards/__tests__/get_shard_stats.js | 0 .../__tests__/normalize_shard_objects.js | 0 .../calculate_shard_stat_indices_totals.js | 0 .../get_indices_unassigned_shard_stats.js | 0 ...get_indices_unassigned_shard_stats.test.js | 0 .../shards/get_nodes_shard_count.js | 0 .../shards/get_nodes_shard_count.test.js | 0 .../shards/get_shard_allocation.js | 0 .../shards/get_shard_allocation.test.js | 0 .../shards/get_shard_stat_aggs.js | 0 .../elasticsearch/shards/get_shard_stats.js | 0 .../shards/get_unassigned_shards.js | 0 .../server/lib/elasticsearch/shards/index.js | 0 .../shards/normalize_shard_objects.js | 0 .../elasticsearch/verify_ccs_availability.js | 0 .../elasticsearch/verify_monitoring_auth.js | 4 +- .../__tests__/cluster.js | 0 .../__tests__/find_reason.js | 0 .../elasticsearch_settings/__tests__/nodes.js | 0 .../lib/elasticsearch_settings/cluster.js | 0 .../lib/elasticsearch_settings/find_reason.js | 0 .../lib/elasticsearch_settings/index.js | 0 .../lib/elasticsearch_settings/nodes.js | 0 .../set/collection_disabled.js | 0 .../set/collection_enabled.js | 0 .../set/collection_interval.js | 0 .../server/lib/error_missing_required.js | 0 .../lib/errors/__tests__/auth_errors.js | 0 .../lib/errors/__tests__/known_errors.js | 0 .../server/lib/errors/auth_errors.js | 0 .../server/lib/errors/custom_errors.js | 0 .../server/lib/errors/handle_error.js | 3 +- .../lib/errors/handle_settings_error.js | 0 .../monitoring/server/lib/errors/index.js | 0 .../server/lib/errors/known_errors.js | 0 .../server/lib/filter_partial_buckets.js | 0 .../monitoring/server/lib/format_timezone.js | 0 .../monitoring/server/lib/get_timezone.js | 0 .../lib/kibana/__tests__/get_kibana_info.js | 0 .../server/lib/kibana/get_kibana_info.js | 0 .../server/lib/kibana/get_kibanas.js | 0 .../lib/kibana/get_kibanas_for_clusters.js | 0 .../monitoring/server/lib/kibana/index.js | 0 .../server/lib/logs/detect_reason.js | 0 .../lib/logs/detect_reason_from_exception.js | 0 .../server/lib/logs/get_log_types.js | 0 .../monitoring/server/lib/logs/get_logs.js | 0 .../monitoring/server/lib/logs/index.js | 0 .../server/lib/logs/init_infra_source.ts} | 11 +- .../lib/logstash/__tests__/get_node_info.js | 0 .../lib/logstash/__tests__/get_pipeline.js | 0 .../server/lib/logstash/get_cluster_status.js | 0 .../lib/logstash/get_logstash_for_clusters.js | 0 .../server/lib/logstash/get_node_info.js | 0 .../server/lib/logstash/get_nodes.js | 0 .../lib/logstash/get_paginated_pipelines.js | 0 .../server/lib/logstash/get_pipeline.js | 0 .../server/lib/logstash/get_pipeline_ids.js | 0 .../logstash/get_pipeline_state_document.js | 0 .../get_pipeline_stats_aggregation.js | 0 .../lib/logstash/get_pipeline_versions.js | 0 .../lib/logstash/get_pipeline_vertex.js | 0 .../get_pipeline_vertex_stats_aggregation.js | 0 .../monitoring/server/lib/logstash/index.js | 0 .../server/lib/logstash/sort_pipelines.js | 0 .../__snapshots__/metrics.test.js.snap | 0 .../lib/metrics/__test__/metrics.test.js | 0 .../server/lib/metrics/apm/classes.js | 0 .../server/lib/metrics/apm/metrics.js | 0 .../cpu_utilization_calculation.test.js | 0 .../server/lib/metrics/beats/classes.js | 0 .../server/lib/metrics/beats/metrics.js | 0 .../latency_metric_calculation.test.js | 0 .../__test__/quota_metric_calculation.test.js | 0 .../lib/metrics/classes/cluster_metric.js | 0 .../server/lib/metrics/classes/index.js | 0 .../server/lib/metrics/classes/metric.js | 0 .../lib/metrics/classes/quota_metric.js | 0 .../__test__/latency_calculation.test.js | 0 .../lib/metrics/elasticsearch/classes.js | 0 .../lib/metrics/elasticsearch/metrics.js | 0 .../monitoring/server/lib/metrics/index.js | 0 .../server/lib/metrics/kibana/classes.js | 0 .../server/lib/metrics/kibana/metrics.js | 0 .../server/lib/metrics/logstash/classes.js | 0 .../server/lib/metrics/logstash/metrics.js | 0 .../monitoring/server/lib/metrics/metrics.js | 0 .../server/lib/normalize_version_string.js | 0 .../server/lib/pagination/filter.js | 0 .../server/lib/pagination/paginate.js | 0 .../__test__/get_collection_status.test.js | 0 .../setup/collection/get_collection_status.js | 8 +- .../server/lib/setup/collection/index.js | 0 .../get_standalone_cluster_definition.js | 0 .../has_standalone_clusters.js | 0 .../server/lib/standalone_clusters/index.js | 0 .../standalone_cluster_query_filter.js | 0 .../monitoring/server/license_service.ts | 59 +++ x-pack/plugins/monitoring/server/plugin.ts | 378 ++++++++++++++++++ .../server/routes/api/v1/alerts/alerts.js | 8 +- .../server/routes/api/v1/alerts/index.js | 0 .../routes/api/v1/alerts/legacy_alerts.js | 18 +- .../api/v1/apm/_get_apm_cluster_status.js | 0 .../server/routes/api/v1/apm/index.js | 0 .../server/routes/api/v1/apm/instance.js | 20 +- .../server/routes/api/v1/apm/instances.js | 18 +- .../routes/api/v1/apm/metric_set_instance.js | 0 .../routes/api/v1/apm/metric_set_overview.js | 0 .../server/routes/api/v1/apm/overview.js | 18 +- .../server/routes/api/v1/beats/beat_detail.js | 20 +- .../server/routes/api/v1/beats/beats.js | 18 +- .../server/routes/api/v1/beats/index.js | 0 .../routes/api/v1/beats/metric_set_detail.js | 0 .../api/v1/beats/metric_set_overview.js | 0 .../server/routes/api/v1/beats/overview.js | 18 +- .../api/v1/check_access/check_access.js | 0 .../routes/api/v1/check_access/index.js | 0 .../server/routes/api/v1/cluster/cluster.js | 24 +- .../server/routes/api/v1/cluster/clusters.js | 18 +- .../server/routes/api/v1/cluster/index.js | 0 .../server/routes/api/v1/elasticsearch/ccr.js | 18 +- .../routes/api/v1/elasticsearch/ccr_shard.js | 22 +- .../routes/api/v1/elasticsearch/index.js | 0 .../api/v1/elasticsearch/index_detail.js | 24 +- .../routes/api/v1/elasticsearch/indices.js | 22 +- .../elasticsearch/metric_set_index_detail.js | 0 .../elasticsearch/metric_set_node_detail.js | 0 .../v1/elasticsearch/metric_set_overview.js | 0 .../routes/api/v1/elasticsearch/ml_jobs.js | 18 +- .../api/v1/elasticsearch/node_detail.js | 24 +- .../routes/api/v1/elasticsearch/nodes.js | 39 +- .../routes/api/v1/elasticsearch/overview.js | 18 +- .../elasticsearch_settings/check/cluster.js | 0 .../v1/elasticsearch_settings/check/nodes.js | 0 .../api/v1/elasticsearch_settings/index.js | 0 .../set/collection_enabled.js | 0 .../set/collection_interval.js | 0 .../v1/kibana/_get_kibana_cluster_status.js | 0 .../server/routes/api/v1/kibana/index.js | 0 .../server/routes/api/v1/kibana/instance.js | 20 +- .../server/routes/api/v1/kibana/instances.js | 18 +- .../api/v1/kibana/metric_set_instance.js | 0 .../api/v1/kibana/metric_set_overview.js | 0 .../server/routes/api/v1/kibana/overview.js | 18 +- .../server/routes/api/v1/logstash/index.js | 0 .../routes/api/v1/logstash/metric_set_node.js | 0 .../api/v1/logstash/metric_set_overview.js | 0 .../server/routes/api/v1/logstash/node.js | 22 +- .../server/routes/api/v1/logstash/nodes.js | 18 +- .../server/routes/api/v1/logstash/overview.js | 18 +- .../server/routes/api/v1/logstash/pipeline.js | 16 +- .../pipelines/cluster_pipeline_ids.js | 18 +- .../logstash/pipelines/cluster_pipelines.js | 41 +- .../v1/logstash/pipelines/node_pipelines.js | 43 +- .../api/v1/setup/cluster_setup_status.js | 26 +- ...sable_elasticsearch_internal_collection.js | 6 +- .../server/routes/api/v1/setup/index.js | 0 .../routes/api/v1/setup/node_setup_status.js | 28 +- .../monitoring/server/routes/api/v1/ui.js | 0 .../plugins/monitoring/server/routes/index.js | 0 .../fixtures/beats_stats_results.json | 0 .../telemetry_collection/create_query.test.ts | 0 .../telemetry_collection/create_query.ts | 0 .../get_all_stats.test.ts | 0 .../telemetry_collection/get_all_stats.ts | 0 .../get_beats_stats.test.ts | 0 .../telemetry_collection/get_beats_stats.ts | 0 .../get_cluster_uuids.test.ts | 0 .../telemetry_collection/get_cluster_uuids.ts | 4 +- .../telemetry_collection/get_es_stats.test.ts | 0 .../telemetry_collection/get_es_stats.ts | 0 .../get_high_level_stats.test.ts | 0 .../get_high_level_stats.ts | 0 .../get_kibana_stats.test.ts | 0 .../telemetry_collection/get_kibana_stats.ts | 0 .../telemetry_collection/get_licenses.test.ts | 0 .../telemetry_collection/get_licenses.ts | 0 .../server/telemetry_collection/index.ts | 0 .../register_monitoring_collection.ts | 33 ++ x-pack/plugins/monitoring/server/types.ts | 21 + .../apis/monitoring/common/mappings_exist.js | 10 +- 387 files changed, 2234 insertions(+), 2134 deletions(-) create mode 100644 x-pack/legacy/plugins/monitoring/index.js delete mode 100644 x-pack/legacy/plugins/monitoring/index.ts delete mode 100644 x-pack/legacy/plugins/monitoring/server/__tests__/check_license.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/es_client/__tests__/fixture_read_file.txt delete mode 100644 x-pack/legacy/plugins/monitoring/server/es_client/__tests__/instantiate_client.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.mocks.ts delete mode 100644 x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.ts delete mode 100644 x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.ts delete mode 100644 x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/event_roller.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_requests.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_response_times.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/event_roller.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_requests.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_response_times.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/ops_buffer.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/get_kibana_info_for_stats.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/plugin.js delete mode 100644 x-pack/legacy/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts create mode 100644 x-pack/plugins/monitoring/common/__tests__/format_timestamp_to_duration.js create mode 100644 x-pack/plugins/monitoring/common/cancel_promise.ts create mode 100644 x-pack/plugins/monitoring/common/constants.ts create mode 100644 x-pack/plugins/monitoring/common/format_timestamp_to_duration.js create mode 100644 x-pack/plugins/monitoring/common/formatting.js rename x-pack/{legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer => plugins/monitoring/common}/index.js (76%) create mode 100644 x-pack/plugins/monitoring/kibana.json rename x-pack/{legacy/plugins/monitoring => plugins/monitoring/server}/__tests__/deprecations.js (75%) rename x-pack/{legacy => }/plugins/monitoring/server/alerts/license_expiration.test.ts (89%) rename x-pack/{legacy => }/plugins/monitoring/server/alerts/license_expiration.ts (91%) rename x-pack/{legacy => }/plugins/monitoring/server/alerts/types.d.ts (92%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/aws.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/azure.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/cloud_detector.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/cloud_response.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/cloud_service.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/cloud_services.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/__tests__/gcp.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/aws.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/azure.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/cloud_detector.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/cloud_response.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/cloud_service.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/cloud_services.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/gcp.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cloud/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js (99%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/__tests__/alerts_clusters_aggregation.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/__tests__/check_license.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js (51%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/__tests__/verify_monitoring_license.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/alerts_cluster_search.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/alerts_clusters_aggregation.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/check_license.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js (88%) create mode 100644 x-pack/plugins/monitoring/server/config.ts rename x-pack/{legacy/plugins/monitoring/deprecations.js => plugins/monitoring/server/deprecations.ts} (54%) rename x-pack/{legacy => }/plugins/monitoring/server/es_client/README.md (100%) create mode 100644 x-pack/plugins/monitoring/server/es_client/__tests__/instantiate_client.js rename x-pack/{legacy/plugins/monitoring/server/es_client/instantiate_client.js => plugins/monitoring/server/es_client/instantiate_client.ts} (60%) create mode 100644 x-pack/plugins/monitoring/server/index.ts rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js (82%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/check_for_email_value.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/get_default_admin_email.js (100%) rename x-pack/{legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.js => plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.ts} (83%) create mode 100644 x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.ts rename x-pack/{legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.js => plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts} (74%) rename x-pack/{legacy/plugins/monitoring/server/kibana_monitoring/collectors/index.js => plugins/monitoring/server/kibana_monitoring/collectors/index.ts} (66%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/init.js (91%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/lib/index.js (83%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/lib/monitoring_bulk.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js (94%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/calculate_auto.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/calculate_availabiilty.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/calculate_overall_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/calculate_rate.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/calculate_timeseries_interval.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/ccs_utils.js (79%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/create_query.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/helpers.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/__tests__/process_version_string.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_available_ccs.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_available_ccs.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_clusters.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_clusters.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts (88%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_default_email_address.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_licenses.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_licenses.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/fetch_status.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/license_expiration.lib.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts (96%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/__tests__/get_apms.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/_apm_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/_get_time_of_last_event.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/create_apm_query.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/get_apm_info.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/get_apms.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/get_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/apm/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js (61%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/get_beat_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/get_beats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/get_beats_for_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/get_latest_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/__tests__/get_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/_beats_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/create_beats_query.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/get_beat_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/get_beats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/get_beats_for_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/get_latest_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/get_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/beats/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/calculate_auto.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/calculate_availability.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/calculate_overall_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/calculate_rate.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/calculate_timeseries_interval.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/ccs_utils.js (88%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__test__/__snapshots__/get_clusters_summary.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__test__/fixtures/clusters.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__test__/get_clusters_summary.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__tests__/flag_supported_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__tests__/get_cluster_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_state.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js (96%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_cluster_license.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_cluster_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_cluster_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_clusters_from_request.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_clusters_state.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_clusters_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_clusters_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/get_index_patterns.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/cluster/is_in_code_path.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/create_query.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/__test__/__snapshots__/get_metrics.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/__test__/fixtures/agg_metrics_buckets.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/__test__/fixtures/deriv_metrics_buckets.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/__test__/fixtures/non_deriv_metrics_buckets.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/__test__/get_metrics.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/get_metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/details/get_series.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/__tests__/get_last_recovery.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/__tests__/get_ml_jobs.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/ccr.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/convert_metric_names.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js (96%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/get_ml_jobs.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_index_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_indices.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/indices/get_index_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/indices/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/calculate_node_type.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_type_class_label.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/lookups.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/calculate_node_type.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_default_node_from_id.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_summary.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_type_class_label.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/get_metric_aggs.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/handle_response.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_info.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_metrics.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/fixtures/cluster_data.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_metric_aggs.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js (93%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_paginated_nodes.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/handle_response.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_info.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_metrics.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_live_nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_metric_aggs.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_node_ids.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_paginated_nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/nodes_listing_metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js (93%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/nodes/lookups.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/cluster.json (100%) create mode 100644 x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/shard_stats.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/get_shard_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/normalize_shard_objects.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/calculate_shard_stat_indices_totals.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stat_aggs.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stats.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/get_unassigned_shards.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/shards/normalize_shard_objects.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/verify_ccs_availability.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js (95%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/cluster.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/find_reason.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/find_reason.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_disabled.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_enabled.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_interval.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/error_missing_required.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/__tests__/auth_errors.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/__tests__/known_errors.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/auth_errors.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/custom_errors.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/handle_error.js (91%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/handle_settings_error.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/errors/known_errors.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/filter_partial_buckets.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/format_timezone.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/get_timezone.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/kibana/__tests__/get_kibana_info.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/kibana/get_kibana_info.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/kibana/get_kibanas.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/kibana/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logs/detect_reason.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logs/get_log_types.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logs/get_logs.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logs/index.js (100%) rename x-pack/{legacy/plugins/monitoring/server/lib/logs/init_infra_source.js => plugins/monitoring/server/lib/logs/init_infra_source.ts} (63%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/__tests__/get_node_info.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/__tests__/get_pipeline.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_cluster_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_node_info.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_paginated_pipelines.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline_ids.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline_stats_aggregation.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline_versions.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline_vertex.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/get_pipeline_vertex_stats_aggregation.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/logstash/sort_pipelines.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/__test__/metrics.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/apm/classes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/apm/metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/beats/__test__/cpu_utilization_calculation.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/beats/classes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/beats/metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/classes/__test__/latency_metric_calculation.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/classes/__test__/quota_metric_calculation.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/classes/cluster_metric.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/classes/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/classes/metric.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/classes/quota_metric.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/elasticsearch/__test__/latency_calculation.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/kibana/classes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/kibana/metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/logstash/classes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/logstash/metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/metrics/metrics.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/normalize_version_string.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/pagination/filter.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/pagination/paginate.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/setup/collection/__test__/get_collection_status.test.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/setup/collection/get_collection_status.js (98%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/setup/collection/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/standalone_clusters/get_standalone_cluster_definition.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/standalone_clusters/has_standalone_clusters.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/standalone_clusters/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/lib/standalone_clusters/standalone_cluster_query_filter.js (100%) create mode 100644 x-pack/plugins/monitoring/server/license_service.ts create mode 100644 x-pack/plugins/monitoring/server/plugin.ts rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/alerts/alerts.js (93%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/alerts/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js (83%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/_get_apm_cluster_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/instance.js (81%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/instances.js (80%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/metric_set_instance.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/metric_set_overview.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/apm/overview.js (81%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js (82%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/beats/beats.js (80%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/beats/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/beats/metric_set_detail.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/beats/metric_set_overview.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/beats/overview.js (82%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/check_access/check_access.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/check_access/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/cluster/cluster.js (77%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/cluster/clusters.js (85%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/cluster/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js (96%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js (90%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js (90%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js (83%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_index_detail.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_node_detail.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_overview.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js (85%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js (89%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js (79%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js (88%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/cluster.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/nodes.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_enabled.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_interval.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/_get_kibana_cluster_status.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/instance.js (82%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/instances.js (82%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/metric_set_instance.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/metric_set_overview.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/kibana/overview.js (82%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/metric_set_node.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/metric_set_overview.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/node.js (85%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/nodes.js (83%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/overview.js (84%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js (88%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js (80%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js (74%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js (73%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js (80%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js (91%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/setup/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js (81%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/api/v1/ui.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/routes/index.js (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/__mocks__/fixtures/beats_stats_results.json (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/create_query.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/create_query.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_all_stats.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_all_stats.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_beats_stats.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts (91%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_es_stats.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_es_stats.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_high_level_stats.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_high_level_stats.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_kibana_stats.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_kibana_stats.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_licenses.test.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/get_licenses.ts (100%) rename x-pack/{legacy => }/plugins/monitoring/server/telemetry_collection/index.ts (100%) create mode 100644 x-pack/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts create mode 100644 x-pack/plugins/monitoring/server/types.ts diff --git a/src/legacy/core_plugins/telemetry/server/collection_manager.ts b/src/legacy/core_plugins/telemetry/server/collection_manager.ts index 715ca56e290a..ebac4bede85b 100644 --- a/src/legacy/core_plugins/telemetry/server/collection_manager.ts +++ b/src/legacy/core_plugins/telemetry/server/collection_manager.ts @@ -20,6 +20,7 @@ import { encryptTelemetry } from './collectors'; import { CallCluster } from '../../elasticsearch'; import { UsageCollectionSetup } from '../../../../plugins/usage_collection/server'; +import { Cluster } from '../../elasticsearch'; import { ESLicense } from './telemetry_collection/get_local_license'; export type EncryptedStatsGetterConfig = { unencrypted: false } & { @@ -70,7 +71,7 @@ export type LicenseGetter = ( interface CollectionConfig { title: string; priority: number; - esCluster: string; + esCluster: string | Cluster; statsGetter: StatsGetter; clusterDetailsGetter: ClusterDetailsGetter; licenseGetter: LicenseGetter; @@ -79,7 +80,7 @@ interface Collection { statsGetter: StatsGetter; licenseGetter: LicenseGetter; clusterDetailsGetter: ClusterDetailsGetter; - esCluster: string; + esCluster: string | Cluster; title: string; } @@ -135,9 +136,10 @@ export class TelemetryCollectionManager { ): Promise => { const { start, end } = config; const server = config.unencrypted ? config.req.server : config.server; - const { callWithRequest, callWithInternalUser } = server.plugins.elasticsearch.getCluster( - collection.esCluster - ); + const { callWithRequest, callWithInternalUser } = + typeof collection.esCluster === 'string' + ? server.plugins.elasticsearch.getCluster(collection.esCluster) + : collection.esCluster; const callCluster = config.unencrypted ? (...args: any[]) => callWithRequest(config.req, ...args) : callWithInternalUser; diff --git a/src/legacy/server/status/constants.js b/src/legacy/server/status/constants.js index d16e46008acc..3bb23749bae8 100644 --- a/src/legacy/server/status/constants.js +++ b/src/legacy/server/status/constants.js @@ -17,4 +17,4 @@ * under the License. */ -export const KIBANA_STATS_TYPE = 'kibana_stats'; // kibana stats per 5s intervals +export const KIBANA_STATS_TYPE = 'oss_kibana_stats'; // kibana stats per 5s intervals diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index d568e9b951d2..a8bb989f6bff 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -28,7 +28,7 @@ "xpack.main": "legacy/plugins/xpack_main", "xpack.maps": ["plugins/maps", "legacy/plugins/maps"], "xpack.ml": ["plugins/ml", "legacy/plugins/ml"], - "xpack.monitoring": "legacy/plugins/monitoring", + "xpack.monitoring": ["plugins/monitoring", "legacy/plugins/monitoring"], "xpack.remoteClusters": "plugins/remote_clusters", "xpack.reporting": ["plugins/reporting", "legacy/plugins/reporting"], "xpack.rollupJobs": "legacy/plugins/rollup", diff --git a/x-pack/legacy/plugins/monitoring/config.js b/x-pack/legacy/plugins/monitoring/config.js index bd35d5271132..fd4e6512c506 100644 --- a/x-pack/legacy/plugins/monitoring/config.js +++ b/x-pack/legacy/plugins/monitoring/config.js @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS } from '../../server/lib/constants'; - /** * User-configurable settings for xpack.monitoring via configuration schema * @param {Object} Joi - HapiJS Joi module that allows for schema validation @@ -132,9 +130,9 @@ export const config = Joi => { email_address: Joi.string().email(), }).default(), }).default(), - xpack_api_polling_frequency_millis: Joi.number().default( - XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS - ), + licensing: Joi.object({ + api_polling_frequency: Joi.number().default(30001), + }), agent: Joi.object({ interval: Joi.string() .regex(/[\d\.]+[yMwdhms]/) diff --git a/x-pack/legacy/plugins/monitoring/index.js b/x-pack/legacy/plugins/monitoring/index.js new file mode 100644 index 000000000000..fcf704b5f65d --- /dev/null +++ b/x-pack/legacy/plugins/monitoring/index.js @@ -0,0 +1,59 @@ +/* + * 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 { resolve } from 'path'; +import { config } from './config'; +import { getUiExports } from './ui_exports'; +import { KIBANA_ALERTING_ENABLED } from './common/constants'; +import { telemetryCollectionManager } from '../../../../src/legacy/core_plugins/telemetry/server'; + +/** + * Invokes plugin modules to instantiate the Monitoring plugin for Kibana + * @param kibana {Object} Kibana plugin instance + * @return {Object} Monitoring UI Kibana plugin object + */ +const deps = ['kibana', 'elasticsearch', 'xpack_main']; +if (KIBANA_ALERTING_ENABLED) { + deps.push(...['alerting', 'actions']); +} +export const monitoring = kibana => { + return new kibana.Plugin({ + require: deps, + id: 'monitoring', + configPrefix: 'monitoring', + publicDir: resolve(__dirname, 'public'), + init(server) { + const serverConfig = server.config(); + const npMonitoring = server.newPlatform.setup.plugins.monitoring; + if (npMonitoring) { + const kbnServerStatus = this.kbnServer.status; + npMonitoring.registerLegacyAPI({ + telemetryCollectionManager, + getServerStatus: () => { + const status = kbnServerStatus.toJSON(); + return get(status, 'overall.state'); + }, + }); + } + + server.injectUiAppVars('monitoring', () => { + return { + maxBucketSize: serverConfig.get('monitoring.ui.max_bucket_size'), + minIntervalSeconds: serverConfig.get('monitoring.ui.min_interval_seconds'), + kbnIndex: serverConfig.get('kibana.index'), + showLicenseExpiration: serverConfig.get('monitoring.ui.show_license_expiration'), + showCgroupMetricsElasticsearch: serverConfig.get( + 'monitoring.ui.container.elasticsearch.enabled' + ), + showCgroupMetricsLogstash: serverConfig.get('monitoring.ui.container.logstash.enabled'), // Note, not currently used, but see https://github.com/elastic/x-pack-kibana/issues/1559 part 2 + }; + }); + }, + config, + uiExports: getUiExports(), + }); +}; diff --git a/x-pack/legacy/plugins/monitoring/index.ts b/x-pack/legacy/plugins/monitoring/index.ts deleted file mode 100644 index 3a23140104e1..000000000000 --- a/x-pack/legacy/plugins/monitoring/index.ts +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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 { resolve } from 'path'; -import KbnServer, { Server } from 'src/legacy/server/kbn_server'; -import { - LegacyPluginApi, - LegacyPluginSpec, - LegacyPluginOptions, -} from 'src/legacy/plugin_discovery/types'; -import { KIBANA_ALERTING_ENABLED } from './common/constants'; - -// @ts-ignore -import { getUiExports } from './ui_exports'; -// @ts-ignore -import { config as configDefaults } from './config'; -// @ts-ignore -import { deprecations } from './deprecations'; -// @ts-ignore -import { Plugin } from './server/plugin'; -// @ts-ignore -import { initInfraSource } from './server/lib/logs/init_infra_source'; - -type InfraPlugin = any; // TODO -type PluginsSetup = any; // TODO -type LegacySetup = any; // TODO - -const deps = ['kibana', 'elasticsearch', 'xpack_main']; -if (KIBANA_ALERTING_ENABLED) { - deps.push(...['alerting', 'actions']); -} - -const validConfigOptions: string[] = [ - 'monitoring.ui.enabled', - 'monitoring.kibana.collection.enabled', - 'monitoring.ui.max_bucket_size', - 'monitoring.ui.min_interval_seconds', - 'kibana.index', - 'monitoring.ui.show_license_expiration', - 'monitoring.ui.container.elasticsearch.enabled', - 'monitoring.ui.container.logstash.enabled', - 'monitoring.tests.cloud_detector.enabled', - 'monitoring.kibana.collection.interval', - 'monitoring.elasticsearch.hosts', - 'monitoring.elasticsearch', - 'monitoring.ui.elasticsearch.hosts', - 'monitoring.ui.elasticsearch', - 'monitoring.xpack_api_polling_frequency_millis', - 'server.uuid', - 'server.name', - 'server.host', - 'server.port', - 'monitoring.cluster_alerts.email_notifications.enabled', - 'monitoring.cluster_alerts.email_notifications.email_address', - 'monitoring.ui.ccs.enabled', - 'monitoring.ui.elasticsearch.logFetchCount', - 'monitoring.ui.logs.index', -]; - -interface LegacyPluginOptionsWithKbnServer extends LegacyPluginOptions { - kbnServer?: KbnServer; -} - -/** - * Invokes plugin modules to instantiate the Monitoring plugin for Kibana - * @param kibana {Object} Kibana plugin instance - * @return {Object} Monitoring UI Kibana plugin object - */ -export const monitoring = (kibana: LegacyPluginApi): LegacyPluginSpec => { - return new kibana.Plugin({ - require: deps, - id: 'monitoring', - configPrefix: 'monitoring', - publicDir: resolve(__dirname, 'public'), - config: configDefaults, - uiExports: getUiExports(), - deprecations, - - async init(server: Server) { - const serverConfig = server.config(); - const { getOSInfo, plugins, injectUiAppVars } = server as typeof server & { getOSInfo?: any }; - const log = (...args: Parameters) => server.log(...args); - const route = (...args: Parameters) => server.route(...args); - const expose = (...args: Parameters) => server.expose(...args); - const serverFacade = { - config: () => ({ - get: (key: string) => { - if (validConfigOptions.includes(key)) { - return serverConfig.get(key); - } - throw new Error(`Unknown key '${key}'`); - }, - }), - injectUiAppVars, - log, - logger: server.newPlatform.coreContext.logger, - getOSInfo, - events: { - on: (...args: Parameters) => server.events.on(...args), - }, - route, - expose, - _hapi: server, - _kbnServer: this.kbnServer, - }; - - const legacyPlugins = plugins as Partial & { infra?: InfraPlugin }; - const { xpack_main, elasticsearch, infra } = legacyPlugins; - const { - core: coreSetup, - plugins: { usageCollection, licensing, alerting }, - } = server.newPlatform.setup; - - const pluginsSetup: PluginsSetup = { - usageCollection, - licensing, - alerting, - }; - - const __LEGACY: LegacySetup = { - ...serverFacade, - plugins: { - xpack_main, - elasticsearch, - infra, - }, - }; - - const plugin = new Plugin(); - await plugin.setup(coreSetup, pluginsSetup, __LEGACY); - }, - - postInit(server: Server) { - const { infra } = server.plugins as Partial & { infra?: InfraPlugin }; - initInfraSource(server.config(), infra); - }, - } as Partial); -}; diff --git a/x-pack/legacy/plugins/monitoring/public/views/cluster/listing/index.js b/x-pack/legacy/plugins/monitoring/public/views/cluster/listing/index.js index 1c8500caa48a..958226514b14 100644 --- a/x-pack/legacy/plugins/monitoring/public/views/cluster/listing/index.js +++ b/x-pack/legacy/plugins/monitoring/public/views/cluster/listing/index.js @@ -56,6 +56,7 @@ uiRoutes const globalState = $injector.get('globalState'); const storage = $injector.get('localStorage'); const showLicenseExpiration = $injector.get('showLicenseExpiration'); + this.data = $route.current.locals.clusters; $scope.$watch( diff --git a/x-pack/legacy/plugins/monitoring/server/__tests__/check_license.js b/x-pack/legacy/plugins/monitoring/server/__tests__/check_license.js deleted file mode 100644 index 60b27cae3087..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/__tests__/check_license.js +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 { BehaviorSubject } from 'rxjs'; -import expect from '@kbn/expect'; -import sinon from 'sinon'; - -import { XPackInfo } from '../../../xpack_main/server/lib/xpack_info'; -import { licensingMock } from '../../../../../plugins/licensing/server/mocks'; - -const createLicense = (type = 'basic') => { - return licensingMock.createLicense({ - license: { - uid: 'custom-uid', - type, - mode: 'basic', - status: 'active', - expiryDateInMillis: 1286575200000, - }, - features: { - monitoring: { - description: '...', - isAvailable: true, - isEnabled: true, - }, - }, - }); -}; - -describe('XPackInfo', () => { - let mockServer; - let mockElasticsearchPlugin; - - beforeEach(() => { - mockServer = sinon.stub({ - plugins: { elasticsearch: mockElasticsearchPlugin }, - events: { on() {} }, - newPlatform: { - setup: { - plugins: { - licensing: {}, - }, - }, - }, - }); - }); - - describe('refreshNow()', () => { - it('check new platform licensing plugin', async () => { - const refresh = sinon.spy(); - const license$ = new BehaviorSubject(createLicense()); - const xPackInfo = new XPackInfo(mockServer, { - licensing: { - license$, - refresh, - }, - }); - - let changed = false; - license$.subscribe(() => (changed = true)); - await xPackInfo.refreshNow(); - expect(changed).to.be(true); - sinon.assert.calledOnce(refresh); - }); - }); - - describe('Change type', () => { - it('trigger event when license type changes', async () => { - const license$ = new BehaviorSubject(createLicense()); - const refresh = () => void 0; - const xPackInfo = new XPackInfo(mockServer, { - licensing: { - license$, - refresh, - }, - }); - let changed = false; - license$.subscribe(() => (changed = true)); - await license$.next(createLicense('gold')); - expect(xPackInfo.license.getType()).to.be('gold'); - expect(changed).to.be(true); - }); - }); -}); diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/__tests__/fixture_read_file.txt b/x-pack/legacy/plugins/monitoring/server/es_client/__tests__/fixture_read_file.txt deleted file mode 100644 index 0cc06add4111..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/es_client/__tests__/fixture_read_file.txt +++ /dev/null @@ -1 +0,0 @@ -another jejune test file diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/__tests__/instantiate_client.js b/x-pack/legacy/plugins/monitoring/server/es_client/__tests__/instantiate_client.js deleted file mode 100644 index 88cf9734d5f5..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/es_client/__tests__/instantiate_client.js +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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 expect from '@kbn/expect'; -import sinon from 'sinon'; -import { noop } from 'lodash'; -import { exposeClient, hasMonitoringCluster } from '../instantiate_client'; - -function getMockServerFromConnectionUrl(monitoringClusterUrl) { - const server = { - monitoring: { - ui: { - elasticsearch: { - hosts: monitoringClusterUrl ? [monitoringClusterUrl] : [], - username: 'monitoring-user-internal-test', - password: 'monitoring-p@ssw0rd!-internal-test', - ssl: {}, - customHeaders: { - 'x-custom-headers-test': 'connection-monitoring', - }, - }, - }, - }, - }; - - return { - elasticsearchConfig: server.monitoring.ui.elasticsearch, - elasticsearchPlugin: { - getCluster: sinon - .stub() - .withArgs('admin') - .returns({ - config: sinon.stub().returns(server.elasticsearch), - }), - createCluster: sinon.stub(), - }, - events: { - on: noop, - }, - expose: sinon.stub(), - log: sinon.stub(), - }; -} - -describe('Instantiate Client', () => { - describe('Logging', () => { - it('logs that the config was sourced from the production options', () => { - const server = getMockServerFromConnectionUrl(null); // pass null for URL to create the client using prod config - - exposeClient(server); - - expect(server.log.getCall(0).args).to.eql([ - ['monitoring', 'es-client'], - 'config sourced from: production cluster', - ]); - }); - - it('logs that the config was sourced from the monitoring options', () => { - const server = getMockServerFromConnectionUrl('monitoring-cluster.test:9200'); - exposeClient(server); - - expect(server.log.getCall(0).args).to.eql([ - ['monitoring', 'es-client'], - 'config sourced from: monitoring cluster', - ]); - }); - }); - - describe('Custom Headers Configuration', () => { - it('Does not add xpack.monitoring.elasticsearch.customHeaders if connected to production cluster', () => { - const server = getMockServerFromConnectionUrl(null); // pass null for URL to create the client using prod config - - exposeClient(server); - - const createCluster = server.elasticsearchPlugin.createCluster; - const createClusterCall = createCluster.getCall(0); - - sinon.assert.calledOnce(createCluster); - expect(createClusterCall.args[0]).to.be('monitoring'); - expect(createClusterCall.args[1].customHeaders).to.eql(undefined); - }); - - it('Adds xpack.monitoring.elasticsearch.customHeaders if connected to monitoring cluster', () => { - const server = getMockServerFromConnectionUrl('http://monitoring-cluster.test:9200'); // pass null for URL to create the client using prod config - - exposeClient(server); - - const createCluster = server.elasticsearchPlugin.createCluster; - const createClusterCall = createCluster.getCall(0); - - sinon.assert.calledOnce(createCluster); - expect(createClusterCall.args[0]).to.be('monitoring'); - expect(createClusterCall.args[1].customHeaders).to.eql({ - 'x-custom-headers-test': 'connection-monitoring', - }); - }); - }); - - describe('Use a connection to production cluster', () => { - it('exposes an authenticated client using production host settings', () => { - const server = getMockServerFromConnectionUrl(null); // pass null for URL to create the client using prod config - exposeClient(server); - - const createCluster = server.elasticsearchPlugin.createCluster; - const createClusterCall = createCluster.getCall(0); - const createClientOptions = createClusterCall.args[1]; - - sinon.assert.calledOnce(createCluster); - expect(createClusterCall.args[0]).to.be('monitoring'); - expect(createClientOptions.hosts).to.eql(undefined); - }); - }); - - describe('Use a connection to monitoring cluster', () => { - it('exposes an authenticated client using monitoring host settings', () => { - const server = getMockServerFromConnectionUrl('http://monitoring-cluster.test:9200'); - exposeClient(server); - - const createCluster = server.elasticsearchPlugin.createCluster; - const createClusterCall = createCluster.getCall(0); - const createClientOptions = createClusterCall.args[1]; - - sinon.assert.calledOnce(createCluster); - expect(createClusterCall.args[0]).to.be('monitoring'); - expect(createClientOptions.hosts[0]).to.eql('http://monitoring-cluster.test:9200'); - expect(createClientOptions.username).to.eql('monitoring-user-internal-test'); - expect(createClientOptions.password).to.eql('monitoring-p@ssw0rd!-internal-test'); - }); - }); - - describe('hasMonitoringCluster', () => { - it('returns true if monitoring is configured', () => { - const server = getMockServerFromConnectionUrl('http://monitoring-cluster.test:9200'); // pass null for URL to create the client using prod config - expect(hasMonitoringCluster(server.elasticsearchConfig)).to.be(true); - }); - - it('returns false if monitoring is not configured', () => { - const server = getMockServerFromConnectionUrl(null); - expect(hasMonitoringCluster(server.elasticsearchConfig)).to.be(false); - }); - }); -}); diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.mocks.ts b/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.mocks.ts deleted file mode 100644 index 42141313ceea..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.mocks.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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. - */ - -export const mockReadFileSync = jest.fn(); -jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - -export const mockReadPkcs12Keystore = jest.fn(); -export const mockReadPkcs12Truststore = jest.fn(); -jest.mock('../../../../../../src/core/utils', () => ({ - readPkcs12Keystore: mockReadPkcs12Keystore, - readPkcs12Truststore: mockReadPkcs12Truststore, -})); diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.ts b/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.ts deleted file mode 100644 index 8d9b5335732c..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.test.ts +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 { - mockReadFileSync, - mockReadPkcs12Keystore, - mockReadPkcs12Truststore, -} from './parse_elasticsearch_config.test.mocks'; - -import { parseElasticsearchConfig } from './parse_elasticsearch_config'; - -const parse = (config: any) => { - return parseElasticsearchConfig({ - get: () => config, - }); -}; - -describe('reads files', () => { - beforeEach(() => { - mockReadFileSync.mockReset(); - mockReadFileSync.mockImplementation((path: string) => `content-of-${path}`); - mockReadPkcs12Keystore.mockReset(); - mockReadPkcs12Keystore.mockImplementation((path: string) => ({ - key: `content-of-${path}.key`, - cert: `content-of-${path}.cert`, - ca: [`content-of-${path}.ca`], - })); - mockReadPkcs12Truststore.mockReset(); - mockReadPkcs12Truststore.mockImplementation((path: string) => [`content-of-${path}`]); - }); - - it('reads certificate authorities when ssl.keystore.path is specified', () => { - const configValue = parse({ ssl: { keystore: { path: 'some-path' } } }); - expect(mockReadPkcs12Keystore).toHaveBeenCalledTimes(1); - expect(configValue.ssl.certificateAuthorities).toEqual(['content-of-some-path.ca']); - }); - - it('reads certificate authorities when ssl.truststore.path is specified', () => { - const configValue = parse({ ssl: { truststore: { path: 'some-path' } } }); - expect(mockReadPkcs12Truststore).toHaveBeenCalledTimes(1); - expect(configValue.ssl.certificateAuthorities).toEqual(['content-of-some-path']); - }); - - it('reads certificate authorities when ssl.certificateAuthorities is specified', () => { - let configValue = parse({ ssl: { certificateAuthorities: 'some-path' } }); - expect(mockReadFileSync).toHaveBeenCalledTimes(1); - expect(configValue.ssl.certificateAuthorities).toEqual(['content-of-some-path']); - - mockReadFileSync.mockClear(); - configValue = parse({ ssl: { certificateAuthorities: ['some-path'] } }); - expect(mockReadFileSync).toHaveBeenCalledTimes(1); - expect(configValue.ssl.certificateAuthorities).toEqual(['content-of-some-path']); - - mockReadFileSync.mockClear(); - configValue = parse({ ssl: { certificateAuthorities: ['some-path', 'another-path'] } }); - expect(mockReadFileSync).toHaveBeenCalledTimes(2); - expect(configValue.ssl.certificateAuthorities).toEqual([ - 'content-of-some-path', - 'content-of-another-path', - ]); - }); - - it('reads certificate authorities when ssl.keystore.path, ssl.truststore.path, and ssl.certificateAuthorities are specified', () => { - const configValue = parse({ - ssl: { - keystore: { path: 'some-path' }, - truststore: { path: 'another-path' }, - certificateAuthorities: 'yet-another-path', - }, - }); - expect(mockReadPkcs12Keystore).toHaveBeenCalledTimes(1); - expect(mockReadPkcs12Truststore).toHaveBeenCalledTimes(1); - expect(mockReadFileSync).toHaveBeenCalledTimes(1); - expect(configValue.ssl.certificateAuthorities).toEqual([ - 'content-of-some-path.ca', - 'content-of-another-path', - 'content-of-yet-another-path', - ]); - }); - - it('reads a private key and certificate when ssl.keystore.path is specified', () => { - const configValue = parse({ ssl: { keystore: { path: 'some-path' } } }); - expect(mockReadPkcs12Keystore).toHaveBeenCalledTimes(1); - expect(configValue.ssl.key).toEqual('content-of-some-path.key'); - expect(configValue.ssl.certificate).toEqual('content-of-some-path.cert'); - }); - - it('reads a private key when ssl.key is specified', () => { - const configValue = parse({ ssl: { key: 'some-path' } }); - expect(mockReadFileSync).toHaveBeenCalledTimes(1); - expect(configValue.ssl.key).toEqual('content-of-some-path'); - }); - - it('reads a certificate when ssl.certificate is specified', () => { - const configValue = parse({ ssl: { certificate: 'some-path' } }); - expect(mockReadFileSync).toHaveBeenCalledTimes(1); - expect(configValue.ssl.certificate).toEqual('content-of-some-path'); - }); -}); - -describe('throws when config is invalid', () => { - beforeAll(() => { - const realFs = jest.requireActual('fs'); - mockReadFileSync.mockImplementation((path: string) => realFs.readFileSync(path)); - const utils = jest.requireActual('../../../../../../src/core/utils'); - mockReadPkcs12Keystore.mockImplementation((path: string, password?: string) => - utils.readPkcs12Keystore(path, password) - ); - mockReadPkcs12Truststore.mockImplementation((path: string, password?: string) => - utils.readPkcs12Truststore(path, password) - ); - }); - - it('throws if key is invalid', () => { - const value = { ssl: { key: '/invalid/key' } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, open '/invalid/key'"` - ); - }); - - it('throws if certificate is invalid', () => { - const value = { ssl: { certificate: '/invalid/cert' } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, open '/invalid/cert'"` - ); - }); - - it('throws if certificateAuthorities is invalid', () => { - const value = { ssl: { certificateAuthorities: '/invalid/ca' } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, open '/invalid/ca'"` - ); - }); - - it('throws if keystore path is invalid', () => { - const value = { ssl: { keystore: { path: '/invalid/keystore' } } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, open '/invalid/keystore'"` - ); - }); - - it('throws if keystore does not contain a key', () => { - mockReadPkcs12Keystore.mockReturnValueOnce({}); - const value = { ssl: { keystore: { path: 'some-path' } } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"Did not find key in Elasticsearch keystore."` - ); - }); - - it('throws if keystore does not contain a certificate', () => { - mockReadPkcs12Keystore.mockReturnValueOnce({ key: 'foo' }); - const value = { ssl: { keystore: { path: 'some-path' } } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"Did not find certificate in Elasticsearch keystore."` - ); - }); - - it('throws if truststore path is invalid', () => { - const value = { ssl: { keystore: { path: '/invalid/truststore' } } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, open '/invalid/truststore'"` - ); - }); - - it('throws if key and keystore.path are both specified', () => { - const value = { ssl: { key: 'foo', keystore: { path: 'bar' } } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"[config validation of [monitoring.ui.elasticsearch].ssl]: cannot use [key] when [keystore.path] is specified"` - ); - }); - - it('throws if certificate and keystore.path are both specified', () => { - const value = { ssl: { certificate: 'foo', keystore: { path: 'bar' } } }; - expect(() => parse(value)).toThrowErrorMatchingInlineSnapshot( - `"[config validation of [monitoring.ui.elasticsearch].ssl]: cannot use [certificate] when [keystore.path] is specified"` - ); - }); -}); diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.ts b/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.ts deleted file mode 100644 index 87b225e48c15..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/es_client/parse_elasticsearch_config.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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 { readFileSync } from 'fs'; -import { readPkcs12Truststore, readPkcs12Keystore } from '../../../../../../src/core/utils'; - -const KEY = 'monitoring.ui.elasticsearch'; - -/* - * Parse a config object's Elasticsearch configuration, reading any - * certificates/keys from the filesystem - * - * TODO: this code can be removed when this plugin is migrated to the Kibana Platform, - * at that point the ElasticsearchClient and ElasticsearchConfig should be used instead - */ -export const parseElasticsearchConfig = (config: any, configKey: string = KEY) => { - const es = config.get(configKey); - if (!es) { - return {}; - } - - const errorPrefix = `[config validation of [${configKey}].ssl]`; - if (es.ssl?.key && es.ssl?.keystore?.path) { - throw new Error(`${errorPrefix}: cannot use [key] when [keystore.path] is specified`); - } - if (es.ssl?.certificate && es.ssl?.keystore?.path) { - throw new Error(`${errorPrefix}: cannot use [certificate] when [keystore.path] is specified`); - } - - const { alwaysPresentCertificate, verificationMode } = es.ssl; - const { key, keyPassphrase, certificate, certificateAuthorities } = readKeyAndCerts(es); - - return { - ...es, - ssl: { - alwaysPresentCertificate, - key, - keyPassphrase, - certificate, - certificateAuthorities, - verificationMode, - }, - }; -}; - -const readKeyAndCerts = (rawConfig: any) => { - let key: string | undefined; - let keyPassphrase: string | undefined; - let certificate: string | undefined; - let certificateAuthorities: string[] | undefined; - - const addCAs = (ca: string[] | undefined) => { - if (ca && ca.length) { - certificateAuthorities = [...(certificateAuthorities || []), ...ca]; - } - }; - - if (rawConfig.ssl.keystore?.path) { - const keystore = readPkcs12Keystore( - rawConfig.ssl.keystore.path, - rawConfig.ssl.keystore.password - ); - if (!keystore.key) { - throw new Error(`Did not find key in Elasticsearch keystore.`); - } else if (!keystore.cert) { - throw new Error(`Did not find certificate in Elasticsearch keystore.`); - } - key = keystore.key; - certificate = keystore.cert; - addCAs(keystore.ca); - } else { - if (rawConfig.ssl.key) { - key = readFile(rawConfig.ssl.key); - keyPassphrase = rawConfig.ssl.keyPassphrase; - } - if (rawConfig.ssl.certificate) { - certificate = readFile(rawConfig.ssl.certificate); - } - } - - if (rawConfig.ssl.truststore?.path) { - const ca = readPkcs12Truststore( - rawConfig.ssl.truststore.path, - rawConfig.ssl.truststore.password - ); - addCAs(ca); - } - - const ca = rawConfig.ssl.certificateAuthorities; - if (ca) { - const parsed: string[] = []; - const paths = Array.isArray(ca) ? ca : [ca]; - if (paths.length > 0) { - for (const path of paths) { - parsed.push(readFile(path)); - } - addCAs(parsed); - } - } - - return { - key, - keyPassphrase, - certificate, - certificateAuthorities, - }; -}; - -const readFile = (file: string) => { - return readFileSync(file, 'utf8'); -}; diff --git a/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js b/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js deleted file mode 100644 index 7a6ab37798db..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 { checkLicenseGenerator } from './cluster_alerts/check_license'; -import { hasMonitoringCluster } from './es_client/instantiate_client'; -import { LOGGING_TAG } from '../common/constants'; -import { XPackInfo } from '../../xpack_main/server/lib/xpack_info'; - -/* - * Expose xpackInfo for the Monitoring cluster as server.plugins.monitoring.info - */ -export const initMonitoringXpackInfo = async ({ - config, - server, - client, - xpackMainPlugin, - licensing, - expose, - log, -}) => { - const xpackInfo = hasMonitoringCluster(config) - ? new XPackInfo(server, { - licensing: licensing.createLicensePoller( - client, - config.get('monitoring.xpack_api_polling_frequency_millis') - ), - }) - : xpackMainPlugin.info; - - xpackInfo.feature('monitoring').registerLicenseCheckResultsGenerator(checkLicenseGenerator); - expose('info', xpackInfo); - - // check if X-Pack is installed on Monitoring Cluster - const xpackInfoTest = await xpackInfo.refreshNow(); - if (!xpackInfoTest.isAvailable()) { - log( - [LOGGING_TAG, 'warning'], - `X-Pack Monitoring Cluster Alerts will not be available: ${xpackInfoTest.unavailableReason()}` - ); - } -}; diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.js deleted file mode 100644 index e7219fcfcaef..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.js +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 { - LOGGING_TAG, - KIBANA_MONITORING_LOGGING_TAG, - KIBANA_STATS_TYPE_MONITORING, -} from '../../../common/constants'; -import { opsBuffer } from './ops_buffer'; -import Oppsy from 'oppsy'; -import { cloneDeep } from 'lodash'; - -let bufferHadEvents = false; - -class OpsMonitor { - constructor(hapiServer, buffer, interval) { - this._buffer = buffer; - this._interval = interval; - this._oppsy = new Oppsy(hapiServer); - this._server = hapiServer; - } - - start = () => { - this._oppsy.on('ops', event => { - // Oppsy has a bad race condition that will modify this data before - // we ship it off to the buffer. Let's create our copy first. - event = cloneDeep(event); - // Oppsy used to provide this, but doesn't anymore. Grab it ourselves. - this._server.listener.getConnections((_, count) => { - event.concurrent_connections = count; - this._buffer.push(event); - }); - }); - - this._oppsy.on('error', console.log); - this._oppsy.start(this._interval); - }; - - stop = () => { - this._oppsy.stop(); - this._oppsy.removeAllListeners(); - }; -} - -/* - * Initialize a collector for Kibana Ops Stats - */ -export function getOpsStatsCollector( - usageCollection, - { elasticsearchPlugin, kbnServerConfig, log, config, getOSInfo, hapiServer } -) { - const buffer = opsBuffer({ log, config, getOSInfo }); - const interval = kbnServerConfig.get('ops.interval'); - const opsMonitor = new OpsMonitor(hapiServer, buffer, interval); - - /* Handle stopping / restarting the event listener if Elasticsearch stops and restarts - * NOTE it is possible for the plugin status to go from red to red and - * trigger handlers twice - */ - elasticsearchPlugin.status.on('red', opsMonitor.stop); - elasticsearchPlugin.status.on('green', opsMonitor.start); - - // `process` is a NodeJS global, and is always available without using require/import - process.on('SIGHUP', () => { - log( - ['info', LOGGING_TAG, KIBANA_MONITORING_LOGGING_TAG], - 'Re-initializing Kibana Monitoring due to SIGHUP' - ); - setTimeout(() => { - opsMonitor.stop(); - opsMonitor.start(); - log( - ['info', LOGGING_TAG, KIBANA_MONITORING_LOGGING_TAG], - 'Re-initializing Kibana Monitoring due to SIGHUP' - ); - }, 5 * 1000); // wait 5 seconds to avoid race condition with reloading logging configuration - }); - - return usageCollection.makeStatsCollector({ - type: KIBANA_STATS_TYPE_MONITORING, - init: opsMonitor.start, - isReady: () => { - if (!bufferHadEvents) { - bufferHadEvents = buffer.hasEvents(); - } - return bufferHadEvents; - }, - fetch: async () => { - return await buffer.flush(); - }, - }); -} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/event_roller.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/event_roller.js deleted file mode 100644 index b64f1a010725..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/event_roller.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 { EventRoller } from '../event_roller'; -import expect from '@kbn/expect'; - -const events = [ - { - requests: { - '5601': { - total: 103, - disconnects: 0, - statusCodes: { '200': 15, '304': 88 }, - }, - }, - responseTimes: { '5601': { avg: 5.213592233009709, max: 36 } }, - osload: [1.90380859375, 1.84033203125, 1.82666015625], - osmem: { total: 17179869184, free: 613638144 }, - osup: 4615, - psup: 62.388, - psmem: { - rss: 518164480, - heapTotal: 474275840, - heapUsed: 318428400, - external: 5172252, - }, - concurrent_connections: 6, - psdelay: 0.4091129992157221, - }, - { - requests: { - '5601': { - total: 35, - disconnects: 0, - statusCodes: { '200': 5, '304': 30 }, - }, - }, - responseTimes: { '5601': { avg: 4.6, max: 29 } }, - sockets: { - http: { total: 1, '169.254.169.254:80:': 1 }, - https: { total: 0 }, - }, - osload: [1.9111328125, 1.8427734375, 1.82763671875], - osmem: { total: 17179869184, free: 641744896 }, - osup: 4620, - psup: 67.39, - psmem: { - rss: 518193152, - heapTotal: 474275840, - heapUsed: 315669840, - external: 5083177, - }, - concurrent_connections: 6, - psdelay: 0.6715770000591874, - }, -]; - -describe('Event Roller', () => { - it('constructs an event roller object', () => { - const eventRoller = new EventRoller(); - expect(eventRoller.rollup).to.be(null); - expect(eventRoller.getFromRollup()).to.be(undefined); - expect(eventRoller.getFromRollup('concurrent_connections')).to.be(undefined); - }); - - it('adds events and rolls them up', () => { - const eventRoller = new EventRoller(); - const [event1, event2] = events; - eventRoller.addEvent(event1); - eventRoller.addEvent(event2); - - const flush = eventRoller.flush(); - // delete unpredictable fields - delete flush.timestamp; - delete flush.process.memory.heap.size_limit; - - expect(flush).to.eql({ - concurrent_connections: 12, // 6 + 6 - os: { - load: { '1m': 1.9111328125, '5m': 1.8427734375, '15m': 1.82763671875 }, // just the latest - memory: { - total_in_bytes: 17179869184, - free_in_bytes: 641744896, - used_in_bytes: 16538124288, // just the latest - }, - uptime_in_millis: 4620000, // converted from latest osup - }, - process: { - event_loop_delay: 1.0806899992749095, // 0.4091129992157221 + 0.6715770000591874 - memory: { - heap: { - total_in_bytes: 474275840, - used_in_bytes: 315669840, - }, - resident_set_size_in_bytes: 518193152, // just the latest - }, - uptime_in_millis: 67390, // latest from psup - }, - requests: { - disconnects: 0, - total: 138, // 103 + 35 - }, - response_times: { - average: 5.213592233009709, // max of 5.213592233009709, 4.6 - max: 36, // max of 36, 29 - }, - }); - }); - - it('forgets the rollup after flush', () => { - const eventRoller = new EventRoller(); - const [event1, event2] = events; - eventRoller.addEvent(event1); - eventRoller.addEvent(event2); - - const flush1 = eventRoller.flush(); // eslint-disable-line no-unused-vars - const flush2 = eventRoller.flush(); - - expect(flush2).to.be(null); - }); -}); diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_requests.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_requests.js deleted file mode 100644 index 330c6387b947..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_requests.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 _ from 'lodash'; -import { mapRequests } from '../map_requests'; -import expect from '@kbn/expect'; - -describe('Map requests', () => { - it('flatten ports', () => { - const requests = { '5603': { total: 1, disconnects: 0, statusCodes: {} } }; - const expected = { total: 1, disconnects: 0 }; - expect(_.isEqual(mapRequests(requests), expected)).to.be(true); - }); - - it('combine values', () => { - const requests = { - '5603': { total: 1, disconnects: 0, statusCodes: {} }, - '5604': { - total: 1, - disconnects: 44, - statusCodes: { - '200': 2, - '201': 4, - }, - }, - '5605': { - total: 1, - disconnects: 0, - statusCodes: { - '200': 20, - }, - }, - }; - const expected = { - total: 3, - disconnects: 44, - }; - expect(_.isEqual(mapRequests(requests), expected)).to.be(true); - }); -}); diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_response_times.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_response_times.js deleted file mode 100644 index c8e8b2da0c5c..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/__tests__/map_response_times.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 { isEqual } from 'lodash'; -import { mapResponseTimes } from '../map_response_times'; -import expect from '@kbn/expect'; - -describe('Map response times', () => { - it('flatten ports', () => { - const responseTimes = { '5603': { avg: 30, max: 250 } }; - const expected = { average: 30, max: 250 }; - expect(isEqual(mapResponseTimes(responseTimes), expected)).to.be(true); - }); - - it('combine empty', () => { - const responseTimes = {}; - const expected = { average: 0, max: 0 }; - expect(isEqual(mapResponseTimes(responseTimes), expected)).to.be(true); - }); - - it('combine results', () => { - const responseTimes = { - '5600': { - avg: 1, - max: 10, - }, - '5602': { - avg: 3, - max: 200, - }, - }; - const expected = { average: 3, max: 200 }; - expect(isEqual(mapResponseTimes(responseTimes), expected)).to.be(true); - }); - - it('combine results with different maximums for average and max value', () => { - const responseTimes = { - '5600': { - avg: 5, - max: 10, - }, - '5602': { - avg: 3, - max: 200, - }, - '5604': { - // no average - max: 105, - }, - }; - const expected = { average: 5, max: 200 }; - expect(isEqual(mapResponseTimes(responseTimes), expected)).to.be(true); - }); -}); diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/event_roller.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/event_roller.js deleted file mode 100644 index 08f1c949f25f..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/event_roller.js +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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, partialRight, assign, max, sum } from 'lodash'; -import moment from 'moment'; -import v8 from 'v8'; -import { mapRequests } from './map_requests'; -import { mapResponseTimes } from './map_response_times'; - -// rollup functions are for objects with unpredictable keys (e.g., {'200': 1, '201': 2} + {'200':2} = {'200': 3, '201': 2}) -const maxRollup = partialRight(assign, (latest, prev) => max([latest, prev])); - -export class EventRoller { - constructor() { - this.rollup = null; - } - - getFromRollup(path) { - return get(this.rollup, path); - } - - hasEvents() { - return this.rollup !== null; - } - - rollupEvent(event) { - const heapStats = v8.getHeapStatistics(); - const requests = mapRequests(event.requests); - - return { - concurrent_connections: sum([ - event.concurrent_connections, - this.getFromRollup('concurrent_connections'), - ]), - // memory/os stats use the latest event's details - os: { - load: { - '1m': get(event, 'osload[0]'), - '5m': get(event, 'osload[1]'), - '15m': get(event, 'osload[2]'), - }, - memory: { - total_in_bytes: get(event, 'osmem.total'), - free_in_bytes: get(event, 'osmem.free'), - used_in_bytes: get(event, 'osmem.total') - get(event, 'osmem.free'), - }, - uptime_in_millis: event.osup * 1000, // seconds to milliseconds - }, - process: { - event_loop_delay: sum([event.psdelay, this.getFromRollup('process.event_loop_delay')]), - memory: { - heap: { - total_in_bytes: get(event, 'psmem.heapTotal'), - used_in_bytes: get(event, 'psmem.heapUsed'), - size_limit: heapStats.heap_size_limit, - }, - resident_set_size_in_bytes: get(event, 'psmem.rss'), - }, - uptime_in_millis: event.psup * 1000, // seconds to milliseconds - }, - requests: { - disconnects: sum([requests.disconnects, this.getFromRollup('requests.disconnects')]), - total: sum([requests.total, this.getFromRollup('requests.total')]), - }, - response_times: maxRollup( - mapResponseTimes(event.responseTimes), - this.getFromRollup('response_times') - ), - timestamp: moment.utc().toISOString(), - }; - } - - addEvent(event) { - // update internal state with new event data - this.rollup = this.rollupEvent(event); - } - - flush() { - // reset the internal state and return it - const rollup = this.rollup; - this.rollup = null; - return rollup; - } -} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_requests.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_requests.js deleted file mode 100644 index 0a4cbc567b60..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_requests.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 _ from 'lodash'; - -export function mapRequests(requests) { - return _.reduce( - _.values(requests), - (result, value) => { - result.total += value.total; - result.disconnects += value.disconnects; - return result; - }, - { total: 0, disconnects: 0 } - ); -} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_response_times.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_response_times.js deleted file mode 100644 index 496ae914a0c5..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/map_response_times.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 _ from 'lodash'; - -export function mapResponseTimes(times) { - const responseTimes = _.reduce( - _.values(times), - (result, value) => { - if (value.avg) { - result.avg = Math.max(result.avg, value.avg); - } - result.max = Math.max(result.max, value.max); - return result; - }, - { avg: 0, max: 0 } - ); - return { - average: responseTimes.avg, - max: responseTimes.max, - }; -} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/ops_buffer.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/ops_buffer.js deleted file mode 100644 index 05f81f5c376a..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/ops_buffer.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 { EventRoller } from './event_roller'; -import { CloudDetector } from '../../../cloud'; - -/** - * Manage the buffer of Kibana Ops events - * @param {Object} server HapiJS server instance - * @return {Object} the revealed `push` and `flush` modules - */ -export function opsBuffer({ config, getOSInfo }) { - // determine the cloud service in the background - const cloudDetector = new CloudDetector(); - - if (config.get('monitoring.tests.cloud_detector.enabled')) { - cloudDetector.detectCloudService(); - } - - const eventRoller = new EventRoller(); - - return { - push(event) { - eventRoller.addEvent(event); - }, - - hasEvents() { - return eventRoller.hasEvents(); - }, - - async flush() { - let cloud; // a property that will be left out of the result if the details are undefined - const cloudDetails = cloudDetector.getCloudDetails(); - if (cloudDetails != null) { - cloud = { cloud: cloudDetails }; - } - - const eventRollup = eventRoller.flush(); - if (eventRollup && eventRollup.os) { - eventRollup.os = { - ...eventRollup.os, - ...(await getOSInfo()), - }; - } - - return { - ...cloud, - ...eventRollup, - }; - }, - }; -} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/get_kibana_info_for_stats.js b/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/get_kibana_info_for_stats.js deleted file mode 100644 index b7cbdbc4f2f9..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/get_kibana_info_for_stats.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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'; - -const snapshotRegex = /-snapshot/i; - -/** - * This provides a common structure to apply to all Kibana monitoring documents so that they can be commonly - * searched, field-collapsed, and aggregated against. - * - * @param {Object} kbnServer manager of Kibana services - see `src/legacy/server/kbn_server` in Kibana core - * @param {Object} config Server config - * @param {String} host Kibana host - * @return {Object} The object containing a "kibana" field and source instance details. - */ -export function getKibanaInfoForStats({ kbnServerStatus, kbnServerVersion, config }) { - const status = kbnServerStatus.toJSON(); - - return { - uuid: config.get('server.uuid'), - name: config.get('server.name'), - index: config.get('kibana.index'), - host: config.get('server.host'), - transport_address: `${config.get('server.host')}:${config.get('server.port')}`, - version: kbnServerVersion.replace(snapshotRegex, ''), - snapshot: snapshotRegex.test(kbnServerVersion), - status: get(status, 'overall.state'), - }; -} diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js b/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js deleted file mode 100644 index 7380864d5ebe..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Not using named imports, because the resources are JSON files - */ -import shardStatsFixture from './shard_stats'; -import clusterFixture from './cluster'; - -export { - shardStatsFixture, - clusterFixture -}; diff --git a/x-pack/legacy/plugins/monitoring/server/plugin.js b/x-pack/legacy/plugins/monitoring/server/plugin.js deleted file mode 100644 index fa9f1ae69991..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/plugin.js +++ /dev/null @@ -1,189 +0,0 @@ -/* - * 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 { i18n } from '@kbn/i18n'; -import { - LOGGING_TAG, - KIBANA_MONITORING_LOGGING_TAG, - KIBANA_ALERTING_ENABLED, -} from '../common/constants'; -import { requireUIRoutes } from './routes'; -import { instantiateClient } from './es_client/instantiate_client'; -import { initMonitoringXpackInfo } from './init_monitoring_xpack_info'; -import { initBulkUploader, registerCollectors } from './kibana_monitoring'; -import { registerMonitoringCollection } from './telemetry_collection'; -import { getLicenseExpiration } from './alerts/license_expiration'; -import { parseElasticsearchConfig } from './es_client/parse_elasticsearch_config'; - -export class Plugin { - async setup(_coreSetup, pluginsSetup, __LEGACY) { - const { - plugins, - _kbnServer: kbnServer, - log, - logger, - getOSInfo, - _hapi: hapiServer, - events, - expose, - config: monitoringConfig, - injectUiAppVars, - } = __LEGACY; - const config = monitoringConfig(); - - const { usageCollection, licensing, alerting } = pluginsSetup; - registerMonitoringCollection(); - /* - * Register collector objects for stats to show up in the APIs - */ - registerCollectors(usageCollection, { - elasticsearchPlugin: plugins.elasticsearch, - kbnServerConfig: kbnServer.config, - log, - config, - getOSInfo, - hapiServer, - }); - - /* - * Instantiate and start the internal background task that calls collector - * fetch methods and uploads to the ES monitoring bulk endpoint - */ - const xpackMainPlugin = plugins.xpack_main; - - /* - * Parse the Elasticsearch config and read any certificates/keys if necessary - */ - const elasticsearchConfig = parseElasticsearchConfig(config); - - // Create the dedicated client - const client = await instantiateClient({ - log, - events, - elasticsearchConfig, - elasticsearchPlugin: plugins.elasticsearch, - }); - - xpackMainPlugin.status.once('green', async () => { - // first time xpack_main turns green - /* - * End-user-facing services - */ - const uiEnabled = config.get('monitoring.ui.enabled'); - - if (uiEnabled) { - await initMonitoringXpackInfo({ - config, - server: hapiServer, - client, - log, - xpackMainPlugin: plugins.xpack_main, - expose, - }); // Route handlers depend on this for xpackInfo - await requireUIRoutes(__LEGACY); - } - }); - - xpackMainPlugin.registerFeature({ - id: 'monitoring', - name: i18n.translate('xpack.monitoring.featureRegistry.monitoringFeatureName', { - defaultMessage: 'Stack Monitoring', - }), - icon: 'monitoringApp', - navLinkId: 'monitoring', - app: ['monitoring', 'kibana'], - catalogue: ['monitoring'], - privileges: {}, - reserved: { - privilege: { - savedObject: { - all: [], - read: [], - }, - ui: [], - }, - description: i18n.translate('xpack.monitoring.feature.reserved.description', { - defaultMessage: 'To grant users access, you should also assign the monitoring_user role.', - }), - }, - }); - - const bulkUploader = initBulkUploader({ - elasticsearchPlugin: plugins.elasticsearch, - config, - log, - kbnServerStatus: kbnServer.status, - kbnServerVersion: kbnServer.version, - }); - const kibanaCollectionEnabled = config.get('monitoring.kibana.collection.enabled'); - - if (kibanaCollectionEnabled) { - /* - * Bulk uploading of Kibana stats - */ - licensing.license$.subscribe(license => { - // use updated xpack license info to start/stop bulk upload - const mainMonitoring = license.getFeature('monitoring'); - const monitoringBulkEnabled = - mainMonitoring && mainMonitoring.isAvailable && mainMonitoring.isEnabled; - if (monitoringBulkEnabled) { - bulkUploader.start(usageCollection); - } else { - bulkUploader.handleNotEnabled(); - } - }); - } else if (!kibanaCollectionEnabled) { - log( - ['info', LOGGING_TAG, KIBANA_MONITORING_LOGGING_TAG], - 'Internal collection for Kibana monitoring is disabled per configuration.' - ); - } - - injectUiAppVars('monitoring', () => { - return { - maxBucketSize: config.get('monitoring.ui.max_bucket_size'), - minIntervalSeconds: config.get('monitoring.ui.min_interval_seconds'), - kbnIndex: config.get('kibana.index'), - monitoringUiEnabled: config.get('monitoring.ui.enabled'), - showLicenseExpiration: config.get('monitoring.ui.show_license_expiration'), - showCgroupMetricsElasticsearch: config.get('monitoring.ui.container.elasticsearch.enabled'), - showCgroupMetricsLogstash: config.get('monitoring.ui.container.logstash.enabled'), // Note, not currently used, but see https://github.com/elastic/x-pack-kibana/issues/1559 part 2 - }; - }); - - if (KIBANA_ALERTING_ENABLED && alerting) { - // this is not ready right away but we need to register alerts right away - async function getMonitoringCluster() { - const configs = config.get('xpack.monitoring.elasticsearch'); - if (configs.hosts) { - const monitoringCluster = plugins.elasticsearch.getCluster('monitoring'); - const { username, password } = configs; - const fakeRequest = { - headers: { - authorization: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`, - }, - }; - return { - callCluster: (...args) => monitoringCluster.callWithRequest(fakeRequest, ...args), - }; - } - return null; - } - - function getLogger(contexts) { - return logger.get('plugins', LOGGING_TAG, ...contexts); - } - alerting.registerType( - getLicenseExpiration( - hapiServer, - getMonitoringCluster, - getLogger, - config.get('xpack.monitoring.ccs.enabled') - ) - ); - } - } -} diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts b/x-pack/legacy/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts deleted file mode 100644 index 0b14eb05f796..000000000000 --- a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 { telemetryCollectionManager } from '../../../../../../src/legacy/core_plugins/telemetry/server'; -import { getAllStats } from './get_all_stats'; -import { getClusterUuids } from './get_cluster_uuids'; -import { getLicenses } from './get_licenses'; - -export function registerMonitoringCollection() { - telemetryCollectionManager.setCollection({ - esCluster: 'monitoring', - title: 'monitoring', - priority: 2, - statsGetter: getAllStats, - clusterDetailsGetter: getClusterUuids, - licenseGetter: getLicenses, - }); -} diff --git a/x-pack/legacy/plugins/xpack_main/server/routes/api/v1/settings.js b/x-pack/legacy/plugins/xpack_main/server/routes/api/v1/settings.js index 0773a142a8c9..c830fc9fcd48 100644 --- a/x-pack/legacy/plugins/xpack_main/server/routes/api/v1/settings.js +++ b/x-pack/legacy/plugins/xpack_main/server/routes/api/v1/settings.js @@ -5,8 +5,8 @@ */ import { boomify } from 'boom'; +import { get } from 'lodash'; import { KIBANA_SETTINGS_TYPE } from '../../../../../monitoring/common/constants'; -import { getKibanaInfoForStats } from '../../../../../monitoring/server/kibana_monitoring/lib'; const getClusterUuid = async callCluster => { const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid' }); @@ -32,11 +32,21 @@ export function settingsRoute(server, kbnServer) { } const uuid = await getClusterUuid(callCluster); - const kibana = getKibanaInfoForStats({ - kbnServerStatus: kbnServer.status, - kbnServerVersion: kbnServer.version, - config: server.config(), - }); + const snapshotRegex = /-snapshot/i; + const config = server.config(); + const status = kbnServer.status.toJSON(); + const kibana = { + uuid: config.get('server.uuid'), + name: config.get('server.name'), + index: config.get('kibana.index'), + host: config.get('server.host'), + port: config.get('server.port'), + locale: config.get('i18n.locale'), + transport_address: `${config.get('server.host')}:${config.get('server.port')}`, + version: kbnServer.version.replace(snapshotRegex, ''), + snapshot: snapshotRegex.test(kbnServer.version), + status: get(status, 'overall.state'), + }; return { cluster_uuid: uuid, diff --git a/x-pack/plugins/infra/server/index.ts b/x-pack/plugins/infra/server/index.ts index 54f858554a5a..6cb04897af3f 100644 --- a/x-pack/plugins/infra/server/index.ts +++ b/x-pack/plugins/infra/server/index.ts @@ -5,10 +5,10 @@ */ import { PluginInitializerContext } from 'src/core/server'; -import { config, InfraConfig, InfraServerPlugin } from './plugin'; +import { config, InfraConfig, InfraServerPlugin, InfraPluginSetup } from './plugin'; import { savedObjectMappings } from './saved_objects'; -export { config, InfraConfig, savedObjectMappings }; +export { config, InfraConfig, savedObjectMappings, InfraPluginSetup }; export function plugin(context: PluginInitializerContext) { return new InfraServerPlugin(context); diff --git a/x-pack/plugins/monitoring/common/__tests__/format_timestamp_to_duration.js b/x-pack/plugins/monitoring/common/__tests__/format_timestamp_to_duration.js new file mode 100644 index 000000000000..470d596bd2bd --- /dev/null +++ b/x-pack/plugins/monitoring/common/__tests__/format_timestamp_to_duration.js @@ -0,0 +1,128 @@ +/* + * 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 expect from '@kbn/expect'; +import moment from 'moment'; +import { formatTimestampToDuration } from '../format_timestamp_to_duration'; +import { CALCULATE_DURATION_SINCE, CALCULATE_DURATION_UNTIL } from '../constants'; + +const testTime = moment('2010-05-01'); // pick a date where adding/subtracting 2 months formats roundly to '2 months 0 days' +const getTestTime = () => moment(testTime); // clones the obj so it's not mutated with .adds and .subtracts + +/** + * Test the moment-duration-format template + */ +describe('formatTimestampToDuration', () => { + describe('format timestamp to duration - time since', () => { + it('should format timestamp to human-readable duration', () => { + // time inputs are a few "moments" extra from the time advertised by name + const fiftyNineSeconds = getTestTime().subtract(59, 'seconds'); + expect( + formatTimestampToDuration(fiftyNineSeconds, CALCULATE_DURATION_SINCE, getTestTime()) + ).to.be('59 seconds'); + + const fiveMins = getTestTime() + .subtract(5, 'minutes') + .subtract(30, 'seconds'); + expect(formatTimestampToDuration(fiveMins, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '6 mins' + ); + + const sixHours = getTestTime() + .subtract(6, 'hours') + .subtract(30, 'minutes'); + expect(formatTimestampToDuration(sixHours, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '6 hrs 30 mins' + ); + + const sevenDays = getTestTime() + .subtract(7, 'days') + .subtract(6, 'hours') + .subtract(18, 'minutes'); + expect(formatTimestampToDuration(sevenDays, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '7 days 6 hrs 18 mins' + ); + + const eightWeeks = getTestTime() + .subtract(8, 'weeks') + .subtract(7, 'days') + .subtract(6, 'hours') + .subtract(18, 'minutes'); + expect(formatTimestampToDuration(eightWeeks, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '2 months 2 days' + ); + + const oneHour = getTestTime().subtract(1, 'hour'); // should trim 0 min + expect(formatTimestampToDuration(oneHour, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '1 hr' + ); + + const oneDay = getTestTime().subtract(1, 'day'); // should trim 0 hrs + expect(formatTimestampToDuration(oneDay, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '1 day' + ); + + const twoMonths = getTestTime().subtract(2, 'month'); // should trim 0 days + expect(formatTimestampToDuration(twoMonths, CALCULATE_DURATION_SINCE, getTestTime())).to.be( + '2 months' + ); + }); + }); + + describe('format timestamp to duration - time until', () => { + it('should format timestamp to human-readable duration', () => { + // time inputs are a few "moments" extra from the time advertised by name + const fiftyNineSeconds = getTestTime().add(59, 'seconds'); + expect( + formatTimestampToDuration(fiftyNineSeconds, CALCULATE_DURATION_UNTIL, getTestTime()) + ).to.be('59 seconds'); + + const fiveMins = getTestTime().add(10, 'minutes'); + expect(formatTimestampToDuration(fiveMins, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '10 mins' + ); + + const sixHours = getTestTime() + .add(6, 'hours') + .add(30, 'minutes'); + expect(formatTimestampToDuration(sixHours, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '6 hrs 30 mins' + ); + + const sevenDays = getTestTime() + .add(7, 'days') + .add(6, 'hours') + .add(18, 'minutes'); + expect(formatTimestampToDuration(sevenDays, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '7 days 6 hrs 18 mins' + ); + + const eightWeeks = getTestTime() + .add(8, 'weeks') + .add(7, 'days') + .add(6, 'hours') + .add(18, 'minutes'); + expect(formatTimestampToDuration(eightWeeks, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '2 months 2 days' + ); + + const oneHour = getTestTime().add(1, 'hour'); // should trim 0 min + expect(formatTimestampToDuration(oneHour, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '1 hr' + ); + + const oneDay = getTestTime().add(1, 'day'); // should trim 0 hrs + expect(formatTimestampToDuration(oneDay, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '1 day' + ); + + const twoMonths = getTestTime().add(2, 'month'); // should trim 0 days + expect(formatTimestampToDuration(twoMonths, CALCULATE_DURATION_UNTIL, getTestTime())).to.be( + '2 months' + ); + }); + }); +}); diff --git a/x-pack/plugins/monitoring/common/cancel_promise.ts b/x-pack/plugins/monitoring/common/cancel_promise.ts new file mode 100644 index 000000000000..f100edda5079 --- /dev/null +++ b/x-pack/plugins/monitoring/common/cancel_promise.ts @@ -0,0 +1,70 @@ +/* + * 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. + */ + +export enum Status { + Canceled, + Failed, + Resolved, + Awaiting, + Idle, +} + +/** + * Simple [PromiseWithCancel] factory + */ +export class PromiseWithCancel { + private _promise: Promise; + private _status: Status = Status.Idle; + + /** + * @param {Promise} promise Promise you want to cancel / track + */ + constructor(promise: Promise) { + this._promise = promise; + } + + /** + * Cancel the promise in any state + */ + public cancel = (): void => { + this._status = Status.Canceled; + }; + + /** + * @returns status based on [Status] + */ + public status = (): Status => { + return this._status; + }; + + /** + * @returns promise passed in [constructor] + * This sets the state to Status.Awaiting + */ + public promise = (): Promise => { + if (this._status === Status.Canceled) { + throw Error('Getting a canceled promise is not allowed'); + } else if (this._status !== Status.Idle) { + return this._promise; + } + return new Promise((resolve, reject) => { + this._status = Status.Awaiting; + return this._promise + .then(response => { + if (this._status !== Status.Canceled) { + this._status = Status.Resolved; + return resolve(response); + } + }) + .catch(error => { + if (this._status !== Status.Canceled) { + this._status = Status.Failed; + return reject(error); + } + }); + }); + }; +} diff --git a/x-pack/plugins/monitoring/common/constants.ts b/x-pack/plugins/monitoring/common/constants.ts new file mode 100644 index 000000000000..9a4030f3eb21 --- /dev/null +++ b/x-pack/plugins/monitoring/common/constants.ts @@ -0,0 +1,264 @@ +/* + * 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. + */ + +/** + * Helper string to add as a tag in every logging call + */ +export const LOGGING_TAG = 'monitoring'; +/** + * Helper string to add as a tag in every logging call related to Kibana monitoring + */ +export const KIBANA_MONITORING_LOGGING_TAG = 'kibana-monitoring'; + +/** + * The Monitoring API version is the expected API format that we export and expect to import. + * @type {string} + */ +export const MONITORING_SYSTEM_API_VERSION = '7'; +/** + * The type name used within the Monitoring index to publish Kibana ops stats. + * @type {string} + */ +export const KIBANA_STATS_TYPE_MONITORING = 'kibana_stats'; // similar to KIBANA_STATS_TYPE but rolled up into 10s stats from 5s intervals through ops_buffer +/** + * The type name used within the Monitoring index to publish Kibana stats. + * @type {string} + */ +export const KIBANA_SETTINGS_TYPE = 'kibana_settings'; +/** + * The type name used within the Monitoring index to publish Kibana usage stats. + * NOTE: this string shows as-is in the stats API as a field name for the kibana usage stats + * @type {string} + */ +export const KIBANA_USAGE_TYPE = 'kibana'; + +/* + * Key for the localStorage service + */ +export const STORAGE_KEY = 'xpack.monitoring.data'; + +/** + * Units for derivative metric values + */ +export const NORMALIZED_DERIVATIVE_UNIT = '1s'; + +/* + * Values for column sorting in table options + * @type {number} 1 or -1 + */ +export const EUI_SORT_ASCENDING = 'asc'; +export const EUI_SORT_DESCENDING = 'desc'; +export const SORT_ASCENDING = 1; +export const SORT_DESCENDING = -1; + +/* + * Chart colors + * @type {string} + */ +export const CHART_LINE_COLOR = '#d2d2d2'; +export const CHART_TEXT_COLOR = '#9c9c9c'; + +/* + * Number of cluster alerts to show on overview page + * @type {number} + */ +export const CLUSTER_ALERTS_SEARCH_SIZE = 3; + +/* + * Format for moment-duration-format timestamp-to-duration template if the time diffs are gte 1 month + * @type {string} + */ +export const FORMAT_DURATION_TEMPLATE_LONG = 'M [months] d [days]'; + +/* + * Format for moment-duration-format timestamp-to-duration template if the time diffs are lt 1 month but gt 1 minute + * @type {string} + */ +export const FORMAT_DURATION_TEMPLATE_SHORT = ' d [days] h [hrs] m [min]'; + +/* + * Format for moment-duration-format timestamp-to-duration template if the time diffs are lt 1 minute + * @type {string} + */ +export const FORMAT_DURATION_TEMPLATE_TINY = ' s [seconds]'; + +/* + * Simple unique values for Timestamp to duration flags. These are used for + * determining if calculation should be formatted as "time until" (now to + * timestamp) or "time since" (timestamp to now) + */ +export const CALCULATE_DURATION_SINCE = 'since'; +export const CALCULATE_DURATION_UNTIL = 'until'; + +/** + * In order to show ML Jobs tab in the Elasticsearch section / tab navigation, license must be supported + */ +export const ML_SUPPORTED_LICENSES = ['trial', 'platinum', 'enterprise']; + +/** + * Metadata service URLs for the different cloud services that have constant URLs (e.g., unlike GCP, which is a constant prefix). + * + * @type {Object} + */ +export const CLOUD_METADATA_SERVICES = { + // We explicitly call out the version, 2016-09-02, rather than 'latest' to avoid unexpected changes + AWS_URL: 'http://169.254.169.254/2016-09-02/dynamic/instance-identity/document', + + // 2017-04-02 is the first GA release of this API + AZURE_URL: 'http://169.254.169.254/metadata/instance?api-version=2017-04-02', + + // GCP documentation shows both 'metadata.google.internal' (mostly) and '169.254.169.254' (sometimes) + // To bypass potential DNS changes, the IP was used because it's shared with other cloud services + GCP_URL_PREFIX: 'http://169.254.169.254/computeMetadata/v1/instance', +}; + +/** + * Constants used by Logstash monitoring code + */ +export const LOGSTASH = { + MAJOR_VER_REQD_FOR_PIPELINES: 6, + + /* + * Names ES keys on for different Logstash pipeline queues. + * @type {string} + */ + QUEUE_TYPES: { + MEMORY: 'memory', + PERSISTED: 'persisted', + }, +}; + +export const DEBOUNCE_SLOW_MS = 17; // roughly how long it takes to render a frame at 60fps +export const DEBOUNCE_FAST_MS = 10; // roughly how long it takes to render a frame at 100fps + +/** + * Configuration key for setting the email address used for cluster alert notifications. + */ +export const CLUSTER_ALERTS_ADDRESS_CONFIG_KEY = 'cluster_alerts.email_notifications.email_address'; + +export const STANDALONE_CLUSTER_CLUSTER_UUID = '__standalone_cluster__'; + +export const INDEX_PATTERN = '.monitoring-*-6-*,.monitoring-*-7-*'; +export const INDEX_PATTERN_KIBANA = '.monitoring-kibana-6-*,.monitoring-kibana-7-*'; +export const INDEX_PATTERN_LOGSTASH = '.monitoring-logstash-6-*,.monitoring-logstash-7-*'; +export const INDEX_PATTERN_BEATS = '.monitoring-beats-6-*,.monitoring-beats-7-*'; +export const INDEX_ALERTS = '.monitoring-alerts-6,.monitoring-alerts-7'; +export const INDEX_PATTERN_ELASTICSEARCH = '.monitoring-es-6-*,.monitoring-es-7-*'; + +// This is the unique token that exists in monitoring indices collected by metricbeat +export const METRICBEAT_INDEX_NAME_UNIQUE_TOKEN = '-mb-'; + +// We use this for metricbeat migration to identify specific products that we do not have constants for +export const ELASTICSEARCH_SYSTEM_ID = 'elasticsearch'; + +/** + * The id of the infra source owned by the monitoring plugin. + */ +export const INFRA_SOURCE_ID = 'internal-stack-monitoring'; + +/* + * These constants represent code paths within `getClustersFromRequest` + * that an api call wants to invoke. This is meant as an optimization to + * avoid unnecessary ES queries (looking at you logstash) when the data + * is not used. In the long term, it'd be nice to have separate api calls + * instead of this path logic. + */ +export const CODE_PATH_ALL = 'all'; +export const CODE_PATH_ALERTS = 'alerts'; +export const CODE_PATH_KIBANA = 'kibana'; +export const CODE_PATH_ELASTICSEARCH = 'elasticsearch'; +export const CODE_PATH_ML = 'ml'; +export const CODE_PATH_BEATS = 'beats'; +export const CODE_PATH_LOGSTASH = 'logstash'; +export const CODE_PATH_APM = 'apm'; +export const CODE_PATH_LICENSE = 'license'; +export const CODE_PATH_LOGS = 'logs'; + +/** + * The header sent by telemetry service when hitting Elasticsearch to identify query source + * @type {string} + */ +export const TELEMETRY_QUERY_SOURCE = 'TELEMETRY'; + +/** + * The name of the Kibana System ID used to publish and look up Kibana stats through the Monitoring system. + * @type {string} + */ +export const KIBANA_SYSTEM_ID = 'kibana'; + +/** + * The name of the Beats System ID used to publish and look up Beats stats through the Monitoring system. + * @type {string} + */ +export const BEATS_SYSTEM_ID = 'beats'; + +/** + * The name of the Apm System ID used to publish and look up Apm stats through the Monitoring system. + * @type {string} + */ +export const APM_SYSTEM_ID = 'apm'; + +/** + * The name of the Kibana System ID used to look up Logstash stats through the Monitoring system. + * @type {string} + */ +export const LOGSTASH_SYSTEM_ID = 'logstash'; + +/** + * The name of the Kibana System ID used to look up Reporting stats through the Monitoring system. + * @type {string} + */ +export const REPORTING_SYSTEM_ID = 'reporting'; + +/** + * The amount of time, in milliseconds, to wait between collecting kibana stats from es. + * + * Currently 24 hours kept in sync with reporting interval. + * @type {Number} + */ +export const TELEMETRY_COLLECTION_INTERVAL = 86400000; + +/** + * We want to slowly rollout the migration from watcher-based cluster alerts to + * kibana alerts and we only want to enable the kibana alerts once all + * watcher-based cluster alerts have been migrated so this flag will serve + * as the only way to see the new UI and actually run Kibana alerts. It will + * be false until all alerts have been migrated, then it will be removed + */ +export const KIBANA_ALERTING_ENABLED = false; + +/** + * The prefix for all alert types used by monitoring + */ +export const ALERT_TYPE_PREFIX = 'monitoring_'; + +/** + * This is the alert type id for the license expiration alert + */ +export const ALERT_TYPE_LICENSE_EXPIRATION = `${ALERT_TYPE_PREFIX}alert_type_license_expiration`; + +/** + * A listing of all alert types + */ +export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION]; + +/** + * Matches the id for the built-in in email action type + * See x-pack/legacy/plugins/actions/server/builtin_action_types/email.ts + */ +export const ALERT_ACTION_TYPE_EMAIL = '.email'; + +/** + * The number of alerts that have been migrated + */ +export const NUMBER_OF_MIGRATED_ALERTS = 1; + +/** + * The advanced settings config name for the email address + */ +export const MONITORING_CONFIG_ALERTING_EMAIL_ADDRESS = 'monitoring:alertingEmailAddress'; + +export const ALERT_EMAIL_SERVICES = ['gmail', 'hotmail', 'icloud', 'outlook365', 'ses', 'yahoo']; diff --git a/x-pack/plugins/monitoring/common/format_timestamp_to_duration.js b/x-pack/plugins/monitoring/common/format_timestamp_to_duration.js new file mode 100644 index 000000000000..46c8f7db49b0 --- /dev/null +++ b/x-pack/plugins/monitoring/common/format_timestamp_to_duration.js @@ -0,0 +1,54 @@ +/* + * 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 moment from 'moment'; +import 'moment-duration-format'; +import { + FORMAT_DURATION_TEMPLATE_TINY, + FORMAT_DURATION_TEMPLATE_SHORT, + FORMAT_DURATION_TEMPLATE_LONG, + CALCULATE_DURATION_SINCE, + CALCULATE_DURATION_UNTIL, +} from './constants'; + +/* + * Formats a timestamp string + * @param timestamp: ISO time string + * @param calculationFlag: control "since" or "until" logic + * @param initialTime {Object} moment object (not required) + * @return string + */ +export function formatTimestampToDuration(timestamp, calculationFlag, initialTime) { + initialTime = initialTime || moment(); + let timeDuration; + if (calculationFlag === CALCULATE_DURATION_SINCE) { + timeDuration = moment.duration(initialTime - moment(timestamp)); // since: now - timestamp + } else if (calculationFlag === CALCULATE_DURATION_UNTIL) { + timeDuration = moment.duration(moment(timestamp) - initialTime); // until: timestamp - now + } else { + throw new Error( + '[formatTimestampToDuration] requires a [calculationFlag] parameter to specify format as "since" or "until" the given time.' + ); + } + + // See https://github.com/elastic/x-pack-kibana/issues/3554 + let duration; + if (Math.abs(initialTime.diff(timestamp, 'months')) >= 1) { + // time diff is greater than 1 month, show months / days + duration = moment.duration(timeDuration).format(FORMAT_DURATION_TEMPLATE_LONG); + } else if (Math.abs(initialTime.diff(timestamp, 'minutes')) >= 1) { + // time diff is less than 1 month but greater than a minute, show days / hours / minutes + duration = moment.duration(timeDuration).format(FORMAT_DURATION_TEMPLATE_SHORT); + } else { + // time diff is less than a minute, show seconds + duration = moment.duration(timeDuration).format(FORMAT_DURATION_TEMPLATE_TINY); + } + + return duration + .replace(/ 0 mins$/, '') + .replace(/ 0 hrs$/, '') + .replace(/ 0 days$/, ''); // See https://github.com/jsmreese/moment-duration-format/issues/64 +} diff --git a/x-pack/plugins/monitoring/common/formatting.js b/x-pack/plugins/monitoring/common/formatting.js new file mode 100644 index 000000000000..a3b3ce07c8c7 --- /dev/null +++ b/x-pack/plugins/monitoring/common/formatting.js @@ -0,0 +1,33 @@ +/* + * 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 moment from 'moment-timezone'; + +export const LARGE_FLOAT = '0,0.[00]'; +export const SMALL_FLOAT = '0.[00]'; +export const LARGE_BYTES = '0,0.0 b'; +export const SMALL_BYTES = '0.0 b'; +export const LARGE_ABBREVIATED = '0,0.[0]a'; + +/** + * Format the {@code date} in the user's expected date/time format using their guessed local time zone. + * @param date Either a numeric Unix timestamp or a {@code Date} object + * @returns The date formatted using 'LL LTS' + */ +export function formatDateTimeLocal(date, useUTC = false) { + return useUTC + ? moment.utc(date).format('LL LTS') + : moment.tz(date, moment.tz.guess()).format('LL LTS'); +} + +/** + * Shorten a Logstash Pipeline's hash for display purposes + * @param {string} hash The complete hash + * @return {string} The shortened hash + */ +export function shortenPipelineHash(hash) { + return hash.substr(0, 6); +} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/index.js b/x-pack/plugins/monitoring/common/index.js similarity index 76% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/index.js rename to x-pack/plugins/monitoring/common/index.js index 8ac495f6293b..183396f8f0d7 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/index.js +++ b/x-pack/plugins/monitoring/common/index.js @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { opsBuffer } from './ops_buffer'; +export { formatTimestampToDuration } from './format_timestamp_to_duration'; diff --git a/x-pack/plugins/monitoring/kibana.json b/x-pack/plugins/monitoring/kibana.json new file mode 100644 index 000000000000..8d69937c3677 --- /dev/null +++ b/x-pack/plugins/monitoring/kibana.json @@ -0,0 +1,10 @@ +{ + "id": "monitoring", + "version": "8.0.0", + "kibanaVersion": "kibana", + "configPath": ["monitoring"], + "requiredPlugins": ["usageCollection", "licensing", "features"], + "optionalPlugins": ["alerting", "actions", "infra"], + "server": true, + "ui": false +} diff --git a/x-pack/legacy/plugins/monitoring/__tests__/deprecations.js b/x-pack/plugins/monitoring/server/__tests__/deprecations.js similarity index 75% rename from x-pack/legacy/plugins/monitoring/__tests__/deprecations.js rename to x-pack/plugins/monitoring/server/__tests__/deprecations.js index 3df93bdb24f3..aa8008346af8 100644 --- a/x-pack/legacy/plugins/monitoring/__tests__/deprecations.js +++ b/x-pack/plugins/monitoring/server/__tests__/deprecations.js @@ -11,11 +11,13 @@ import sinon from 'sinon'; describe('monitoring plugin deprecations', function() { let transformDeprecations; + const rename = sinon.stub().returns(() => {}); + const fromPath = 'monitoring'; before(function() { - const deprecations = deprecationsModule(); - transformDeprecations = (settings, log = noop) => { - deprecations.forEach(deprecation => deprecation(settings, log)); + const deprecations = deprecationsModule({ rename }); + transformDeprecations = (settings, fromPath, log = noop) => { + deprecations.forEach(deprecation => deprecation(settings, fromPath, log)); }; }); @@ -30,7 +32,7 @@ describe('monitoring plugin deprecations', function() { }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(false); }); @@ -45,7 +47,7 @@ describe('monitoring plugin deprecations', function() { }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(false); }); @@ -61,7 +63,7 @@ describe('monitoring plugin deprecations', function() { }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(false); }); @@ -76,7 +78,7 @@ describe('monitoring plugin deprecations', function() { }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(true); }); }); @@ -86,7 +88,7 @@ describe('monitoring plugin deprecations', function() { const settings = { elasticsearch: { username: 'elastic' } }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(true); }); @@ -94,7 +96,7 @@ describe('monitoring plugin deprecations', function() { const settings = { elasticsearch: { username: 'otheruser' } }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(false); }); @@ -102,7 +104,7 @@ describe('monitoring plugin deprecations', function() { const settings = { elasticsearch: { username: undefined } }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(false); }); @@ -110,7 +112,7 @@ describe('monitoring plugin deprecations', function() { const settings = { elasticsearch: { ssl: { key: '' } } }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(true); }); @@ -118,7 +120,7 @@ describe('monitoring plugin deprecations', function() { const settings = { elasticsearch: { ssl: { certificate: '' } } }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(true); }); @@ -126,8 +128,17 @@ describe('monitoring plugin deprecations', function() { const settings = { elasticsearch: { ssl: { key: '', certificate: '' } } }; const log = sinon.spy(); - transformDeprecations(settings, log); + transformDeprecations(settings, fromPath, log); expect(log.called).to.be(false); }); }); + + describe('xpack_api_polling_frequency_millis', () => { + it('should call rename for this renamed config key', () => { + const settings = { xpack_api_polling_frequency_millis: 30000 }; + const log = sinon.spy(); + transformDeprecations(settings, fromPath, log); + expect(rename.called).to.be(true); + }); + }); }); diff --git a/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.test.ts b/x-pack/plugins/monitoring/server/alerts/license_expiration.test.ts similarity index 89% rename from x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.test.ts rename to x-pack/plugins/monitoring/server/alerts/license_expiration.test.ts index 1d52ab04dcdb..0773af6e7f07 100644 --- a/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.test.ts +++ b/x-pack/plugins/monitoring/server/alerts/license_expiration.test.ts @@ -11,7 +11,7 @@ import { MONITORING_CONFIG_ALERTING_EMAIL_ADDRESS, } from '../../common/constants'; import { Logger } from 'src/core/server'; -import { AlertServices, AlertInstance } from '../../../../../plugins/alerting/server'; +import { AlertServices, AlertInstance } from '../../../alerting/server'; import { savedObjectsClientMock } from 'src/core/server/mocks'; import { AlertState, @@ -69,18 +69,12 @@ const alertExecutorOptions: LicenseExpirationAlertExecutorOptions = { describe('getLicenseExpiration', () => { const emailAddress = 'foo@foo.com'; - const server: any = { - newPlatform: { - __internals: { - uiSettings: { - asScopedToClient: (): any => ({ - get: () => new Promise(resolve => resolve(emailAddress)), - }), - }, - }, - }, - }; - const getMonitoringCluster: () => void = jest.fn(); + const getUiSettingsService: any = () => ({ + asScopedToClient: (): any => ({ + get: () => new Promise(resolve => resolve(emailAddress)), + }), + }); + const monitoringCluster: any = null; const logger: Logger = { warn: jest.fn(), log: jest.fn(), @@ -99,13 +93,23 @@ describe('getLicenseExpiration', () => { }); it('should have the right id and actionGroups', () => { - const alert = getLicenseExpiration(server, getMonitoringCluster, getLogger, ccrEnabled); + const alert = getLicenseExpiration( + getUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); expect(alert.id).toBe(ALERT_TYPE_LICENSE_EXPIRATION); expect(alert.actionGroups).toEqual([{ id: 'default', name: 'Default' }]); }); it('should return the state if no license is provided', async () => { - const alert = getLicenseExpiration(server, getMonitoringCluster, getLogger, ccrEnabled); + const alert = getLicenseExpiration( + getUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); const services: MockServices | AlertServices = { callCluster: jest.fn(), @@ -125,18 +129,17 @@ describe('getLicenseExpiration', () => { }); it('should log a warning if no email is provided', async () => { - const customServer: any = { - newPlatform: { - __internals: { - uiSettings: { - asScopedToClient: () => ({ - get: () => null, - }), - }, - }, - }, - }; - const alert = getLicenseExpiration(customServer, getMonitoringCluster, getLogger, ccrEnabled); + const customGetUiSettingsService: any = () => ({ + asScopedToClient: () => ({ + get: () => null, + }), + }); + const alert = getLicenseExpiration( + customGetUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); const services = { callCluster: jest.fn( @@ -186,7 +189,12 @@ describe('getLicenseExpiration', () => { } ); - const alert = getLicenseExpiration(server, getMonitoringCluster, getLogger, ccrEnabled); + const alert = getLicenseExpiration( + getUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); const savedObjectsClient = savedObjectsClientMock.create(); savedObjectsClient.get.mockReturnValue( @@ -256,7 +264,12 @@ describe('getLicenseExpiration', () => { return instance; } ); - const alert = getLicenseExpiration(server, getMonitoringCluster, getLogger, ccrEnabled); + const alert = getLicenseExpiration( + getUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); const savedObjectsClient = savedObjectsClientMock.create(); savedObjectsClient.get.mockReturnValue( @@ -332,7 +345,12 @@ describe('getLicenseExpiration', () => { return instance; } ); - const alert = getLicenseExpiration(server, getMonitoringCluster, getLogger, ccrEnabled); + const alert = getLicenseExpiration( + getUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); const savedObjectsClient = savedObjectsClientMock.create(); savedObjectsClient.get.mockReturnValue( @@ -396,7 +414,12 @@ describe('getLicenseExpiration', () => { return instance; } ); - const alert = getLicenseExpiration(server, getMonitoringCluster, getLogger, ccrEnabled); + const alert = getLicenseExpiration( + getUiSettingsService, + monitoringCluster, + getLogger, + ccrEnabled + ); const savedObjectsClient = savedObjectsClientMock.create(); savedObjectsClient.get.mockReturnValue( diff --git a/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts b/x-pack/plugins/monitoring/server/alerts/license_expiration.ts similarity index 91% rename from x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts rename to x-pack/plugins/monitoring/server/alerts/license_expiration.ts index 9ef19e58bada..93397ff3641a 100644 --- a/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts +++ b/x-pack/plugins/monitoring/server/alerts/license_expiration.ts @@ -6,11 +6,10 @@ import moment from 'moment-timezone'; import { get } from 'lodash'; -import { Legacy } from 'kibana'; -import { Logger } from 'src/core/server'; +import { Logger, ICustomClusterClient, UiSettingsServiceStart } from 'src/core/server'; import { i18n } from '@kbn/i18n'; import { ALERT_TYPE_LICENSE_EXPIRATION, INDEX_PATTERN_ELASTICSEARCH } from '../../common/constants'; -import { AlertType } from '../../../../../plugins/alerting/server'; +import { AlertType } from '../../../../plugins/alerting/server'; import { fetchLicenses } from '../lib/alerts/fetch_licenses'; import { fetchDefaultEmailAddress } from '../lib/alerts/fetch_default_email_address'; import { fetchClusters } from '../lib/alerts/fetch_clusters'; @@ -28,21 +27,20 @@ import { executeActions, getUiMessage } from '../lib/alerts/license_expiration.l const EXPIRES_DAYS = [60, 30, 14, 7]; export const getLicenseExpiration = ( - server: Legacy.Server, - getMonitoringCluster: any, - getLogger: (contexts: string[]) => Logger, + getUiSettingsService: () => Promise, + monitoringCluster: ICustomClusterClient, + getLogger: (...scopes: string[]) => Logger, ccsEnabled: boolean ): AlertType => { async function getCallCluster(services: any): Promise { - const monitoringCluster = await getMonitoringCluster(); if (!monitoringCluster) { return services.callCluster; } - return monitoringCluster.callCluster; + return monitoringCluster.callAsInternalUser; } - const logger = getLogger([ALERT_TYPE_LICENSE_EXPIRATION]); + const logger = getLogger(ALERT_TYPE_LICENSE_EXPIRATION); return { id: ALERT_TYPE_LICENSE_EXPIRATION, name: 'Monitoring Alert - License Expiration', @@ -85,7 +83,7 @@ export const getLicenseExpiration = ( return state; } - const uiSettings = server.newPlatform.__internals.uiSettings.asScopedToClient( + const uiSettings = (await getUiSettingsService()).asScopedToClient( services.savedObjectsClient ); const dateFormat: string = await uiSettings.get('dateFormat'); diff --git a/x-pack/legacy/plugins/monitoring/server/alerts/types.d.ts b/x-pack/plugins/monitoring/server/alerts/types.d.ts similarity index 92% rename from x-pack/legacy/plugins/monitoring/server/alerts/types.d.ts rename to x-pack/plugins/monitoring/server/alerts/types.d.ts index 76fc7074e411..ff47d6f2ad4d 100644 --- a/x-pack/legacy/plugins/monitoring/server/alerts/types.d.ts +++ b/x-pack/plugins/monitoring/server/alerts/types.d.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { Moment } from 'moment'; -import { AlertExecutorOptions } from '../../../../../plugins/alerting/server'; +import { AlertExecutorOptions } from '../../../alerting/server'; export interface AlertLicense { status: string; diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/aws.js b/x-pack/plugins/monitoring/server/cloud/__tests__/aws.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/aws.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/aws.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/azure.js b/x-pack/plugins/monitoring/server/cloud/__tests__/azure.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/azure.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/azure.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_detector.js b/x-pack/plugins/monitoring/server/cloud/__tests__/cloud_detector.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_detector.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/cloud_detector.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_response.js b/x-pack/plugins/monitoring/server/cloud/__tests__/cloud_response.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_response.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/cloud_response.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_service.js b/x-pack/plugins/monitoring/server/cloud/__tests__/cloud_service.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_service.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/cloud_service.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_services.js b/x-pack/plugins/monitoring/server/cloud/__tests__/cloud_services.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/cloud_services.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/cloud_services.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/__tests__/gcp.js b/x-pack/plugins/monitoring/server/cloud/__tests__/gcp.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/__tests__/gcp.js rename to x-pack/plugins/monitoring/server/cloud/__tests__/gcp.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/aws.js b/x-pack/plugins/monitoring/server/cloud/aws.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/aws.js rename to x-pack/plugins/monitoring/server/cloud/aws.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/azure.js b/x-pack/plugins/monitoring/server/cloud/azure.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/azure.js rename to x-pack/plugins/monitoring/server/cloud/azure.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/cloud_detector.js b/x-pack/plugins/monitoring/server/cloud/cloud_detector.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/cloud_detector.js rename to x-pack/plugins/monitoring/server/cloud/cloud_detector.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/cloud_response.js b/x-pack/plugins/monitoring/server/cloud/cloud_response.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/cloud_response.js rename to x-pack/plugins/monitoring/server/cloud/cloud_response.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/cloud_service.js b/x-pack/plugins/monitoring/server/cloud/cloud_service.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/cloud_service.js rename to x-pack/plugins/monitoring/server/cloud/cloud_service.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/cloud_services.js b/x-pack/plugins/monitoring/server/cloud/cloud_services.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/cloud_services.js rename to x-pack/plugins/monitoring/server/cloud/cloud_services.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/gcp.js b/x-pack/plugins/monitoring/server/cloud/gcp.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/gcp.js rename to x-pack/plugins/monitoring/server/cloud/gcp.js diff --git a/x-pack/legacy/plugins/monitoring/server/cloud/index.js b/x-pack/plugins/monitoring/server/cloud/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cloud/index.js rename to x-pack/plugins/monitoring/server/cloud/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js similarity index 99% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js rename to x-pack/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js index f6dafb5bb8c7..aa94adb57e65 100644 --- a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js +++ b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/alerts_cluster_search.js @@ -97,6 +97,7 @@ describe('Alerts Cluster Search', () => { expect(alerts[1]).to.eql({ metadata: { severity: 0, + cluster_uuid: cluster.cluster_uuid, link: 'https://www.elastic.co/guide/en/x-pack/6.1/ssl-tls.html', }, diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/alerts_clusters_aggregation.js b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/alerts_clusters_aggregation.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/alerts_clusters_aggregation.js rename to x-pack/plugins/monitoring/server/cluster_alerts/__tests__/alerts_clusters_aggregation.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/check_license.js b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/check_license.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/check_license.js rename to x-pack/plugins/monitoring/server/cluster_alerts/__tests__/check_license.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js similarity index 51% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js rename to x-pack/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js index 5f1ed3f970c2..9fc53cea2f4e 100644 --- a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js +++ b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/fixtures/create_stubs.js @@ -1,10 +1,19 @@ +/* + * 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 sinon from 'sinon'; export function createStubs(mockQueryResult, featureStub) { const callWithRequestStub = sinon.stub().returns(Promise.resolve(mockQueryResult)); const getClusterStub = sinon.stub().returns({ callWithRequest: callWithRequestStub }); const configStub = sinon.stub().returns({ - get: sinon.stub().withArgs('xpack.monitoring.cluster_alerts.enabled').returns(true) + get: sinon + .stub() + .withArgs('xpack.monitoring.cluster_alerts.enabled') + .returns(true), }); return { callWithRequestStub, @@ -14,14 +23,14 @@ export function createStubs(mockQueryResult, featureStub) { plugins: { monitoring: { info: { - feature: featureStub - } + feature: featureStub, + }, }, elasticsearch: { - getCluster: getClusterStub - } - } - } - } + getCluster: getClusterStub, + }, + }, + }, + }, }; -}; +} diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/verify_monitoring_license.js b/x-pack/plugins/monitoring/server/cluster_alerts/__tests__/verify_monitoring_license.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/__tests__/verify_monitoring_license.js rename to x-pack/plugins/monitoring/server/cluster_alerts/__tests__/verify_monitoring_license.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/alerts_cluster_search.js b/x-pack/plugins/monitoring/server/cluster_alerts/alerts_cluster_search.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/alerts_cluster_search.js rename to x-pack/plugins/monitoring/server/cluster_alerts/alerts_cluster_search.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/alerts_clusters_aggregation.js b/x-pack/plugins/monitoring/server/cluster_alerts/alerts_clusters_aggregation.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/alerts_clusters_aggregation.js rename to x-pack/plugins/monitoring/server/cluster_alerts/alerts_clusters_aggregation.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/check_license.js b/x-pack/plugins/monitoring/server/cluster_alerts/check_license.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/check_license.js rename to x-pack/plugins/monitoring/server/cluster_alerts/check_license.js diff --git a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js b/x-pack/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js similarity index 88% rename from x-pack/legacy/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js rename to x-pack/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js index e94f4e08fbdb..71d8051c4598 100644 --- a/x-pack/legacy/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js +++ b/x-pack/plugins/monitoring/server/cluster_alerts/verify_monitoring_license.js @@ -22,11 +22,10 @@ export function verifyMonitoringLicense(server) { if (config.get('monitoring.cluster_alerts.enabled')) { const xpackInfo = get(server.plugins.monitoring, 'info'); if (xpackInfo) { - const monitoringCluster = xpackInfo.feature('monitoring').getLicenseCheckResults(); - + const watcherFeature = xpackInfo.getWatcherFeature(); return { - enabled: monitoringCluster.clusterAlerts.enabled, - message: monitoringCluster.message, + enabled: watcherFeature.isEnabled, + message: xpackInfo.getMessage(), }; } diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts new file mode 100644 index 000000000000..6e5092a11274 --- /dev/null +++ b/x-pack/plugins/monitoring/server/config.ts @@ -0,0 +1,230 @@ +/* + * 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 { schema, TypeOf } from '@kbn/config-schema'; + +const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); +const DEFAULT_API_VERSION = 'master'; + +export const configSchema = schema.object({ + enabled: schema.boolean({ defaultValue: true }), + elasticsearch: schema.object({ + logFetchCount: schema.number({ defaultValue: 10 }), + sniffOnStart: schema.boolean({ defaultValue: false }), + sniffInterval: schema.oneOf([schema.duration(), schema.literal(false)], { + defaultValue: false, + }), + sniffOnConnectionFault: schema.boolean({ defaultValue: false }), + hosts: schema.maybe( + schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })]) + ), + preserveHost: schema.boolean({ defaultValue: true }), + username: schema.maybe( + schema.conditional( + schema.contextRef('dist'), + false, + schema.string({ + validate: () => {}, + }), + schema.string() + ) + ), + password: schema.maybe(schema.string()), + requestHeadersWhitelist: schema.oneOf([schema.string(), schema.arrayOf(schema.string())], { + defaultValue: ['authorization'], + }), + customHeaders: schema.recordOf(schema.string(), schema.string(), { defaultValue: {} }), + shardTimeout: schema.duration({ defaultValue: '30s' }), + requestTimeout: schema.duration({ defaultValue: '30s' }), + pingTimeout: schema.duration({ defaultValue: schema.siblingRef('requestTimeout') }), + startupTimeout: schema.duration({ defaultValue: '5s' }), + logQueries: schema.boolean({ defaultValue: false }), + ssl: schema.object( + { + verificationMode: schema.oneOf( + [schema.literal('none'), schema.literal('certificate'), schema.literal('full')], + { defaultValue: 'full' } + ), + certificateAuthorities: schema.maybe( + schema.oneOf([schema.string(), schema.arrayOf(schema.string(), { minSize: 1 })]) + ), + certificate: schema.maybe(schema.string()), + key: schema.maybe(schema.string()), + keyPassphrase: schema.maybe(schema.string()), + keystore: schema.object({ + path: schema.maybe(schema.string()), + password: schema.maybe(schema.string()), + }), + truststore: schema.object({ + path: schema.maybe(schema.string()), + password: schema.maybe(schema.string()), + }), + alwaysPresentCertificate: schema.boolean({ defaultValue: false }), + }, + { + validate: rawConfig => { + if (rawConfig.key && rawConfig.keystore.path) { + return 'cannot use [key] when [keystore.path] is specified'; + } + if (rawConfig.certificate && rawConfig.keystore.path) { + return 'cannot use [certificate] when [keystore.path] is specified'; + } + }, + } + ), + apiVersion: schema.string({ defaultValue: DEFAULT_API_VERSION }), + healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }), + ignoreVersionMismatch: schema.conditional( + schema.contextRef('dev'), + false, + schema.boolean({ + validate: rawValue => { + if (rawValue === true) { + return '"ignoreVersionMismatch" can only be set to true in development mode'; + } + }, + defaultValue: false, + }), + schema.boolean({ defaultValue: false }) + ), + }), + ui: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + ccs: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), + logs: schema.object({ + index: schema.string({ defaultValue: 'filebeat-*' }), + }), + max_bucket_size: schema.number({ defaultValue: 10000 }), + elasticsearch: schema.object({ + logFetchCount: schema.number({ defaultValue: 10 }), + sniffOnStart: schema.boolean({ defaultValue: false }), + sniffInterval: schema.oneOf([schema.duration(), schema.literal(false)], { + defaultValue: false, + }), + sniffOnConnectionFault: schema.boolean({ defaultValue: false }), + hosts: schema.maybe( + schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })]) + ), + preserveHost: schema.boolean({ defaultValue: true }), + username: schema.maybe( + schema.conditional( + schema.contextRef('dist'), + false, + schema.string({ + validate: rawConfig => { + if (rawConfig === 'elastic') { + return ( + 'value of "elastic" is forbidden. This is a superuser account that can obfuscate ' + + 'privilege-related issues. You should use the "kibana" user instead.' + ); + } + }, + }), + schema.string() + ) + ), + password: schema.maybe(schema.string()), + requestHeadersWhitelist: schema.oneOf([schema.string(), schema.arrayOf(schema.string())], { + defaultValue: ['authorization'], + }), + customHeaders: schema.recordOf(schema.string(), schema.string(), { defaultValue: {} }), + shardTimeout: schema.duration({ defaultValue: '30s' }), + requestTimeout: schema.duration({ defaultValue: '30s' }), + pingTimeout: schema.duration({ defaultValue: schema.siblingRef('requestTimeout') }), + startupTimeout: schema.duration({ defaultValue: '5s' }), + logQueries: schema.boolean({ defaultValue: false }), + ssl: schema.object( + { + verificationMode: schema.oneOf( + [schema.literal('none'), schema.literal('certificate'), schema.literal('full')], + { defaultValue: 'full' } + ), + certificateAuthorities: schema.maybe( + schema.oneOf([schema.string(), schema.arrayOf(schema.string(), { minSize: 1 })]) + ), + certificate: schema.maybe(schema.string()), + key: schema.maybe(schema.string()), + keyPassphrase: schema.maybe(schema.string()), + keystore: schema.object({ + path: schema.maybe(schema.string()), + password: schema.maybe(schema.string()), + }), + truststore: schema.object({ + path: schema.maybe(schema.string()), + password: schema.maybe(schema.string()), + }), + alwaysPresentCertificate: schema.boolean({ defaultValue: false }), + }, + { + validate: rawConfig => { + if (rawConfig.key && rawConfig.keystore.path) { + return 'cannot use [key] when [keystore.path] is specified'; + } + if (rawConfig.certificate && rawConfig.keystore.path) { + return 'cannot use [certificate] when [keystore.path] is specified'; + } + }, + } + ), + apiVersion: schema.string({ defaultValue: DEFAULT_API_VERSION }), + healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }), + ignoreVersionMismatch: schema.conditional( + schema.contextRef('dev'), + false, + schema.boolean({ + validate: rawValue => { + if (rawValue === true) { + return '"ignoreVersionMismatch" can only be set to true in development mode'; + } + }, + defaultValue: false, + }), + schema.boolean({ defaultValue: false }) + ), + }), + container: schema.object({ + elasticsearch: schema.object({ + enabled: schema.boolean({ defaultValue: false }), + }), + logstash: schema.object({ + enabled: schema.boolean({ defaultValue: false }), + }), + }), + min_interval_seconds: schema.number({ defaultValue: 10 }), + show_license_expiration: schema.boolean({ defaultValue: true }), + }), + kibana: schema.object({ + collection: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + interval: schema.number({ defaultValue: 10000 }), // op status metrics get buffered at `ops.interval` and flushed to the bulk endpoint at this interval + }), + }), + cluster_alerts: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + email_notifications: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + email_address: schema.string({ defaultValue: '' }), + }), + }), + licensing: schema.object({ + api_polling_frequency: schema.duration({ + defaultValue: '30s', + }), + }), + agent: schema.object({ + interval: schema.string({ defaultValue: '10s' }), + // TOOD: NP + // .regex(/[\d\.]+[yMwdhms]/) + }), + tests: schema.object({ + cloud_detector: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), + }), +}); + +export type MonitoringConfig = TypeOf; diff --git a/x-pack/legacy/plugins/monitoring/deprecations.js b/x-pack/plugins/monitoring/server/deprecations.ts similarity index 54% rename from x-pack/legacy/plugins/monitoring/deprecations.js rename to x-pack/plugins/monitoring/server/deprecations.ts index ae8650fd3b26..dfe8ab31f972 100644 --- a/x-pack/legacy/plugins/monitoring/deprecations.js +++ b/x-pack/plugins/monitoring/server/deprecations.ts @@ -5,7 +5,8 @@ */ import { get } from 'lodash'; -import { CLUSTER_ALERTS_ADDRESS_CONFIG_KEY, KIBANA_ALERTING_ENABLED } from './common/constants'; +import { ConfigDeprecationFactory, ConfigDeprecation } from 'kibana/server'; +import { CLUSTER_ALERTS_ADDRESS_CONFIG_KEY } from '../common/constants'; /** * Re-writes deprecated user-defined config settings and logs warnings as a @@ -15,53 +16,45 @@ import { CLUSTER_ALERTS_ADDRESS_CONFIG_KEY, KIBANA_ALERTING_ENABLED } from './co * major version! * @return {Array} array of rename operations and callback function for rename logging */ -export const deprecations = () => { +export const deprecations = ({ rename }: ConfigDeprecationFactory): ConfigDeprecation[] => { return [ - (settings, log) => { - const clusterAlertsEnabled = get(settings, 'cluster_alerts.enabled'); + (config, fromPath, logger) => { + const clusterAlertsEnabled = get(config, 'cluster_alerts.enabled'); const emailNotificationsEnabled = - clusterAlertsEnabled && get(settings, 'cluster_alerts.email_notifications.enabled'); - if (emailNotificationsEnabled) { - if (KIBANA_ALERTING_ENABLED) { - if (get(settings, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) { - log( - `Config key "${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}" is deprecated. Please configure the email adddress through the Stack Monitoring UI instead."` - ); - } - } else { - if (!get(settings, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) { - log( - `Config key "${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}" will be required for email notifications to work in 7.0."` - ); - } - } + clusterAlertsEnabled && get(config, 'cluster_alerts.email_notifications.enabled'); + if (emailNotificationsEnabled && !get(config, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) { + logger( + `Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 7.0."` + ); } + return config; }, - (settings, log) => { - const fromPath = 'monitoring.elasticsearch'; - const es = get(settings, 'elasticsearch'); + (config, fromPath, logger) => { + const es: Record = get(config, 'elasticsearch'); if (es) { if (es.username === 'elastic') { - log( + logger( `Setting [${fromPath}.username] to "elastic" is deprecated. You should use the "kibana" user instead.` ); } } + return config; }, - (settings, log) => { - const fromPath = 'monitoring.elasticsearch.ssl'; - const ssl = get(settings, 'elasticsearch.ssl'); + (config, fromPath, logger) => { + const ssl: Record = get(config, 'elasticsearch.ssl'); if (ssl) { if (ssl.key !== undefined && ssl.certificate === undefined) { - log( + logger( `Setting [${fromPath}.key] without [${fromPath}.certificate] is deprecated. This has no effect, you should use both settings to enable TLS client authentication to Elasticsearch.` ); } else if (ssl.certificate !== undefined && ssl.key === undefined) { - log( + logger( `Setting [${fromPath}.certificate] without [${fromPath}.key] is deprecated. This has no effect, you should use both settings to enable TLS client authentication to Elasticsearch.` ); } } + return config; }, + rename('xpack_api_polling_frequency_millis', 'licensing.api_polling_frequency'), ]; }; diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/README.md b/x-pack/plugins/monitoring/server/es_client/README.md similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/es_client/README.md rename to x-pack/plugins/monitoring/server/es_client/README.md diff --git a/x-pack/plugins/monitoring/server/es_client/__tests__/instantiate_client.js b/x-pack/plugins/monitoring/server/es_client/__tests__/instantiate_client.js new file mode 100644 index 000000000000..a18b7cc8b79f --- /dev/null +++ b/x-pack/plugins/monitoring/server/es_client/__tests__/instantiate_client.js @@ -0,0 +1,125 @@ +/* + * 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 expect from '@kbn/expect'; +import sinon from 'sinon'; +import { instantiateClient, hasMonitoringCluster } from '../instantiate_client'; + +const server = { + monitoring: { + ui: { + elasticsearch: { + hosts: [], + username: 'monitoring-user-internal-test', + password: 'monitoring-p@ssw0rd!-internal-test', + ssl: {}, + customHeaders: { + 'x-custom-headers-test': 'connection-monitoring', + }, + }, + }, + }, +}; +const serverWithUrl = { + monitoring: { + ui: { + elasticsearch: { + hosts: ['http://monitoring-cluster.test:9200'], + username: 'monitoring-user-internal-test', + password: 'monitoring-p@ssw0rd!-internal-test', + ssl: {}, + customHeaders: { + 'x-custom-headers-test': 'connection-monitoring', + }, + }, + }, + }, +}; + +const createClient = sinon.stub(); +const log = { info: sinon.stub() }; + +describe('Instantiate Client', () => { + afterEach(() => { + createClient.resetHistory(); + log.info.resetHistory(); + }); + + describe('Logging', () => { + it('logs that the config was sourced from the production options', () => { + instantiateClient(server.monitoring.ui.elasticsearch, log, createClient); + + expect(log.info.getCall(0).args).to.eql(['config sourced from: production cluster']); + }); + + it('logs that the config was sourced from the monitoring options', () => { + instantiateClient(serverWithUrl.monitoring.ui.elasticsearch, log, createClient); + + expect(log.info.getCall(0).args).to.eql(['config sourced from: monitoring cluster']); + }); + }); + + describe('Custom Headers Configuration', () => { + it('Does not add xpack.monitoring.elasticsearch.customHeaders if connected to production cluster', () => { + instantiateClient(server.monitoring.ui.elasticsearch, log, createClient); + + const createClusterCall = createClient.getCall(0); + + sinon.assert.calledOnce(createClient); + expect(createClusterCall.args[0]).to.be('monitoring'); + expect(createClusterCall.args[1].customHeaders).to.eql(undefined); + }); + + it('Adds xpack.monitoring.elasticsearch.customHeaders if connected to monitoring cluster', () => { + instantiateClient(serverWithUrl.monitoring.ui.elasticsearch, log, createClient); + + const createClusterCall = createClient.getCall(0); + + sinon.assert.calledOnce(createClient); + expect(createClusterCall.args[0]).to.be('monitoring'); + expect(createClusterCall.args[1].customHeaders).to.eql({ + 'x-custom-headers-test': 'connection-monitoring', + }); + }); + }); + + describe('Use a connection to production cluster', () => { + it('exposes an authenticated client using production host settings', () => { + instantiateClient(server.monitoring.ui.elasticsearch, log, createClient); + + const createClusterCall = createClient.getCall(0); + const createClientOptions = createClusterCall.args[1]; + + sinon.assert.calledOnce(createClient); + expect(createClusterCall.args[0]).to.be('monitoring'); + expect(createClientOptions.hosts).to.eql(undefined); + }); + }); + + describe('Use a connection to monitoring cluster', () => { + it('exposes an authenticated client using monitoring host settings', () => { + instantiateClient(serverWithUrl.monitoring.ui.elasticsearch, log, createClient); + const createClusterCall = createClient.getCall(0); + const createClientOptions = createClusterCall.args[1]; + + sinon.assert.calledOnce(createClient); + expect(createClusterCall.args[0]).to.be('monitoring'); + expect(createClientOptions.hosts[0]).to.eql('http://monitoring-cluster.test:9200'); + expect(createClientOptions.username).to.eql('monitoring-user-internal-test'); + expect(createClientOptions.password).to.eql('monitoring-p@ssw0rd!-internal-test'); + }); + }); + + describe('hasMonitoringCluster', () => { + it('returns true if monitoring is configured', () => { + expect(hasMonitoringCluster(serverWithUrl.monitoring.ui.elasticsearch)).to.be(true); + }); + + it('returns false if monitoring is not configured', () => { + expect(hasMonitoringCluster(server.monitoring.ui.elasticsearch)).to.be(false); + }); + }); +}); diff --git a/x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js b/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts similarity index 60% rename from x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js rename to x-pack/plugins/monitoring/server/es_client/instantiate_client.ts index 671c6cdaaed7..280d8aab7030 100644 --- a/x-pack/legacy/plugins/monitoring/server/es_client/instantiate_client.js +++ b/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts @@ -4,9 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { bindKey, once } from 'lodash'; +import { Logger, ElasticsearchClientConfig, ICustomClusterClient } from 'kibana/server'; +// @ts-ignore import { monitoringBulk } from '../kibana_monitoring/lib/monitoring_bulk'; -import { LOGGING_TAG } from '../../common/constants'; +import { MonitoringElasticsearchConfig } from '../types'; /* Provide a dedicated Elasticsearch client for Monitoring * The connection options can be customized for the Monitoring application @@ -14,22 +15,26 @@ import { LOGGING_TAG } from '../../common/constants'; * Kibana itself is connected to a production cluster. */ -export function exposeClient({ elasticsearchConfig, events, log, elasticsearchPlugin }) { +export function instantiateClient( + elasticsearchConfig: any, + log: Logger, + createClient: ( + type: string, + clientConfig?: Partial + ) => ICustomClusterClient +) { const isMonitoringCluster = hasMonitoringCluster(elasticsearchConfig); - const cluster = elasticsearchPlugin.createCluster('monitoring', { + const cluster = createClient('monitoring', { ...(isMonitoringCluster ? elasticsearchConfig : {}), plugins: [monitoringBulk], logQueries: Boolean(elasticsearchConfig.logQueries), }); - events.on('stop', bindKey(cluster, 'close')); const configSource = isMonitoringCluster ? 'monitoring' : 'production'; - log([LOGGING_TAG, 'es-client'], `config sourced from: ${configSource} cluster`); + log.info(`config sourced from: ${configSource} cluster`); return cluster; } -export function hasMonitoringCluster(config) { - return Boolean(config.hosts && config.hosts.length); +export function hasMonitoringCluster(config: MonitoringElasticsearchConfig) { + return Boolean(config.hosts && config.hosts[0]); } - -export const instantiateClient = once(exposeClient); diff --git a/x-pack/plugins/monitoring/server/index.ts b/x-pack/plugins/monitoring/server/index.ts new file mode 100644 index 000000000000..a992037fc608 --- /dev/null +++ b/x-pack/plugins/monitoring/server/index.ts @@ -0,0 +1,17 @@ +/* + * 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 { TypeOf } from '@kbn/config-schema'; +import { PluginInitializerContext, PluginConfigDescriptor } from '../../../../src/core/server'; +import { Plugin } from './plugin'; +import { configSchema } from './config'; +import { deprecations } from './deprecations'; + +export const plugin = (initContext: PluginInitializerContext) => new Plugin(initContext); +export const config: PluginConfigDescriptor> = { + schema: configSchema, + deprecations, +}; diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js b/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js b/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js similarity index 82% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js index 7417e6ca804d..c09a08f61dc0 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js @@ -5,20 +5,12 @@ */ import { defaultsDeep, uniq, compact, get } from 'lodash'; -import { callClusterFactory } from '../../../xpack_main'; -import { - LOGGING_TAG, - KIBANA_MONITORING_LOGGING_TAG, - TELEMETRY_COLLECTION_INTERVAL, -} from '../../common/constants'; +import { TELEMETRY_COLLECTION_INTERVAL } from '../../common/constants'; -import { sendBulkPayload, monitoringBulk, getKibanaInfoForStats } from './lib'; -import { parseElasticsearchConfig } from '../es_client/parse_elasticsearch_config'; +import { sendBulkPayload, monitoringBulk } from './lib'; import { hasMonitoringCluster } from '../es_client/instantiate_client'; -const LOGGING_TAGS = [LOGGING_TAG, KIBANA_MONITORING_LOGGING_TAG]; - /* * Handles internal Kibana stats collection and uploading data to Monitoring * bulk endpoint. @@ -36,7 +28,7 @@ const LOGGING_TAGS = [LOGGING_TAG, KIBANA_MONITORING_LOGGING_TAG]; * @param {Object} xpackInfo server.plugins.xpack_main.info object */ export class BulkUploader { - constructor({ config, log, interval, elasticsearchPlugin, kbnServerStatus, kbnServerVersion }) { + constructor({ config, log, interval, elasticsearch, kibanaStats }) { if (typeof interval !== 'number') { throw new Error('interval number of milliseconds is required'); } @@ -53,39 +45,27 @@ export class BulkUploader { // Limit sending and fetching usage to once per day once usage is successfully stored // into the monitoring indices. this._usageInterval = TELEMETRY_COLLECTION_INTERVAL; + this._log = log; - this._log = { - debug: message => log(['debug', ...LOGGING_TAGS], message), - info: message => log(['info', ...LOGGING_TAGS], message), - warn: message => log(['warning', ...LOGGING_TAGS], message), - }; - - this._cluster = elasticsearchPlugin.createCluster('admin', { + this._cluster = elasticsearch.createClient('admin', { plugins: [monitoringBulk], }); - const directConfig = parseElasticsearchConfig(config, 'monitoring.elasticsearch'); - if (hasMonitoringCluster(directConfig)) { + if (hasMonitoringCluster(config.elasticsearch)) { this._log.info(`Detected direct connection to monitoring cluster`); this._hasDirectConnectionToMonitoringCluster = true; - this._cluster = elasticsearchPlugin.createCluster('monitoring-direct', directConfig); - elasticsearchPlugin - .getCluster('admin') - .callWithInternalUser('info') - .then(data => { - this._productionClusterUuid = get(data, 'cluster_uuid'); - }); + this._cluster = elasticsearch.createClient('monitoring-direct', config.elasticsearch); + elasticsearch.adminClient.callAsInternalUser('info').then(data => { + this._productionClusterUuid = get(data, 'cluster_uuid'); + }); } - this._callClusterWithInternalUser = callClusterFactory({ - plugins: { elasticsearch: elasticsearchPlugin }, - }).getCallClusterInternal(); - this._getKibanaInfoForStats = () => - getKibanaInfoForStats({ - kbnServerStatus, - kbnServerVersion, - config, - }); + this.kibanaStats = kibanaStats; + this.kibanaStatusGetter = null; + } + + setKibanaStatusGetter(getter) { + this.kibanaStatusGetter = getter; } filterCollectorSet(usageCollection) { @@ -166,7 +146,7 @@ export class BulkUploader { return; } - const data = await usageCollection.bulkFetch(this._callClusterWithInternalUser); + const data = await usageCollection.bulkFetch(this._cluster.callAsInternalUser); const payload = this.toBulkUploadFormat(compact(data), usageCollection); if (payload) { try { @@ -208,6 +188,13 @@ export class BulkUploader { ); } + getKibanaStats() { + return { + ...this.kibanaStats, + status: this.kibanaStatusGetter(), + }; + } + /* * Bulk stats are transformed into a bulk upload format * Non-legacy transformation is done in CollectorSet.toApiStats @@ -265,7 +252,7 @@ export class BulkUploader { ...accum, { index: { _type: type } }, { - kibana: this._getKibanaInfoForStats(), + kibana: this.getKibanaStats(), ...typesNested[type], }, ]; diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/check_for_email_value.js b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/check_for_email_value.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/check_for_email_value.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/check_for_email_value.js diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/get_default_admin_email.js b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/get_default_admin_email.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/get_default_admin_email.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/collectors/__tests__/get_default_admin_email.js diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.js b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.ts similarity index 83% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.ts index ffb4ea583107..2c40ac56e19e 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_kibana_usage_collector.ts @@ -5,6 +5,7 @@ */ import { get, snakeCase } from 'lodash'; +import { CallCluster } from 'src/legacy/core_plugins/elasticsearch'; import { KIBANA_USAGE_TYPE, KIBANA_STATS_TYPE_MONITORING } from '../../../common/constants'; const TYPES = [ @@ -19,14 +20,13 @@ const TYPES = [ /** * Fetches saved object counts by querying the .kibana index */ -export function getKibanaUsageCollector(usageCollection, config) { +export function getKibanaUsageCollector(usageCollection: any, kibanaIndex: string) { return usageCollection.makeUsageCollector({ type: KIBANA_USAGE_TYPE, isReady: () => true, - async fetch(callCluster) { - const index = config.get('kibana.index'); + async fetch(callCluster: CallCluster) { const savedObjectCountSearchParams = { - index, + index: kibanaIndex, ignoreUnavailable: true, filterPath: 'aggregations.types.buckets', body: { @@ -43,11 +43,11 @@ export function getKibanaUsageCollector(usageCollection, config) { }; const resp = await callCluster('search', savedObjectCountSearchParams); - const buckets = get(resp, 'aggregations.types.buckets', []); + const buckets: any = get(resp, 'aggregations.types.buckets', []); // get the doc_count from each bucket const bucketCounts = buckets.reduce( - (acc, bucket) => ({ + (acc: any, bucket: any) => ({ ...acc, [bucket.key]: bucket.doc_count, }), @@ -55,7 +55,7 @@ export function getKibanaUsageCollector(usageCollection, config) { ); return { - index, + index: kibanaIndex, ...TYPES.reduce( (acc, type) => ({ // combine the bucketCounts and 0s for types that don't have documents @@ -74,7 +74,7 @@ export function getKibanaUsageCollector(usageCollection, config) { * 1. Make this data part of the "kibana_stats" type * 2. Organize the payload in the usage namespace of the data payload (usage.index, etc) */ - formatForBulkUpload: result => { + formatForBulkUpload: (result: any) => { return { type: KIBANA_STATS_TYPE_MONITORING, payload: { diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.ts b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.ts new file mode 100644 index 000000000000..00197e98948b --- /dev/null +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_ops_stats_collector.ts @@ -0,0 +1,37 @@ +/* + * 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 { Observable } from 'rxjs'; +import moment from 'moment'; +import { OpsMetrics } from 'kibana/server'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { KIBANA_STATS_TYPE_MONITORING } from '../../../common/constants'; + +interface MonitoringOpsMetrics extends OpsMetrics { + timestamp: string; +} + +/* + * Initialize a collector for Kibana Ops Stats + */ +export function getOpsStatsCollector( + usageCollection: UsageCollectionSetup, + metrics$: Observable +) { + let lastMetrics: MonitoringOpsMetrics | null = null; + metrics$.subscribe(metrics => { + lastMetrics = { + ...metrics, + timestamp: moment.utc().toISOString(), + }; + }); + + return usageCollection.makeStatsCollector({ + type: KIBANA_STATS_TYPE_MONITORING, + isReady: () => !!lastMetrics, + fetch: () => lastMetrics, + }); +} diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.js b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts similarity index 74% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts index f51e7d22a0c7..63e1dbc40078 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts @@ -4,34 +4,29 @@ * you may not use this file except in compliance with the Elastic License. */ -import { CLUSTER_ALERTS_ADDRESS_CONFIG_KEY, KIBANA_SETTINGS_TYPE } from '../../../common/constants'; +import { KIBANA_SETTINGS_TYPE } from '../../../common/constants'; +import { MonitoringConfig } from '../../config'; /* * Check if Cluster Alert email notifications is enabled in config * If so, get email from kibana.yml */ -export async function getDefaultAdminEmail(config) { - if (!config.get('monitoring.cluster_alerts.email_notifications.enabled')) { +export async function getDefaultAdminEmail(config: MonitoringConfig) { + if (!config.cluster_alerts.email_notifications.enabled) { return null; } - - const emailAddressConfigKey = `monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`; - const configuredEmailAddress = config.get(emailAddressConfigKey); - - return configuredEmailAddress || null; + return config.cluster_alerts.email_notifications.email_address || null; } // we use shouldUseNull to determine if we need to send nulls; we only send nulls if the last email wasn't null let shouldUseNull = true; export async function checkForEmailValue( - config, - callCluster, - log, + config: MonitoringConfig, _shouldUseNull = shouldUseNull, _getDefaultAdminEmail = getDefaultAdminEmail ) { - const defaultAdminEmail = await _getDefaultAdminEmail(config, callCluster, log); + const defaultAdminEmail = await _getDefaultAdminEmail(config); // Allow null so clearing the advanced setting will be reflected in the data const isAcceptableNull = defaultAdminEmail === null && _shouldUseNull; @@ -46,13 +41,13 @@ export async function checkForEmailValue( } } -export function getSettingsCollector(usageCollection, config) { +export function getSettingsCollector(usageCollection: any, config: MonitoringConfig) { return usageCollection.makeStatsCollector({ type: KIBANA_SETTINGS_TYPE, isReady: () => true, - async fetch(callCluster) { + async fetch() { let kibanaSettingsData; - const defaultAdminEmail = await checkForEmailValue(config, callCluster, this.log); + const defaultAdminEmail = await checkForEmailValue(config); // skip everything if defaultAdminEmail === undefined if (defaultAdminEmail || (defaultAdminEmail === null && shouldUseNull)) { @@ -72,7 +67,7 @@ export function getSettingsCollector(usageCollection, config) { // returns undefined if there was no result return kibanaSettingsData; }, - getEmailValueStructure(email) { + getEmailValueStructure(email: string) { return { xpack: { default_admin_email: email, diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/index.js b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/index.ts similarity index 66% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/index.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/collectors/index.ts index 1099a23dea10..e41b1512f1b2 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/collectors/index.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/index.ts @@ -3,15 +3,20 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - +import { Observable } from 'rxjs'; +import { OpsMetrics } from 'kibana/server'; import { getKibanaUsageCollector } from './get_kibana_usage_collector'; import { getOpsStatsCollector } from './get_ops_stats_collector'; import { getSettingsCollector } from './get_settings_collector'; +import { MonitoringConfig } from '../../config'; -export function registerCollectors(usageCollection, collectorsConfigs) { - const { config } = collectorsConfigs; - - usageCollection.registerCollector(getOpsStatsCollector(usageCollection, collectorsConfigs)); - usageCollection.registerCollector(getKibanaUsageCollector(usageCollection, config)); +export function registerCollectors( + usageCollection: any, + config: MonitoringConfig, + opsMetrics$: Observable, + kibanaIndex: string +) { + usageCollection.registerCollector(getOpsStatsCollector(usageCollection, opsMetrics$)); + usageCollection.registerCollector(getKibanaUsageCollector(usageCollection, kibanaIndex)); usageCollection.registerCollector(getSettingsCollector(usageCollection, config)); } diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/index.js b/x-pack/plugins/monitoring/server/kibana_monitoring/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/index.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/init.js b/x-pack/plugins/monitoring/server/kibana_monitoring/init.js similarity index 91% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/init.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/init.js index 3c02e2be58de..79aafb8f361f 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/init.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/init.js @@ -16,7 +16,7 @@ import { BulkUploader } from './bulk_uploader'; * @param {Object} server HapiJS server instance */ export function initBulkUploader({ config, ...params }) { - const interval = config.get('monitoring.kibana.collection.interval'); + const interval = config.kibana.collection.interval; return new BulkUploader({ interval, config, diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/index.js b/x-pack/plugins/monitoring/server/kibana_monitoring/lib/index.js similarity index 83% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/index.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/lib/index.js index 56a2f48de88d..c5fdd29d4306 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/index.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/lib/index.js @@ -6,4 +6,3 @@ export { sendBulkPayload } from './send_bulk_payload'; export { monitoringBulk } from './monitoring_bulk'; -export { getKibanaInfoForStats } from './get_kibana_info_for_stats'; diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/monitoring_bulk.js b/x-pack/plugins/monitoring/server/kibana_monitoring/lib/monitoring_bulk.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/monitoring_bulk.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/lib/monitoring_bulk.js diff --git a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js b/x-pack/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js similarity index 94% rename from x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js rename to x-pack/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js index c378c0ad0fa0..9607b45d7e40 100644 --- a/x-pack/legacy/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/lib/send_bulk_payload.js @@ -56,12 +56,12 @@ export async function sendBulkPayload( ); } const formattedPayload = formatForNormalBulkEndpoint(payload, productionClusterUuid); - return await cluster.callWithInternalUser('bulk', { + return await cluster.callAsInternalUser('bulk', { body: formattedPayload, }); } - return cluster.callWithInternalUser('monitoring.bulk', { + return cluster.callAsInternalUser('monitoring.bulk', { system_id: KIBANA_SYSTEM_ID, system_api_version: MONITORING_SYSTEM_API_VERSION, interval: interval + 'ms', diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_auto.js b/x-pack/plugins/monitoring/server/lib/__tests__/calculate_auto.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_auto.js rename to x-pack/plugins/monitoring/server/lib/__tests__/calculate_auto.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_availabiilty.js b/x-pack/plugins/monitoring/server/lib/__tests__/calculate_availabiilty.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_availabiilty.js rename to x-pack/plugins/monitoring/server/lib/__tests__/calculate_availabiilty.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_overall_status.js b/x-pack/plugins/monitoring/server/lib/__tests__/calculate_overall_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_overall_status.js rename to x-pack/plugins/monitoring/server/lib/__tests__/calculate_overall_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_rate.js b/x-pack/plugins/monitoring/server/lib/__tests__/calculate_rate.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_rate.js rename to x-pack/plugins/monitoring/server/lib/__tests__/calculate_rate.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_timeseries_interval.js b/x-pack/plugins/monitoring/server/lib/__tests__/calculate_timeseries_interval.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/calculate_timeseries_interval.js rename to x-pack/plugins/monitoring/server/lib/__tests__/calculate_timeseries_interval.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/ccs_utils.js b/x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js similarity index 79% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/ccs_utils.js rename to x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js index ad02807b5585..d17253dc0169 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/ccs_utils.js +++ b/x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js @@ -53,9 +53,11 @@ describe('ccs_utils', () => { const abcPattern = prefixIndexPattern(config, indexPattern, 'aBc'); const underscorePattern = prefixIndexPattern(config, indexPattern, 'cluster_one'); - expect(abcPattern).to.eql('aBc:.monitoring-xyz-1-*,aBc:.monitoring-xyz-2-*'); + expect(abcPattern).to.eql( + 'aBc:.monitoring-xyz-1-*,aBc:.monitoring-xyz-2-*,aBc:monitoring-xyz-1-*,aBc:monitoring-xyz-2-*' + ); expect(underscorePattern).to.eql( - 'cluster_one:.monitoring-xyz-1-*,cluster_one:.monitoring-xyz-2-*' + 'cluster_one:.monitoring-xyz-1-*,cluster_one:.monitoring-xyz-2-*,cluster_one:monitoring-xyz-1-*,cluster_one:monitoring-xyz-2-*' ); expect(get.callCount).to.eql(2); }); @@ -69,7 +71,11 @@ describe('ccs_utils', () => { const pattern = prefixIndexPattern(config, indexPattern, '*'); // it should have BOTH patterns so that it searches all CCS clusters and the local cluster - expect(pattern).to.eql('*:.monitoring-xyz-1-*,*:.monitoring-xyz-2-*' + ',' + indexPattern); + expect(pattern).to.eql( + '*:.monitoring-xyz-1-*,*:.monitoring-xyz-2-*,*:monitoring-xyz-1-*,*:monitoring-xyz-2-*' + + ',' + + indexPattern + ); expect(get.callCount).to.eql(1); }); }); @@ -77,18 +83,25 @@ describe('ccs_utils', () => { describe('parseCrossClusterPrefix', () => { it('returns ccs prefix for index with one', () => { expect(parseCrossClusterPrefix('abc:.monitoring-es-6-2017.07.28')).to.eql('abc'); + expect(parseCrossClusterPrefix('abc:monitoring-es-6-2017.07.28')).to.eql('abc'); expect(parseCrossClusterPrefix('abc_123:.monitoring-es-6-2017.07.28')).to.eql('abc_123'); + expect(parseCrossClusterPrefix('abc_123:monitoring-es-6-2017.07.28')).to.eql('abc_123'); expect(parseCrossClusterPrefix('broken:example:.monitoring-es-6-2017.07.28')).to.eql( 'broken' ); + expect(parseCrossClusterPrefix('broken:example:monitoring-es-6-2017.07.28')).to.eql('broken'); expect(parseCrossClusterPrefix('with-a-dash:.monitoring-es-6-2017.07.28')).to.eql( 'with-a-dash' ); + expect(parseCrossClusterPrefix('with-a-dash:monitoring-es-6-2017.07.28')).to.eql( + 'with-a-dash' + ); expect(parseCrossClusterPrefix('something:not-monitoring')).to.eql('something'); }); it('returns null when no prefix exists', () => { expect(parseCrossClusterPrefix('.monitoring-es-6-2017.07.28')).to.be(null); + expect(parseCrossClusterPrefix('monitoring-es-6-2017.07.28')).to.be(null); expect(parseCrossClusterPrefix('random')).to.be(null); }); }); diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/create_query.js b/x-pack/plugins/monitoring/server/lib/__tests__/create_query.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/create_query.js rename to x-pack/plugins/monitoring/server/lib/__tests__/create_query.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/helpers.js b/x-pack/plugins/monitoring/server/lib/__tests__/helpers.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/helpers.js rename to x-pack/plugins/monitoring/server/lib/__tests__/helpers.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/__tests__/process_version_string.js b/x-pack/plugins/monitoring/server/lib/__tests__/process_version_string.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/__tests__/process_version_string.js rename to x-pack/plugins/monitoring/server/lib/__tests__/process_version_string.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_available_ccs.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_available_ccs.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_available_ccs.test.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_available_ccs.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_available_ccs.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_available_ccs.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_available_ccs.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_available_ccs.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_clusters.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_clusters.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_clusters.test.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_clusters.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_clusters.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_clusters.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_clusters.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_clusters.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts similarity index 88% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts index 25b09b956038..ae914c7a2ace 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts +++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_default_email_address.test.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { fetchDefaultEmailAddress } from './fetch_default_email_address'; -import { uiSettingsServiceMock } from '../../../../../../../src/core/server/mocks'; +import { uiSettingsServiceMock } from '../../../../../../src/core/server/mocks'; describe('fetchDefaultEmailAddress', () => { it('get the email address', async () => { diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_default_email_address.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_default_email_address.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_default_email_address.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_default_email_address.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_licenses.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_licenses.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_licenses.test.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_licenses.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_licenses.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_licenses.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_licenses.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_licenses.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_status.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_status.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/fetch_status.ts rename to x-pack/plugins/monitoring/server/lib/alerts/fetch_status.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.test.ts rename to x-pack/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.ts b/x-pack/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.ts rename to x-pack/plugins/monitoring/server/lib/alerts/get_ccs_index_pattern.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/license_expiration.lib.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/license_expiration.lib.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/license_expiration.lib.test.ts rename to x-pack/plugins/monitoring/server/lib/alerts/license_expiration.lib.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts b/x-pack/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts similarity index 96% rename from x-pack/legacy/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts rename to x-pack/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts index 520cb31e151a..41b68d69bbd2 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts +++ b/x-pack/plugins/monitoring/server/lib/alerts/license_expiration.lib.ts @@ -5,7 +5,7 @@ */ import { Moment } from 'moment-timezone'; import { i18n } from '@kbn/i18n'; -import { AlertInstance } from '../../../../../../plugins/alerting/server'; +import { AlertInstance } from '../../../../alerting/server'; import { AlertLicense } from '../../alerts/types'; const RESOLVED_SUBJECT = i18n.translate( diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/__tests__/get_apms.js b/x-pack/plugins/monitoring/server/lib/apm/__tests__/get_apms.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/__tests__/get_apms.js rename to x-pack/plugins/monitoring/server/lib/apm/__tests__/get_apms.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/_apm_stats.js b/x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/_apm_stats.js rename to x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/_get_time_of_last_event.js b/x-pack/plugins/monitoring/server/lib/apm/_get_time_of_last_event.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/_get_time_of_last_event.js rename to x-pack/plugins/monitoring/server/lib/apm/_get_time_of_last_event.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/create_apm_query.js b/x-pack/plugins/monitoring/server/lib/apm/create_apm_query.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/create_apm_query.js rename to x-pack/plugins/monitoring/server/lib/apm/create_apm_query.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/get_apm_info.js b/x-pack/plugins/monitoring/server/lib/apm/get_apm_info.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/get_apm_info.js rename to x-pack/plugins/monitoring/server/lib/apm/get_apm_info.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/get_apms.js b/x-pack/plugins/monitoring/server/lib/apm/get_apms.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/get_apms.js rename to x-pack/plugins/monitoring/server/lib/apm/get_apms.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js b/x-pack/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js rename to x-pack/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/get_stats.js b/x-pack/plugins/monitoring/server/lib/apm/get_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/get_stats.js rename to x-pack/plugins/monitoring/server/lib/apm/get_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/apm/index.js b/x-pack/plugins/monitoring/server/lib/apm/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/apm/index.js rename to x-pack/plugins/monitoring/server/lib/apm/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js similarity index 61% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js index 7771f916ae28..f6e86ae92d0b 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js +++ b/x-pack/plugins/monitoring/server/lib/beats/__tests__/fixtures/get_listing_response.js @@ -1,3 +1,9 @@ +/* + * 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. + */ + export function getListingsResponses() { return { obsolete_hit: { @@ -8,37 +14,37 @@ export function getListingsResponses() { name: 'spicy.local', type: 'filebeat', uuid: '2736e08b-5830-409b-8169-32aac39c5e55', - version: '7.0.0-alpha1' + version: '7.0.0-alpha1', }, metrics: { beat: { info: { - ephemeral_id: '919c2130-47ea-4f6b-8e7c-510d87e185f2' + ephemeral_id: '919c2130-47ea-4f6b-8e7c-510d87e185f2', }, memstats: { - memory_alloc: 30680648 - } + memory_alloc: 30680648, + }, }, libbeat: { output: { read: { - errors: 0 + errors: 0, }, type: 'elasticsearch', write: { bytes: 137661163, - errors: 0 - } + errors: 0, + }, }, pipeline: { events: { - total: 100 - } - } - } + total: 100, + }, + }, + }, }, - timestamp: '2018-02-09T21:49:35.683Z' - } + timestamp: '2018-02-09T21:49:35.683Z', + }, }, inner_hits: { earliest: { @@ -51,28 +57,28 @@ export function getListingsResponses() { libbeat: { output: { read: { - errors: 0 + errors: 0, }, write: { bytes: 49325414, - errors: 0 - } + errors: 0, + }, }, pipeline: { events: { - total: 34 - } - } - } + total: 34, + }, + }, + }, }, - timestamp: '2018-02-09T21:49:15.683Z' - } - } - } - ] - } - } - } + timestamp: '2018-02-09T21:49:15.683Z', + }, + }, + }, + ], + }, + }, + }, }, unique_hits: [ { @@ -83,37 +89,37 @@ export function getListingsResponses() { name: 'spicy.local', type: 'filebeat', uuid: '2736e08b-5830-409b-8169-32aac39c5e55', - version: '7.0.0-alpha1' + version: '7.0.0-alpha1', }, metrics: { beat: { info: { - ephemeral_id: 'd9b3ccac-cb80-4cb4-9179-2295a305679f' + ephemeral_id: 'd9b3ccac-cb80-4cb4-9179-2295a305679f', }, memstats: { - memory_alloc: 27209376 - } + memory_alloc: 27209376, + }, }, libbeat: { output: { read: { - errors: 0 + errors: 0, }, type: 'elasticsearch', write: { bytes: 2046089790, - errors: 0 - } + errors: 0, + }, }, pipeline: { events: { - total: 1366 - } - } - } + total: 1366, + }, + }, + }, }, - timestamp: '2018-02-09T21:48:55.244Z' - } + timestamp: '2018-02-09T21:48:55.244Z', + }, }, inner_hits: { earliest: { @@ -126,28 +132,28 @@ export function getListingsResponses() { libbeat: { output: { read: { - errors: 0 + errors: 0, }, write: { bytes: 103678160, - errors: 0 - } + errors: 0, + }, }, pipeline: { events: { - total: 69 - } - } - } + total: 69, + }, + }, + }, }, - timestamp: '2018-02-09T21:42:35.243Z' - } - } - } - ] - } - } - } + timestamp: '2018-02-09T21:42:35.243Z', + }, + }, + }, + ], + }, + }, + }, }, { _source: { @@ -157,37 +163,37 @@ export function getListingsResponses() { name: 'spicy.local', type: 'metricbeat', uuid: '60599a4f-8139-4251-b0b9-15866df34221', - version: '7.0.0-alpha1' + version: '7.0.0-alpha1', }, metrics: { beat: { info: { - ephemeral_id: 'f506ef06-1f89-4520-b698-b5591c0784b8' + ephemeral_id: 'f506ef06-1f89-4520-b698-b5591c0784b8', }, memstats: { - memory_alloc: 7598304 - } + memory_alloc: 7598304, + }, }, libbeat: { output: { read: { - errors: 0 + errors: 0, }, type: 'elasticsearch', write: { bytes: 9992700, - errors: 0 - } + errors: 0, + }, }, pipeline: { events: { - total: 12011 - } - } - } + total: 12011, + }, + }, + }, }, - timestamp: '2018-02-09T21:49:38.496Z' - } + timestamp: '2018-02-09T21:49:38.496Z', + }, }, inner_hits: { earliest: { @@ -200,29 +206,29 @@ export function getListingsResponses() { libbeat: { output: { read: { - errors: 0 + errors: 0, }, write: { bytes: 427954, - errors: 0 - } + errors: 0, + }, }, pipeline: { events: { - total: 545 - } - } - } + total: 545, + }, + }, + }, }, - timestamp: '2018-02-09T21:42:38.496Z' - } - } - } - ] - } - } - } - } - ] + timestamp: '2018-02-09T21:42:38.496Z', + }, + }, + }, + ], + }, + }, + }, + }, + ], }; } diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_beat_summary.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/get_beat_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_beat_summary.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/get_beat_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_beats.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/get_beats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_beats.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/get_beats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_beats_for_clusters.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/get_beats_for_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_beats_for_clusters.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/get_beats_for_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_latest_stats.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/get_latest_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_latest_stats.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/get_latest_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_stats.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/get_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/__tests__/get_stats.js rename to x-pack/plugins/monitoring/server/lib/beats/__tests__/get_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/_beats_stats.js b/x-pack/plugins/monitoring/server/lib/beats/_beats_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/_beats_stats.js rename to x-pack/plugins/monitoring/server/lib/beats/_beats_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/create_beats_query.js b/x-pack/plugins/monitoring/server/lib/beats/create_beats_query.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/create_beats_query.js rename to x-pack/plugins/monitoring/server/lib/beats/create_beats_query.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/get_beat_summary.js b/x-pack/plugins/monitoring/server/lib/beats/get_beat_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/get_beat_summary.js rename to x-pack/plugins/monitoring/server/lib/beats/get_beat_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/get_beats.js b/x-pack/plugins/monitoring/server/lib/beats/get_beats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/get_beats.js rename to x-pack/plugins/monitoring/server/lib/beats/get_beats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/get_beats_for_clusters.js b/x-pack/plugins/monitoring/server/lib/beats/get_beats_for_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/get_beats_for_clusters.js rename to x-pack/plugins/monitoring/server/lib/beats/get_beats_for_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/get_latest_stats.js b/x-pack/plugins/monitoring/server/lib/beats/get_latest_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/get_latest_stats.js rename to x-pack/plugins/monitoring/server/lib/beats/get_latest_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/get_stats.js b/x-pack/plugins/monitoring/server/lib/beats/get_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/get_stats.js rename to x-pack/plugins/monitoring/server/lib/beats/get_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/beats/index.js b/x-pack/plugins/monitoring/server/lib/beats/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/beats/index.js rename to x-pack/plugins/monitoring/server/lib/beats/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/calculate_auto.js b/x-pack/plugins/monitoring/server/lib/calculate_auto.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/calculate_auto.js rename to x-pack/plugins/monitoring/server/lib/calculate_auto.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/calculate_availability.js b/x-pack/plugins/monitoring/server/lib/calculate_availability.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/calculate_availability.js rename to x-pack/plugins/monitoring/server/lib/calculate_availability.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/calculate_overall_status.js b/x-pack/plugins/monitoring/server/lib/calculate_overall_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/calculate_overall_status.js rename to x-pack/plugins/monitoring/server/lib/calculate_overall_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/calculate_rate.js b/x-pack/plugins/monitoring/server/lib/calculate_rate.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/calculate_rate.js rename to x-pack/plugins/monitoring/server/lib/calculate_rate.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/calculate_timeseries_interval.js b/x-pack/plugins/monitoring/server/lib/calculate_timeseries_interval.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/calculate_timeseries_interval.js rename to x-pack/plugins/monitoring/server/lib/calculate_timeseries_interval.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/ccs_utils.js b/x-pack/plugins/monitoring/server/lib/ccs_utils.js similarity index 88% rename from x-pack/legacy/plugins/monitoring/server/lib/ccs_utils.js rename to x-pack/plugins/monitoring/server/lib/ccs_utils.js index 3409462156a0..f600fafd892c 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/ccs_utils.js +++ b/x-pack/plugins/monitoring/server/lib/ccs_utils.js @@ -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 { isFunction, get } from 'lodash'; /** * Prefix all comma separated index patterns within the original {@code indexPattern}. @@ -16,7 +17,14 @@ * @return {String} The index pattern with the {@code cluster} prefix appropriately prepended. */ export function prefixIndexPattern(config, indexPattern, ccs) { - const ccsEnabled = config.get('monitoring.ui.ccs.enabled'); + let ccsEnabled = false; + // TODO: NP + // This function is called with both NP config and LP config + if (isFunction(config.get)) { + ccsEnabled = config.get('monitoring.ui.ccs.enabled'); + } else { + ccsEnabled = get(config, 'monitoring.ui.ccs.enabled'); + } if (!ccsEnabled || !ccs) { return indexPattern; diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__test__/__snapshots__/get_clusters_summary.test.js.snap b/x-pack/plugins/monitoring/server/lib/cluster/__test__/__snapshots__/get_clusters_summary.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__test__/__snapshots__/get_clusters_summary.test.js.snap rename to x-pack/plugins/monitoring/server/lib/cluster/__test__/__snapshots__/get_clusters_summary.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__test__/fixtures/clusters.json b/x-pack/plugins/monitoring/server/lib/cluster/__test__/fixtures/clusters.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__test__/fixtures/clusters.json rename to x-pack/plugins/monitoring/server/lib/cluster/__test__/fixtures/clusters.json diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__test__/get_clusters_summary.test.js b/x-pack/plugins/monitoring/server/lib/cluster/__test__/get_clusters_summary.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__test__/get_clusters_summary.test.js rename to x-pack/plugins/monitoring/server/lib/cluster/__test__/get_clusters_summary.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/flag_supported_clusters.js b/x-pack/plugins/monitoring/server/lib/cluster/__tests__/flag_supported_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/flag_supported_clusters.js rename to x-pack/plugins/monitoring/server/lib/cluster/__tests__/flag_supported_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/get_cluster_status.js b/x-pack/plugins/monitoring/server/lib/cluster/__tests__/get_cluster_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/get_cluster_status.js rename to x-pack/plugins/monitoring/server/lib/cluster/__tests__/get_cluster_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_state.js b/x-pack/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_state.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_state.js rename to x-pack/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_state.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_stats.js b/x-pack/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_stats.js rename to x-pack/plugins/monitoring/server/lib/cluster/__tests__/get_clusters_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js b/x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js similarity index 96% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js rename to x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js index 3683be968f0c..1739f5dc3303 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js +++ b/x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js @@ -6,7 +6,7 @@ import { get, set, find } from 'lodash'; import { checkParam } from '../error_missing_required'; -import { LOGGING_TAG, STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants'; +import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants'; async function findSupportedBasicLicenseCluster( req, @@ -72,7 +72,7 @@ export function flagSupportedClusters(req, kbnIndexPattern) { checkParam(kbnIndexPattern, 'kbnIndexPattern in cluster/flagSupportedClusters'); const config = req.server.config(); - const serverLog = msg => req.server.log(['debug', LOGGING_TAG, 'supported-clusters'], msg); + const serverLog = msg => req.getLogger('supported-clusters').debug(msg); const flagAllSupported = clusters => { clusters.forEach(cluster => { if (cluster.license) { diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_cluster_license.js b/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_license.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_cluster_license.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_cluster_license.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_cluster_stats.js b/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_cluster_stats.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_cluster_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_cluster_status.js b/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_cluster_status.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_from_request.js b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_from_request.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_from_request.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_clusters_from_request.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_state.js b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_state.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_state.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_clusters_state.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_stats.js b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_stats.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_clusters_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_summary.js b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_clusters_summary.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_clusters_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_index_patterns.js b/x-pack/plugins/monitoring/server/lib/cluster/get_index_patterns.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/get_index_patterns.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_index_patterns.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/is_in_code_path.js b/x-pack/plugins/monitoring/server/lib/cluster/is_in_code_path.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/cluster/is_in_code_path.js rename to x-pack/plugins/monitoring/server/lib/cluster/is_in_code_path.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/create_query.js b/x-pack/plugins/monitoring/server/lib/create_query.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/create_query.js rename to x-pack/plugins/monitoring/server/lib/create_query.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/__test__/__snapshots__/get_metrics.test.js.snap b/x-pack/plugins/monitoring/server/lib/details/__test__/__snapshots__/get_metrics.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/__test__/__snapshots__/get_metrics.test.js.snap rename to x-pack/plugins/monitoring/server/lib/details/__test__/__snapshots__/get_metrics.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/__test__/fixtures/agg_metrics_buckets.json b/x-pack/plugins/monitoring/server/lib/details/__test__/fixtures/agg_metrics_buckets.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/__test__/fixtures/agg_metrics_buckets.json rename to x-pack/plugins/monitoring/server/lib/details/__test__/fixtures/agg_metrics_buckets.json diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/__test__/fixtures/deriv_metrics_buckets.json b/x-pack/plugins/monitoring/server/lib/details/__test__/fixtures/deriv_metrics_buckets.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/__test__/fixtures/deriv_metrics_buckets.json rename to x-pack/plugins/monitoring/server/lib/details/__test__/fixtures/deriv_metrics_buckets.json diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/__test__/fixtures/non_deriv_metrics_buckets.json b/x-pack/plugins/monitoring/server/lib/details/__test__/fixtures/non_deriv_metrics_buckets.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/__test__/fixtures/non_deriv_metrics_buckets.json rename to x-pack/plugins/monitoring/server/lib/details/__test__/fixtures/non_deriv_metrics_buckets.json diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/__test__/get_metrics.test.js b/x-pack/plugins/monitoring/server/lib/details/__test__/get_metrics.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/__test__/get_metrics.test.js rename to x-pack/plugins/monitoring/server/lib/details/__test__/get_metrics.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/get_metrics.js b/x-pack/plugins/monitoring/server/lib/details/get_metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/get_metrics.js rename to x-pack/plugins/monitoring/server/lib/details/get_metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/details/get_series.js b/x-pack/plugins/monitoring/server/lib/details/get_series.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/details/get_series.js rename to x-pack/plugins/monitoring/server/lib/details/get_series.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/__tests__/get_last_recovery.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/__tests__/get_last_recovery.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/__tests__/get_last_recovery.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/__tests__/get_last_recovery.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/__tests__/get_ml_jobs.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/__tests__/get_ml_jobs.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/__tests__/get_ml_jobs.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/__tests__/get_ml_jobs.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/ccr.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/ccr.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/ccr.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/ccr.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/convert_metric_names.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/convert_metric_names.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/convert_metric_names.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/convert_metric_names.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js similarity index 96% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js index c32b975118f5..d58144ac5729 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/get_last_recovery.js @@ -3,7 +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 moment from 'moment'; import _ from 'lodash'; import { checkParam } from '../error_missing_required'; import { createQuery } from '../create_query'; @@ -38,7 +38,7 @@ export function filterOldShardActivity(startMs) { export function handleLastRecoveries(resp, start) { if (resp.hits.hits.length === 1) { const data = _.get(resp.hits.hits[0], '_source.index_recovery.shards', []).filter( - filterOldShardActivity(start.getTime()) + filterOldShardActivity(moment.utc(start).valueOf()) ); data.sort((a, b) => b.start_time_in_millis - a.start_time_in_millis); return data; diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/get_ml_jobs.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/get_ml_jobs.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/get_ml_jobs.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/get_ml_jobs.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/index.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_index_summary.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_index_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_index_summary.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_index_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_indices.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_indices.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_indices.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/indices/__tests__/get_indices.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/get_index_summary.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_index_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/get_index_summary.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_index_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/indices/index.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/indices/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/calculate_node_type.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/calculate_node_type.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/calculate_node_type.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/calculate_node_type.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_summary.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_summary.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_type_class_label.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_type_class_label.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_type_class_label.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/get_node_type_class_label.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/lookups.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/lookups.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/lookups.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/__tests__/lookups.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/calculate_node_type.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/calculate_node_type.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/calculate_node_type.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/calculate_node_type.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_default_node_from_id.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_default_node_from_id.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_default_node_from_id.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_default_node_from_id.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_summary.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_summary.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_summary.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_summary.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_type_class_label.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_type_class_label.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_type_class_label.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_node_type_class_label.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/get_metric_aggs.test.js.snap b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/get_metric_aggs.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/get_metric_aggs.test.js.snap rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/get_metric_aggs.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/handle_response.test.js.snap b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/handle_response.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/handle_response.test.js.snap rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/handle_response.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_info.test.js.snap b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_info.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_info.test.js.snap rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_info.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_metrics.test.js.snap b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_metrics.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_metrics.test.js.snap rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/__snapshots__/map_nodes_metrics.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/fixtures/cluster_data.json b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/fixtures/cluster_data.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/fixtures/cluster_data.json rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/fixtures/cluster_data.json diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_metric_aggs.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_metric_aggs.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_metric_aggs.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_metric_aggs.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js similarity index 93% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js index 19fa99a78330..969216d6859e 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_node_ids.test.js @@ -47,7 +47,7 @@ describe('getNodeIds', () => { }; const clusterUuid = '1cb'; - const result = await getNodeIds(req, '.monitoring-es-*', { clusterUuid }, 10); + const result = await getNodeIds(req, '.monitoring-es-*s', { clusterUuid }, 10); expect(result).toEqual([ { name: 'foobar', uuid: 1 }, { name: 'barfoo', uuid: 2 }, diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_paginated_nodes.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_paginated_nodes.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_paginated_nodes.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/get_paginated_nodes.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/handle_response.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/handle_response.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/handle_response.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/handle_response.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_info.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_info.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_info.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_info.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_metrics.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_metrics.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_metrics.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/__test__/map_nodes_metrics.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_live_nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_live_nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_live_nodes.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_live_nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_metric_aggs.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_metric_aggs.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_metric_aggs.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_metric_aggs.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_node_ids.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_node_ids.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_node_ids.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_node_ids.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_paginated_nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_paginated_nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_paginated_nodes.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_paginated_nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/index.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_metrics.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_metrics.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/nodes_listing_metrics.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/nodes_listing_metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/nodes_listing_metrics.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/nodes_listing_metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js similarity index 93% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js index 6b38e4d3ef3a..d0f845a8b0ed 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/sort_nodes.js @@ -6,7 +6,7 @@ import { sortByOrder } from 'lodash'; export function sortNodes(nodes, sort) { - if (!sort) { + if (!sort || !sort.field) { return nodes; } diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/index.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/lookups.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/lookups.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/nodes/lookups.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/lookups.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/cluster.json b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/cluster.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/cluster.json rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/cluster.json diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js new file mode 100644 index 000000000000..72db17db8242 --- /dev/null +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/index.js @@ -0,0 +1,10 @@ +/* + * 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 shardStatsFixture from './shard_stats'; +import clusterFixture from './cluster'; + +export { shardStatsFixture, clusterFixture }; diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/shard_stats.json b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/shard_stats.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/shard_stats.json rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/fixtures/shard_stats.json diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/get_shard_stats.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/get_shard_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/get_shard_stats.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/get_shard_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/normalize_shard_objects.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/normalize_shard_objects.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/normalize_shard_objects.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/__tests__/normalize_shard_objects.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/calculate_shard_stat_indices_totals.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/calculate_shard_stat_indices_totals.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/calculate_shard_stat_indices_totals.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/calculate_shard_stat_indices_totals.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_indices_unassigned_shard_stats.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_nodes_shard_count.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.test.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_allocation.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stat_aggs.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stat_aggs.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stat_aggs.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stat_aggs.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stats.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stats.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stats.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_shard_stats.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_unassigned_shards.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_unassigned_shards.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/get_unassigned_shards.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/get_unassigned_shards.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/index.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/normalize_shard_objects.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/shards/normalize_shard_objects.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/shards/normalize_shard_objects.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/shards/normalize_shard_objects.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_ccs_availability.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_ccs_availability.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_ccs_availability.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/verify_ccs_availability.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js similarity index 95% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js index 96a035455609..6d2a853ee24d 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js @@ -19,10 +19,10 @@ export async function verifyMonitoringAuth(req) { const xpackInfo = get(req.server.plugins.monitoring, 'info'); if (xpackInfo) { - const security = xpackInfo.feature('security'); + const security = xpackInfo.getSecurityFeature(); // we only need to verify permissions if we're using X-Pack Security - if (security.isAvailable() && security.isEnabled()) { + if (security.isAvailable && security.isEnabled) { await verifyHasPrivileges(req); } } diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/cluster.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/cluster.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/cluster.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/cluster.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/find_reason.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/find_reason.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/find_reason.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/find_reason.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/nodes.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/__tests__/nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/find_reason.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/find_reason.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/find_reason.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/find_reason.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/index.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/index.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_disabled.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_disabled.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_disabled.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_disabled.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_enabled.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_enabled.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_enabled.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_enabled.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_interval.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_interval.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_interval.js rename to x-pack/plugins/monitoring/server/lib/elasticsearch_settings/set/collection_interval.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/error_missing_required.js b/x-pack/plugins/monitoring/server/lib/error_missing_required.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/error_missing_required.js rename to x-pack/plugins/monitoring/server/lib/error_missing_required.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/__tests__/auth_errors.js b/x-pack/plugins/monitoring/server/lib/errors/__tests__/auth_errors.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/__tests__/auth_errors.js rename to x-pack/plugins/monitoring/server/lib/errors/__tests__/auth_errors.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/__tests__/known_errors.js b/x-pack/plugins/monitoring/server/lib/errors/__tests__/known_errors.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/__tests__/known_errors.js rename to x-pack/plugins/monitoring/server/lib/errors/__tests__/known_errors.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/auth_errors.js b/x-pack/plugins/monitoring/server/lib/errors/auth_errors.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/auth_errors.js rename to x-pack/plugins/monitoring/server/lib/errors/auth_errors.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/custom_errors.js b/x-pack/plugins/monitoring/server/lib/errors/custom_errors.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/custom_errors.js rename to x-pack/plugins/monitoring/server/lib/errors/custom_errors.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/handle_error.js b/x-pack/plugins/monitoring/server/lib/errors/handle_error.js similarity index 91% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/handle_error.js rename to x-pack/plugins/monitoring/server/lib/errors/handle_error.js index 319f93d4cd19..d6549a8fa98e 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/errors/handle_error.js +++ b/x-pack/plugins/monitoring/server/lib/errors/handle_error.js @@ -7,10 +7,9 @@ import { boomify } from 'boom'; import { isKnownError, handleKnownError } from './known_errors'; import { isAuthError, handleAuthError } from './auth_errors'; -import { LOGGING_TAG } from '../../../common/constants'; export function handleError(err, req) { - req.log(['error', LOGGING_TAG], err); + req.logger.error(err); // specially handle auth errors if (isAuthError(err)) { diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/handle_settings_error.js b/x-pack/plugins/monitoring/server/lib/errors/handle_settings_error.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/handle_settings_error.js rename to x-pack/plugins/monitoring/server/lib/errors/handle_settings_error.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/index.js b/x-pack/plugins/monitoring/server/lib/errors/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/index.js rename to x-pack/plugins/monitoring/server/lib/errors/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/errors/known_errors.js b/x-pack/plugins/monitoring/server/lib/errors/known_errors.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/errors/known_errors.js rename to x-pack/plugins/monitoring/server/lib/errors/known_errors.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/filter_partial_buckets.js b/x-pack/plugins/monitoring/server/lib/filter_partial_buckets.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/filter_partial_buckets.js rename to x-pack/plugins/monitoring/server/lib/filter_partial_buckets.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/format_timezone.js b/x-pack/plugins/monitoring/server/lib/format_timezone.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/format_timezone.js rename to x-pack/plugins/monitoring/server/lib/format_timezone.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/get_timezone.js b/x-pack/plugins/monitoring/server/lib/get_timezone.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/get_timezone.js rename to x-pack/plugins/monitoring/server/lib/get_timezone.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/kibana/__tests__/get_kibana_info.js b/x-pack/plugins/monitoring/server/lib/kibana/__tests__/get_kibana_info.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/kibana/__tests__/get_kibana_info.js rename to x-pack/plugins/monitoring/server/lib/kibana/__tests__/get_kibana_info.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/kibana/get_kibana_info.js b/x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/kibana/get_kibana_info.js rename to x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/kibana/get_kibanas.js b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/kibana/get_kibanas.js rename to x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js rename to x-pack/plugins/monitoring/server/lib/kibana/get_kibanas_for_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/kibana/index.js b/x-pack/plugins/monitoring/server/lib/kibana/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/kibana/index.js rename to x-pack/plugins/monitoring/server/lib/kibana/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason.js b/x-pack/plugins/monitoring/server/lib/logs/detect_reason.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason.js rename to x-pack/plugins/monitoring/server/lib/logs/detect_reason.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js b/x-pack/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js rename to x-pack/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js b/x-pack/plugins/monitoring/server/lib/logs/get_log_types.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js rename to x-pack/plugins/monitoring/server/lib/logs/get_log_types.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js b/x-pack/plugins/monitoring/server/lib/logs/get_logs.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js rename to x-pack/plugins/monitoring/server/lib/logs/get_logs.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/index.js b/x-pack/plugins/monitoring/server/lib/logs/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logs/index.js rename to x-pack/plugins/monitoring/server/lib/logs/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/init_infra_source.js b/x-pack/plugins/monitoring/server/lib/logs/init_infra_source.ts similarity index 63% rename from x-pack/legacy/plugins/monitoring/server/lib/logs/init_infra_source.js rename to x-pack/plugins/monitoring/server/lib/logs/init_infra_source.ts index 7ca36e8b2955..b6be7bbe1398 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/logs/init_infra_source.js +++ b/x-pack/plugins/monitoring/server/lib/logs/init_infra_source.ts @@ -4,16 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ +// @ts-ignore import { prefixIndexPattern } from '../ccs_utils'; import { INFRA_SOURCE_ID } from '../../../common/constants'; +import { MonitoringConfig } from '../../config'; +import { InfraPluginSetup } from '../../../../infra/server'; -export const initInfraSource = (config, infraPlugin) => { +export const initInfraSource = (config: MonitoringConfig, infraPlugin: InfraPluginSetup) => { if (infraPlugin) { - const filebeatIndexPattern = prefixIndexPattern( - config, - config.get('monitoring.ui.logs.index'), - '*' - ); + const filebeatIndexPattern = prefixIndexPattern(config, config.ui.logs.index, '*'); infraPlugin.defineInternalSourceConfiguration(INFRA_SOURCE_ID, { name: 'Elastic Stack Logs', logAlias: filebeatIndexPattern, diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/__tests__/get_node_info.js b/x-pack/plugins/monitoring/server/lib/logstash/__tests__/get_node_info.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/__tests__/get_node_info.js rename to x-pack/plugins/monitoring/server/lib/logstash/__tests__/get_node_info.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/__tests__/get_pipeline.js b/x-pack/plugins/monitoring/server/lib/logstash/__tests__/get_pipeline.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/__tests__/get_pipeline.js rename to x-pack/plugins/monitoring/server/lib/logstash/__tests__/get_pipeline.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_cluster_status.js b/x-pack/plugins/monitoring/server/lib/logstash/get_cluster_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_cluster_status.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_cluster_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js b/x-pack/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_logstash_for_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_node_info.js b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_node_info.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_node_info.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_nodes.js b/x-pack/plugins/monitoring/server/lib/logstash/get_nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_nodes.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_paginated_pipelines.js b/x-pack/plugins/monitoring/server/lib/logstash/get_paginated_pipelines.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_paginated_pipelines.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_paginated_pipelines.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_ids.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_ids.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_ids.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_ids.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_stats_aggregation.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_stats_aggregation.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_stats_aggregation.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_stats_aggregation.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_versions.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_versions.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_versions.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_versions.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_vertex.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_vertex.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_vertex.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_vertex.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_vertex_stats_aggregation.js b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_vertex_stats_aggregation.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/get_pipeline_vertex_stats_aggregation.js rename to x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_vertex_stats_aggregation.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/index.js b/x-pack/plugins/monitoring/server/lib/logstash/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/index.js rename to x-pack/plugins/monitoring/server/lib/logstash/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logstash/sort_pipelines.js b/x-pack/plugins/monitoring/server/lib/logstash/sort_pipelines.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/logstash/sort_pipelines.js rename to x-pack/plugins/monitoring/server/lib/logstash/sort_pipelines.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap b/x-pack/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap rename to x-pack/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/__test__/metrics.test.js b/x-pack/plugins/monitoring/server/lib/metrics/__test__/metrics.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/__test__/metrics.test.js rename to x-pack/plugins/monitoring/server/lib/metrics/__test__/metrics.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/apm/classes.js b/x-pack/plugins/monitoring/server/lib/metrics/apm/classes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/apm/classes.js rename to x-pack/plugins/monitoring/server/lib/metrics/apm/classes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/apm/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/apm/metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/apm/metrics.js rename to x-pack/plugins/monitoring/server/lib/metrics/apm/metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/beats/__test__/cpu_utilization_calculation.test.js b/x-pack/plugins/monitoring/server/lib/metrics/beats/__test__/cpu_utilization_calculation.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/beats/__test__/cpu_utilization_calculation.test.js rename to x-pack/plugins/monitoring/server/lib/metrics/beats/__test__/cpu_utilization_calculation.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/beats/classes.js b/x-pack/plugins/monitoring/server/lib/metrics/beats/classes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/beats/classes.js rename to x-pack/plugins/monitoring/server/lib/metrics/beats/classes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/beats/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/beats/metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/beats/metrics.js rename to x-pack/plugins/monitoring/server/lib/metrics/beats/metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/__test__/latency_metric_calculation.test.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/__test__/latency_metric_calculation.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/__test__/latency_metric_calculation.test.js rename to x-pack/plugins/monitoring/server/lib/metrics/classes/__test__/latency_metric_calculation.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/__test__/quota_metric_calculation.test.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/__test__/quota_metric_calculation.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/__test__/quota_metric_calculation.test.js rename to x-pack/plugins/monitoring/server/lib/metrics/classes/__test__/quota_metric_calculation.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/cluster_metric.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/cluster_metric.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/cluster_metric.js rename to x-pack/plugins/monitoring/server/lib/metrics/classes/cluster_metric.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/index.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/index.js rename to x-pack/plugins/monitoring/server/lib/metrics/classes/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/metric.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/metric.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/metric.js rename to x-pack/plugins/monitoring/server/lib/metrics/classes/metric.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/quota_metric.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/quota_metric.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/classes/quota_metric.js rename to x-pack/plugins/monitoring/server/lib/metrics/classes/quota_metric.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/elasticsearch/__test__/latency_calculation.test.js b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/__test__/latency_calculation.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/elasticsearch/__test__/latency_calculation.test.js rename to x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/__test__/latency_calculation.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js rename to x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js rename to x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/index.js b/x-pack/plugins/monitoring/server/lib/metrics/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/index.js rename to x-pack/plugins/monitoring/server/lib/metrics/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/kibana/classes.js b/x-pack/plugins/monitoring/server/lib/metrics/kibana/classes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/kibana/classes.js rename to x-pack/plugins/monitoring/server/lib/metrics/kibana/classes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/kibana/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/kibana/metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/kibana/metrics.js rename to x-pack/plugins/monitoring/server/lib/metrics/kibana/metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/logstash/classes.js b/x-pack/plugins/monitoring/server/lib/metrics/logstash/classes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/logstash/classes.js rename to x-pack/plugins/monitoring/server/lib/metrics/logstash/classes.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/logstash/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/logstash/metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/logstash/metrics.js rename to x-pack/plugins/monitoring/server/lib/metrics/logstash/metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/metrics/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/metrics.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/metrics/metrics.js rename to x-pack/plugins/monitoring/server/lib/metrics/metrics.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/normalize_version_string.js b/x-pack/plugins/monitoring/server/lib/normalize_version_string.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/normalize_version_string.js rename to x-pack/plugins/monitoring/server/lib/normalize_version_string.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/pagination/filter.js b/x-pack/plugins/monitoring/server/lib/pagination/filter.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/pagination/filter.js rename to x-pack/plugins/monitoring/server/lib/pagination/filter.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/pagination/paginate.js b/x-pack/plugins/monitoring/server/lib/pagination/paginate.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/pagination/paginate.js rename to x-pack/plugins/monitoring/server/lib/pagination/paginate.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/setup/collection/__test__/get_collection_status.test.js b/x-pack/plugins/monitoring/server/lib/setup/collection/__test__/get_collection_status.test.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/setup/collection/__test__/get_collection_status.test.js rename to x-pack/plugins/monitoring/server/lib/setup/collection/__test__/get_collection_status.test.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/setup/collection/get_collection_status.js b/x-pack/plugins/monitoring/server/lib/setup/collection/get_collection_status.js similarity index 98% rename from x-pack/legacy/plugins/monitoring/server/lib/setup/collection/get_collection_status.js rename to x-pack/plugins/monitoring/server/lib/setup/collection/get_collection_status.js index 0029aaa9ce8e..22fd117595a8 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/setup/collection/get_collection_status.js +++ b/x-pack/plugins/monitoring/server/lib/setup/collection/get_collection_status.js @@ -12,15 +12,15 @@ import { KIBANA_SYSTEM_ID, BEATS_SYSTEM_ID, LOGSTASH_SYSTEM_ID, + KIBANA_STATS_TYPE_MONITORING, } from '../../../../common/constants'; import { getLivesNodes } from '../../elasticsearch/nodes/get_nodes/get_live_nodes'; -import { KIBANA_STATS_TYPE } from '../../../../../../../../src/legacy/server/status/constants'; const NUMBER_OF_SECONDS_AGO_TO_LOOK = 30; const getRecentMonitoringDocuments = async (req, indexPatterns, clusterUuid, nodeUuid) => { - const start = get(req.payload, 'timeRange.min', `now-${NUMBER_OF_SECONDS_AGO_TO_LOOK}s`); - const end = get(req.payload, 'timeRange.max', 'now'); + const start = get(req.payload, 'timeRange.min') || `now-${NUMBER_OF_SECONDS_AGO_TO_LOOK}s`; + const end = get(req.payload, 'timeRange.max') || 'now'; const filters = [ { @@ -274,7 +274,7 @@ async function getLiveKibanaInstance(usageCollection) { if (!usageCollection) { return null; } - const kibanaStatsCollector = usageCollection.getCollectorByType(KIBANA_STATS_TYPE); + const kibanaStatsCollector = usageCollection.getCollectorByType(KIBANA_STATS_TYPE_MONITORING); if (!(await kibanaStatsCollector.isReady())) { return null; } diff --git a/x-pack/legacy/plugins/monitoring/server/lib/setup/collection/index.js b/x-pack/plugins/monitoring/server/lib/setup/collection/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/setup/collection/index.js rename to x-pack/plugins/monitoring/server/lib/setup/collection/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/get_standalone_cluster_definition.js b/x-pack/plugins/monitoring/server/lib/standalone_clusters/get_standalone_cluster_definition.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/get_standalone_cluster_definition.js rename to x-pack/plugins/monitoring/server/lib/standalone_clusters/get_standalone_cluster_definition.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/has_standalone_clusters.js b/x-pack/plugins/monitoring/server/lib/standalone_clusters/has_standalone_clusters.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/has_standalone_clusters.js rename to x-pack/plugins/monitoring/server/lib/standalone_clusters/has_standalone_clusters.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/index.js b/x-pack/plugins/monitoring/server/lib/standalone_clusters/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/index.js rename to x-pack/plugins/monitoring/server/lib/standalone_clusters/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/standalone_cluster_query_filter.js b/x-pack/plugins/monitoring/server/lib/standalone_clusters/standalone_cluster_query_filter.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/lib/standalone_clusters/standalone_cluster_query_filter.js rename to x-pack/plugins/monitoring/server/lib/standalone_clusters/standalone_cluster_query_filter.js diff --git a/x-pack/plugins/monitoring/server/license_service.ts b/x-pack/plugins/monitoring/server/license_service.ts new file mode 100644 index 000000000000..01746a550ced --- /dev/null +++ b/x-pack/plugins/monitoring/server/license_service.ts @@ -0,0 +1,59 @@ +/* + * 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 { Subscription } from 'rxjs'; +import { ICustomClusterClient } from 'kibana/server'; +import { ILicense, LicenseFeature } from '../../licensing/common/types'; +import { LicensingPluginSetup } from '../../licensing/server'; +import { MonitoringConfig } from './config'; +import { Logger } from '../../../../src/core/server'; +import { MonitoringLicenseService } from './types'; + +interface SetupDeps { + licensing: LicensingPluginSetup; + monitoringClient: ICustomClusterClient; + config: MonitoringConfig; + log: Logger; +} + +const defaultLicenseFeature: LicenseFeature = { + isAvailable: false, + isEnabled: false, +}; + +export class LicenseService { + public setup({ licensing, monitoringClient, config, log }: SetupDeps): MonitoringLicenseService { + const { refresh, license$ } = licensing.createLicensePoller( + monitoringClient, + config.licensing.api_polling_frequency.asMilliseconds() + ); + + let rawLicense: Readonly | undefined; + let licenseSubscription: Subscription | undefined = license$.subscribe(nextRawLicense => { + rawLicense = nextRawLicense; + }); + + if (!rawLicense?.isAvailable) { + log.warn( + `X-Pack Monitoring Cluster Alerts will not be available: ${rawLicense?.getUnavailableReason()}` + ); + } + + return { + refresh, + license$, + getMessage: () => rawLicense?.getUnavailableReason() || 'N/A', + getMonitoringFeature: () => rawLicense?.getFeature('monitoring') || defaultLicenseFeature, + getWatcherFeature: () => rawLicense?.getFeature('monitoring') || defaultLicenseFeature, + getSecurityFeature: () => rawLicense?.getFeature('security') || defaultLicenseFeature, + stop: () => { + if (licenseSubscription) { + licenseSubscription.unsubscribe(); + licenseSubscription = undefined; + } + }, + }; + } +} diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts new file mode 100644 index 000000000000..bd1455a2c582 --- /dev/null +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -0,0 +1,378 @@ +/* + * 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 Boom from 'boom'; +import { combineLatest } from 'rxjs'; +import { first } from 'rxjs/operators'; +import { i18n } from '@kbn/i18n'; +import { has, get } from 'lodash'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { TelemetryCollectionManager } from 'src/legacy/core_plugins/telemetry/server/collection_manager'; +import { + LOGGING_TAG, + KIBANA_MONITORING_LOGGING_TAG, + KIBANA_ALERTING_ENABLED, + KIBANA_STATS_TYPE_MONITORING, +} from '../common/constants'; +import { + Logger, + PluginInitializerContext, + RequestHandlerContext, + KibanaRequest, + KibanaResponseFactory, + CoreSetup, + ICustomClusterClient, + CoreStart, + IRouter, + IClusterClient, +} from '../../../../src/core/server'; +import { MonitoringConfig } from './config'; +// @ts-ignore +import { requireUIRoutes } from './routes'; +// @ts-ignore +import { initBulkUploader } from './kibana_monitoring'; +// @ts-ignore +import { initInfraSource } from './lib/logs/init_infra_source'; +import { instantiateClient } from './es_client/instantiate_client'; +import { registerCollectors } from './kibana_monitoring/collectors'; +import { registerMonitoringCollection } from './telemetry_collection'; +import { LicensingPluginSetup } from '../../licensing/server'; +import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server'; +import { LicenseService } from './license_service'; +import { MonitoringLicenseService } from './types'; +import { + PluginStartContract as AlertingPluginStartContract, + PluginSetupContract as AlertingPluginSetupContract, +} from '../../alerting/server'; +import { getLicenseExpiration } from './alerts/license_expiration'; +import { InfraPluginSetup } from '../../infra/server'; + +export interface LegacyAPI { + telemetryCollectionManager: TelemetryCollectionManager; + getServerStatus: () => string; + infra: any; +} + +interface PluginsSetup { + usageCollection: UsageCollectionSetup; + licensing: LicensingPluginSetup; + features: FeaturesPluginSetupContract; + alerting: AlertingPluginSetupContract; + infra: InfraPluginSetup; +} + +interface PluginsStart { + alerting: AlertingPluginStartContract; +} + +interface MonitoringCoreConfig { + get: (key: string) => string | undefined; +} + +interface MonitoringCore { + config: () => MonitoringCoreConfig; + log: Logger; + route: (options: any) => void; +} + +interface LegacyShimDependencies { + router: IRouter; + instanceUuid: string; + esDataClient: IClusterClient; + kibanaStatsCollector: any; +} + +interface IBulkUploader { + setKibanaStatusGetter: (getter: () => string | undefined) => void; + getKibanaStats: () => any; +} + +// This is used to test the version of kibana +const snapshotRegex = /-snapshot/i; + +export class Plugin { + private readonly initializerContext: PluginInitializerContext; + private readonly log: Logger; + private readonly getLogger: (...scopes: string[]) => Logger; + private cluster = {} as ICustomClusterClient; + private licenseService = {} as MonitoringLicenseService; + private monitoringCore = {} as MonitoringCore; + private legacyShimDependencies = {} as LegacyShimDependencies; + private bulkUploader = {} as IBulkUploader; + + constructor(initializerContext: PluginInitializerContext) { + this.initializerContext = initializerContext; + this.log = initializerContext.logger.get(LOGGING_TAG); + this.getLogger = (...scopes: string[]) => initializerContext.logger.get(LOGGING_TAG, ...scopes); + } + + async setup(core: CoreSetup, plugins: PluginsSetup) { + const [config, legacyConfig] = await combineLatest([ + this.initializerContext.config.create(), + this.initializerContext.config.legacy.globalConfig$, + ]) + .pipe(first()) + .toPromise(); + + this.legacyShimDependencies = { + router: core.http.createRouter(), + instanceUuid: core.uuid.getInstanceUuid(), + esDataClient: core.elasticsearch.dataClient, + kibanaStatsCollector: plugins.usageCollection.getCollectorByType( + KIBANA_STATS_TYPE_MONITORING + ), + }; + + // Monitoring creates and maintains a connection to a potentially + // separate ES cluster - create this first + const cluster = (this.cluster = instantiateClient( + config.ui.elasticsearch, + this.log, + core.elasticsearch.createClient + )); + + // Start our license service which will ensure + // the appropriate licenses are present + this.licenseService = new LicenseService().setup({ + licensing: plugins.licensing, + monitoringClient: cluster, + config, + log: this.log, + }); + await this.licenseService.refresh(); + + if (KIBANA_ALERTING_ENABLED) { + plugins.alerting.registerType( + getLicenseExpiration( + async () => { + const coreStart = (await core.getStartServices())[0]; + return coreStart.uiSettings; + }, + cluster, + this.getLogger, + config.ui.ccs.enabled + ) + ); + } + + // Register collector objects for stats to show up in the APIs + registerCollectors( + plugins.usageCollection, + config, + core.metrics.getOpsMetrics$(), + get(legacyConfig, 'kibana.index') + ); + + // If collection is enabled, create the bulk uploader + const kibanaMonitoringLog = this.getLogger(KIBANA_MONITORING_LOGGING_TAG); + const kibanaCollectionEnabled = config.kibana.collection.enabled; + if (kibanaCollectionEnabled) { + // Start kibana internal collection + const serverInfo = core.http.getServerInfo(); + const bulkUploader = (this.bulkUploader = initBulkUploader({ + elasticsearch: core.elasticsearch, + config, + log: kibanaMonitoringLog, + kibanaStats: { + uuid: core.uuid.getInstanceUuid(), + name: serverInfo.name, + index: get(legacyConfig, 'kibana.index'), + host: serverInfo.host, + transport_address: `${serverInfo.host}:${serverInfo.port}`, + port: serverInfo.port.toString(), + version: this.initializerContext.env.packageInfo.version, + snapshot: snapshotRegex.test(this.initializerContext.env.packageInfo.version), + }, + })); + + // Do not use `this.licenseService` as that looks at the monitoring cluster + // whereas we want to check the production cluster here + if (plugins.licensing) { + plugins.licensing.license$.subscribe((license: any) => { + // use updated xpack license info to start/stop bulk upload + const mainMonitoring = license.getFeature('monitoring'); + const monitoringBulkEnabled = + mainMonitoring && mainMonitoring.isAvailable && mainMonitoring.isEnabled; + if (monitoringBulkEnabled) { + bulkUploader.start(plugins.usageCollection); + } else { + bulkUploader.handleNotEnabled(); + } + }); + } + } else { + kibanaMonitoringLog.info( + 'Internal collection for Kibana monitoring is disabled per configuration.' + ); + } + + // If the UI is enabled, then we want to register it so it shows up + // and start any other UI-related setup tasks + if (config.ui.enabled) { + // Create our shim which is currently used to power our routing + this.monitoringCore = this.getLegacyShim( + config, + legacyConfig, + core.getStartServices as () => Promise<[CoreStart, PluginsStart]>, + this.licenseService, + this.cluster + ); + + this.registerPluginInUI(plugins); + requireUIRoutes(this.monitoringCore); + initInfraSource(config, plugins.infra); + } + + return { + // The legacy plugin calls this to register certain legacy dependencies + // that are necessary for the plugin to properly run + registerLegacyAPI: (legacyAPI: LegacyAPI) => { + this.setupLegacy(legacyAPI); + }, + // OSS stats api needs to call this in order to centralize how + // we fetch kibana specific stats + getKibanaStats: () => this.bulkUploader.getKibanaStats(), + }; + } + + start() {} + + stop() { + if (this.cluster) { + this.cluster.close(); + } + if (this.licenseService) { + this.licenseService.stop(); + } + } + + registerPluginInUI(plugins: PluginsSetup) { + plugins.features.registerFeature({ + id: 'monitoring', + name: i18n.translate('xpack.monitoring.featureRegistry.monitoringFeatureName', { + defaultMessage: 'Stack Monitoring', + }), + icon: 'monitoringApp', + navLinkId: 'monitoring', + app: ['monitoring', 'kibana'], + catalogue: ['monitoring'], + privileges: {}, + reserved: { + privilege: { + savedObject: { + all: [], + read: [], + }, + ui: [], + }, + description: i18n.translate('xpack.monitoring.feature.reserved.description', { + defaultMessage: 'To grant users access, you should also assign the monitoring_user role.', + }), + }, + }); + } + + async setupLegacy(legacyAPI: LegacyAPI) { + // Initialize telemetry + registerMonitoringCollection(this.cluster, legacyAPI.telemetryCollectionManager); + + // Set the stats getter + this.bulkUploader.setKibanaStatusGetter(() => legacyAPI.getServerStatus()); + } + + getLegacyShim( + config: MonitoringConfig, + legacyConfig: any, + getCoreServices: () => Promise<[CoreStart, PluginsStart]>, + licenseService: MonitoringLicenseService, + cluster: ICustomClusterClient + ): MonitoringCore { + const router = this.legacyShimDependencies.router; + const legacyConfigWrapper = () => ({ + get: (_key: string): string | undefined => { + const key = _key.includes('monitoring.') ? _key.split('monitoring.')[1] : _key; + if (has(config, key)) { + return get(config, key); + } + if (has(legacyConfig, key)) { + return get(legacyConfig, key); + } + + if (key === 'server.uuid') { + return this.legacyShimDependencies.instanceUuid; + } + + throw new Error(`Unknown key '${_key}'`); + }, + }); + return { + config: legacyConfigWrapper, + log: this.log, + route: (options: any) => { + const method = options.method; + const handler = async ( + context: RequestHandlerContext, + req: KibanaRequest, + res: KibanaResponseFactory + ) => { + const plugins = (await getCoreServices())[1]; + const legacyRequest = { + ...req, + logger: this.log, + getLogger: this.getLogger, + payload: req.body, + getKibanaStatsCollector: () => this.legacyShimDependencies.kibanaStatsCollector, + getUiSettingsService: () => context.core.uiSettings.client, + getAlertsClient: () => plugins.alerting.getAlertsClientWithRequest(req), + server: { + config: legacyConfigWrapper, + newPlatform: { + setup: { + plugins, + }, + }, + plugins: { + monitoring: { + info: licenseService, + }, + elasticsearch: { + getCluster: (name: string) => ({ + callWithRequest: async (_req: any, endpoint: string, params: any) => { + const client = + name === 'monitoring' ? cluster : this.legacyShimDependencies.esDataClient; + return client.asScoped(req).callAsCurrentUser(endpoint, params); + }, + }), + }, + }, + }, + }; + + const result = await options.handler(legacyRequest); + if (Boom.isBoom(result)) { + return res.customError({ statusCode: result.output.statusCode, body: result }); + } + return res.ok({ body: result }); + }; + + const validate: any = get(options, 'config.validate', false); + if (validate && validate.payload) { + validate.body = validate.payload; + } + options.validate = validate; + + if (method === 'POST') { + router.post(options, handler); + } else if (method === 'GET') { + router.get(options, handler); + } else if (method === 'PUT') { + router.put(options, handler); + } else { + throw new Error('Unsupport API method: ' + method); + } + }, + }; + } +} diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/alerts.js b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/alerts.js similarity index 93% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/alerts.js rename to x-pack/plugins/monitoring/server/routes/api/v1/alerts/alerts.js index f87683effe43..56922bd8e87e 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/alerts.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/alerts.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { isFunction } from 'lodash'; import { ALERT_TYPE_LICENSE_EXPIRATION, @@ -65,9 +65,9 @@ export function createKibanaAlertsRoute(server) { path: '/api/monitoring/v1/alerts', config: { validate: { - payload: Joi.object({ - selectedEmailActionId: Joi.string().required(), - emailAddress: Joi.string().required(), + payload: schema.object({ + selectedEmailActionId: schema.string(), + emailAddress: schema.string(), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/alerts/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js similarity index 83% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js rename to x-pack/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js index a3049f0f3e2d..14f3ca8b5cb5 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/legacy_alerts.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { alertsClusterSearch } from '../../../../cluster_alerts/alerts_cluster_search'; import { checkLicense } from '../../../../cluster_alerts/check_license'; import { getClusterLicense } from '../../../../lib/cluster/get_cluster_license'; @@ -20,15 +20,15 @@ export function legacyClusterAlertsRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/legacy_alerts', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/_get_apm_cluster_status.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/_get_apm_cluster_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/_get_apm_cluster_status.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/_get_apm_cluster_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/instance.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js similarity index 81% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/instance.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js index 4be5fc6719e6..0ff9e834b924 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/instance.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { metricSet } from './metric_set_overview'; @@ -18,16 +18,16 @@ export function apmInstanceRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/apm/{apmUuid}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - apmUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + apmUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/instances.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js similarity index 80% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/instances.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js index f3c3c42f8398..7083e2600bee 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/instances.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getStats, getApms } from '../../../../lib/apm'; import { handleError } from '../../../../lib/errors'; @@ -16,15 +16,15 @@ export function apmInstancesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/apm/instances', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/metric_set_instance.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/metric_set_instance.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/metric_set_instance.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/metric_set_instance.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/metric_set_overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/metric_set_overview.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/metric_set_overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/metric_set_overview.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js similarity index 81% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js index 7f12a9cac841..f2dfa0b45076 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/apm/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { metricSet } from './metric_set_overview'; @@ -18,15 +18,15 @@ export function apmOverviewRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/apm', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js similarity index 82% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js rename to x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js index 638795fd6b64..6f2c3b5f6f21 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getBeatSummary } from '../../../../lib/beats'; import { getMetrics } from '../../../../lib/details/get_metrics'; @@ -18,16 +18,16 @@ export function beatsDetailRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/beats/beat/{beatUuid}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - beatUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + beatUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/beats.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js similarity index 80% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/beats.js rename to x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js index 6d681e697b33..425058934604 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/beats.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getStats, getBeats } from '../../../../lib/beats'; import { handleError } from '../../../../lib/errors'; @@ -16,15 +16,15 @@ export function beatsListingRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/beats/beats', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/beats/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/metric_set_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/metric_set_detail.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/metric_set_detail.js rename to x-pack/plugins/monitoring/server/routes/api/v1/beats/metric_set_detail.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/metric_set_overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/metric_set_overview.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/metric_set_overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/beats/metric_set_overview.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js similarity index 82% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js index b6cdc8e2588e..f4722acdf825 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/beats/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { getLatestStats, getStats } from '../../../../lib/beats'; @@ -18,15 +18,15 @@ export function beatsOverviewRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/beats', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/check_access/check_access.js b/x-pack/plugins/monitoring/server/routes/api/v1/check_access/check_access.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/check_access/check_access.js rename to x-pack/plugins/monitoring/server/routes/api/v1/check_access/check_access.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/check_access/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/check_access/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/check_access/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/check_access/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/cluster.js b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js similarity index 77% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/cluster.js rename to x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js index b2c2db7ea793..8d6fe04cdb7b 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/cluster.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClustersFromRequest } from '../../../../lib/cluster/get_clusters_from_request'; import { handleError } from '../../../../lib/errors'; import { getIndexPatterns } from '../../../../lib/cluster/get_index_patterns'; @@ -19,24 +19,22 @@ export function clusterRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - codePaths: Joi.array() - .items(Joi.string().required()) - .required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + codePaths: schema.arrayOf(schema.string()), }), }, }, handler: async req => { - await verifyCcsAvailability(req); const config = server.config(); + await verifyCcsAvailability(req); const indexPatterns = getIndexPatterns(server, { filebeatIndexPattern: config.get('monitoring.ui.logs.index'), diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/clusters.js b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js similarity index 85% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/clusters.js rename to x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js index 92f036709722..014f22c1ffe1 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/clusters.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClustersFromRequest } from '../../../../lib/cluster/get_clusters_from_request'; import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth'; import { verifyCcsAvailability } from '../../../../lib/elasticsearch/verify_ccs_availability'; @@ -21,20 +21,18 @@ export function clustersRoute(server) { path: '/api/monitoring/v1/clusters', config: { validate: { - payload: Joi.object({ - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - codePaths: Joi.array() - .items(Joi.string().required()) - .required(), + body: schema.object({ + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + codePaths: schema.arrayOf(schema.string()), }), }, }, handler: async req => { - const config = server.config(); let clusters = []; + const config = server.config(); // NOTE using try/catch because checkMonitoringAuth is expected to throw // an error when current logged-in user doesn't have permission to read diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/cluster/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/cluster/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js similarity index 96% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js index fcdf4ad8a706..b16a83199a72 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import moment from 'moment'; import { get, groupBy } from 'lodash'; import { handleError } from '../../../../lib/errors/handle_error'; @@ -174,15 +174,15 @@ export function ccrRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/ccr', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js similarity index 90% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js index 9dc2f62d74b3..4ee6cfe7fc54 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js @@ -6,7 +6,7 @@ import { get } from 'lodash'; import moment from 'moment'; -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getMetrics } from '../../../../lib/details/get_metrics'; @@ -74,17 +74,17 @@ export function ccrShardRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/ccr/{index}/shard/{shardId}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - index: Joi.string().required(), - shardId: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + index: schema.string(), + shardId: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js similarity index 90% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js index 6f03459acf28..0d589146878d 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js @@ -5,7 +5,7 @@ */ import { get } from 'lodash'; -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStats } from '../../../../lib/cluster/get_cluster_stats'; import { getIndexSummary } from '../../../../lib/elasticsearch/indices'; import { getMetrics } from '../../../../lib/details/get_metrics'; @@ -24,17 +24,17 @@ export function esIndexRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/indices/{id}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - id: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + id: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - is_advanced: Joi.boolean().required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + is_advanced: schema.boolean(), }), }, }, @@ -50,7 +50,7 @@ export function esIndexRoute(server) { const filebeatIndexPattern = prefixIndexPattern( config, config.get('monitoring.ui.logs.index'), - ccs + '*' ); const isAdvanced = req.payload.is_advanced; const metricSet = isAdvanced ? metricSetAdvanced : metricSetOverview; diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js similarity index 83% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js index 241b54fbf0c2..2911f13e459c 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStats } from '../../../../lib/cluster/get_cluster_stats'; import { getClusterStatus } from '../../../../lib/cluster/get_cluster_status'; import { getIndices } from '../../../../lib/elasticsearch/indices'; @@ -19,18 +19,18 @@ export function esIndicesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/indices', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - query: Joi.object({ - show_system_indices: Joi.boolean(), + query: schema.object({ + show_system_indices: schema.boolean(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_index_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_index_detail.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_index_detail.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_index_detail.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_node_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_node_detail.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_node_detail.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_node_detail.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_overview.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/metric_set_overview.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js similarity index 85% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js index de3b9863d914..c24b5bc2d080 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStats } from '../../../../lib/cluster/get_cluster_stats'; import { getClusterStatus } from '../../../../lib/cluster/get_cluster_status'; import { getMlJobs } from '../../../../lib/elasticsearch/get_ml_jobs'; @@ -19,15 +19,15 @@ export function mlJobRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/ml_jobs', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js similarity index 89% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js index 364214d45c2d..0156ea222217 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js @@ -5,7 +5,7 @@ */ import { get } from 'lodash'; -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStats } from '../../../../lib/cluster/get_cluster_stats'; import { getNodeSummary } from '../../../../lib/elasticsearch/nodes'; import { getShardStats, getShardAllocation } from '../../../../lib/elasticsearch/shards'; @@ -24,18 +24,18 @@ export function esNodeRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/nodes/{nodeUuid}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - nodeUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + nodeUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - showSystemIndices: Joi.boolean().default(false), // show/hide system indices in shard allocation table - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - is_advanced: Joi.boolean().required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + showSystemIndices: schema.boolean({ defaultValue: false }), // show/hide system indices in shard allocation table + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + is_advanced: schema.boolean(), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js similarity index 79% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js index fb2d04ecc041..36951f08975c 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStats } from '../../../../lib/cluster/get_cluster_stats'; import { getClusterStatus } from '../../../../lib/cluster/get_cluster_status'; import { getNodes } from '../../../../lib/elasticsearch/nodes'; @@ -22,27 +22,24 @@ export function esNodesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch/nodes', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - pagination: Joi.object({ - index: Joi.number().required(), - size: Joi.number().required(), - }).required(), - sort: Joi.object({ - field: Joi.string().required(), - direction: Joi.string().required(), - }).optional(), - queryText: Joi.string() - .default('') - .allow('') - .optional(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + pagination: schema.object({ + index: schema.number(), + size: schema.number(), + }), + sort: schema.object({ + field: schema.string({ defaultValue: '' }), + direction: schema.string({ defaultValue: '' }), + }), + queryText: schema.string({ defaultValue: '' }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js similarity index 88% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js index df1e847c1660..33220b040d8d 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStats } from '../../../../lib/cluster/get_cluster_stats'; import { getClusterStatus } from '../../../../lib/cluster/get_cluster_status'; import { getLastRecovery } from '../../../../lib/elasticsearch/get_last_recovery'; @@ -22,15 +22,15 @@ export function esOverviewRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/elasticsearch', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/cluster.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/cluster.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/cluster.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/cluster.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/nodes.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/nodes.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/nodes.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/check/nodes.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_enabled.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_enabled.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_enabled.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_enabled.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_interval.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_interval.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_interval.js rename to x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch_settings/set/collection_interval.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/_get_kibana_cluster_status.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/_get_kibana_cluster_status.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/_get_kibana_cluster_status.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/_get_kibana_cluster_status.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/instance.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js similarity index 82% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/instance.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js index 4135757860fe..02229de37286 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/instance.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getKibanaInfo } from '../../../../lib/kibana/get_kibana_info'; import { handleError } from '../../../../lib/errors'; import { getMetrics } from '../../../../lib/details/get_metrics'; @@ -24,16 +24,16 @@ export function kibanaInstanceRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/kibana/{kibanaUuid}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - kibanaUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + kibanaUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/instances.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js similarity index 82% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/instances.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js index 3136940dd253..3fde25578947 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/instances.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getKibanaClusterStatus } from './_get_kibana_cluster_status'; import { getKibanas } from '../../../../lib/kibana/get_kibanas'; @@ -20,15 +20,15 @@ export function kibanaInstancesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/kibana/instances', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/metric_set_instance.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/metric_set_instance.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/metric_set_instance.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/metric_set_instance.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/metric_set_overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/metric_set_overview.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/metric_set_overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/metric_set_overview.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js similarity index 82% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js index 208cc5d55ab8..f47a8f791fa0 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/kibana/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getKibanaClusterStatus } from './_get_kibana_cluster_status'; import { getMetrics } from '../../../../lib/details/get_metrics'; @@ -21,15 +21,15 @@ export function kibanaOverviewRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/kibana', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/metric_set_node.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/metric_set_node.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/metric_set_node.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/metric_set_node.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/metric_set_overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/metric_set_overview.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/metric_set_overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/metric_set_overview.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/node.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js similarity index 85% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/node.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js index bd3ae5f5c267..f2a337b3cfa2 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/node.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getNodeInfo } from '../../../../lib/logstash/get_node_info'; import { handleError } from '../../../../lib/errors'; import { getMetrics } from '../../../../lib/details/get_metrics'; @@ -33,17 +33,17 @@ export function logstashNodeRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/logstash/node/{logstashUuid}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - logstashUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + logstashUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - is_advanced: Joi.boolean().required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + is_advanced: schema.boolean(), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/nodes.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js similarity index 83% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/nodes.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js index f2d396913f94..009aab6c18ee 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/nodes.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStatus } from '../../../../lib/logstash/get_cluster_status'; import { getNodes } from '../../../../lib/logstash/get_nodes'; import { handleError } from '../../../../lib/errors'; @@ -30,15 +30,15 @@ export function logstashNodesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/logstash/nodes', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js similarity index 84% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/overview.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js index 35ef337a3faf..c90bee294f90 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStatus } from '../../../../lib/logstash/get_cluster_status'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { handleError } from '../../../../lib/errors'; @@ -31,15 +31,15 @@ export function logstashOverviewRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/logstash', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js similarity index 88% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js index 2999fb73d2df..8f19d164ad5d 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { handleError } from '../../../../lib/errors'; import { getPipelineVersions } from '../../../../lib/logstash/get_pipeline_versions'; import { getPipeline } from '../../../../lib/logstash/get_pipeline'; @@ -35,14 +35,14 @@ export function logstashPipelineRoute(server) { '/api/monitoring/v1/clusters/{clusterUuid}/logstash/pipeline/{pipelineId}/{pipelineHash?}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - pipelineId: Joi.string().required(), - pipelineHash: Joi.string().optional(), + params: schema.object({ + clusterUuid: schema.string(), + pipelineId: schema.string(), + pipelineHash: schema.maybe(schema.string()), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - detailVertexId: Joi.string().optional(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + detailVertexId: schema.maybe(schema.string()), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js similarity index 80% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js index 93330880babc..f96a534a1eab 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipeline_ids.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { handleError } from '../../../../../lib/errors'; import { prefixIndexPattern } from '../../../../../lib/ccs_utils'; import { INDEX_PATTERN_LOGSTASH } from '../../../../../../common/constants'; @@ -19,15 +19,15 @@ export function logstashClusterPipelineIdsRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/logstash/pipeline_ids', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js similarity index 74% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js index 87c8b8519360..4491b0289dcf 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getClusterStatus } from '../../../../../lib/logstash/get_cluster_status'; import { handleError } from '../../../../../lib/errors'; import { prefixIndexPattern } from '../../../../../lib/ccs_utils'; @@ -20,27 +20,26 @@ export function logstashClusterPipelinesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/logstash/pipelines', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - pagination: Joi.object({ - index: Joi.number().required(), - size: Joi.number().required(), - }).required(), - sort: Joi.object({ - field: Joi.string().required(), - direction: Joi.string().required(), - }).optional(), - queryText: Joi.string() - .default('') - .allow('') - .optional(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + pagination: schema.object({ + index: schema.number(), + size: schema.number(), + }), + sort: schema.maybe( + schema.object({ + field: schema.string(), + direction: schema.string(), + }) + ), + queryText: schema.string({ defaultValue: '' }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js similarity index 73% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js rename to x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js index 089cf36b8b26..b14b24ba3e81 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { getNodeInfo } from '../../../../../lib/logstash/get_node_info'; import { handleError } from '../../../../../lib/errors'; import { prefixIndexPattern } from '../../../../../lib/ccs_utils'; @@ -20,28 +20,27 @@ export function logstashNodePipelinesRoute(server) { path: '/api/monitoring/v1/clusters/{clusterUuid}/logstash/node/{logstashUuid}/pipelines', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), - logstashUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), + logstashUuid: schema.string(), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).required(), - pagination: Joi.object({ - index: Joi.number().required(), - size: Joi.number().required(), - }).required(), - sort: Joi.object({ - field: Joi.string().required(), - direction: Joi.string().required(), - }).optional(), - queryText: Joi.string() - .default('') - .allow('') - .optional(), + payload: schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string(), + max: schema.string(), + }), + pagination: schema.object({ + index: schema.number(), + size: schema.number(), + }), + sort: schema.maybe( + schema.object({ + field: schema.string(), + direction: schema.string(), + }) + ), + queryText: schema.string({ defaultValue: '' }), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js b/x-pack/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js similarity index 80% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js rename to x-pack/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js index 2b6f3b6e71d0..a4b811b88ee8 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js @@ -3,7 +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 Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth'; import { handleError } from '../../../../lib/errors'; import { getCollectionStatus } from '../../../../lib/setup/collection'; @@ -19,10 +19,10 @@ export function clusterSetupStatusRoute(server) { path: '/api/monitoring/v1/setup/collection/cluster/{clusterUuid?}', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().optional(), + params: schema.object({ + clusterUuid: schema.maybe(schema.string()), }), - query: Joi.object({ + query: schema.object({ // This flag is not intended to be used in production. It was introduced // as a way to ensure consistent API testing - the typical data source // for API tests are archived data, where the cluster configuration and data @@ -31,15 +31,17 @@ export function clusterSetupStatusRoute(server) { // which will vary from environment to environment making it difficult // to write tests against. Therefore, this flag exists and should only be used // in our testing environment. - skipLiveData: Joi.boolean().default(false), + skipLiveData: schema.boolean({ defaultValue: false }), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).optional(), - }).allow(null), + payload: schema.nullable( + schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.object({ + min: schema.string({ defaultValue: '' }), + max: schema.string({ defaultValue: '' }), + }), + }) + ), }, }, handler: async req => { diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js b/x-pack/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js similarity index 91% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js rename to x-pack/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js index c6a3ce8438b7..d3bb5523c1a9 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/setup/disable_elasticsearch_internal_collection.js @@ -3,7 +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 Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth'; import { handleError } from '../../../../lib/errors'; import { setCollectionDisabled } from '../../../../lib/elasticsearch_settings/set/collection_disabled'; @@ -14,8 +14,8 @@ export function disableElasticsearchInternalCollectionRoute(server) { path: '/api/monitoring/v1/setup/collection/{clusterUuid}/disable_internal_collection', config: { validate: { - params: Joi.object({ - clusterUuid: Joi.string().required(), + params: schema.object({ + clusterUuid: schema.string(), }), }, }, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/setup/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/index.js rename to x-pack/plugins/monitoring/server/routes/api/v1/setup/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js b/x-pack/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js similarity index 81% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js rename to x-pack/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js index 2a615b887500..1612e501faa5 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js @@ -3,7 +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 Joi from 'joi'; +import { schema } from '@kbn/config-schema'; import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth'; import { handleError } from '../../../../lib/errors'; import { getCollectionStatus } from '../../../../lib/setup/collection'; @@ -19,10 +19,10 @@ export function nodeSetupStatusRoute(server) { path: '/api/monitoring/v1/setup/collection/node/{nodeUuid}', config: { validate: { - params: Joi.object({ - nodeUuid: Joi.string().required(), + params: schema.object({ + nodeUuid: schema.string(), }), - query: Joi.object({ + query: schema.object({ // This flag is not intended to be used in production. It was introduced // as a way to ensure consistent API testing - the typical data source // for API tests are archived data, where the cluster configuration and data @@ -31,15 +31,19 @@ export function nodeSetupStatusRoute(server) { // which will vary from environment to environment making it difficult // to write tests against. Therefore, this flag exists and should only be used // in our testing environment. - skipLiveData: Joi.boolean().default(false), + skipLiveData: schema.boolean({ defaultValue: false }), }), - payload: Joi.object({ - ccs: Joi.string().optional(), - timeRange: Joi.object({ - min: Joi.date().required(), - max: Joi.date().required(), - }).optional(), - }).allow(null), + payload: schema.nullable( + schema.object({ + ccs: schema.maybe(schema.string()), + timeRange: schema.maybe( + schema.object({ + min: schema.string(), + max: schema.string(), + }) + ), + }) + ), }, }, handler: async req => { diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/ui.js b/x-pack/plugins/monitoring/server/routes/api/v1/ui.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/api/v1/ui.js rename to x-pack/plugins/monitoring/server/routes/api/v1/ui.js diff --git a/x-pack/legacy/plugins/monitoring/server/routes/index.js b/x-pack/plugins/monitoring/server/routes/index.js similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/routes/index.js rename to x-pack/plugins/monitoring/server/routes/index.js diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/__mocks__/fixtures/beats_stats_results.json b/x-pack/plugins/monitoring/server/telemetry_collection/__mocks__/fixtures/beats_stats_results.json similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/__mocks__/fixtures/beats_stats_results.json rename to x-pack/plugins/monitoring/server/telemetry_collection/__mocks__/fixtures/beats_stats_results.json diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/create_query.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/create_query.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/create_query.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/create_query.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/create_query.ts b/x-pack/plugins/monitoring/server/telemetry_collection/create_query.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/create_query.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/create_query.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_all_stats.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_all_stats.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_all_stats.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_all_stats.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_all_stats.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_all_stats.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_all_stats.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_all_stats.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_beats_stats.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_beats_stats.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts similarity index 91% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts index 4738ab5b8af8..46b3007ae80e 100644 --- a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts +++ b/x-pack/plugins/monitoring/server/telemetry_collection/get_cluster_uuids.ts @@ -14,12 +14,12 @@ import { ClusterDetailsGetter, StatsCollectionConfig, ClusterDetails, -} from '../../../../../../src/legacy/core_plugins/telemetry/server/collection_manager'; +} from '../../../../../src/legacy/core_plugins/telemetry/server/collection_manager'; /** * Get a list of Cluster UUIDs that exist within the specified timespan. */ -export const getClusterUuids: ClusterDetailsGetter = async config => { +export const getClusterUuids: ClusterDetailsGetter = async (config: any) => { const response = await fetchClusterUuids(config); return handleClusterUuidsResponse(response); }; diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_es_stats.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_es_stats.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_es_stats.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_es_stats.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_es_stats.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_es_stats.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_es_stats.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_es_stats.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_high_level_stats.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_high_level_stats.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_high_level_stats.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_high_level_stats.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_high_level_stats.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_high_level_stats.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_high_level_stats.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_high_level_stats.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_kibana_stats.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_kibana_stats.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_kibana_stats.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_kibana_stats.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_kibana_stats.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_kibana_stats.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_kibana_stats.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_kibana_stats.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_licenses.test.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_licenses.test.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_licenses.test.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_licenses.test.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_licenses.ts b/x-pack/plugins/monitoring/server/telemetry_collection/get_licenses.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_licenses.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/get_licenses.ts diff --git a/x-pack/legacy/plugins/monitoring/server/telemetry_collection/index.ts b/x-pack/plugins/monitoring/server/telemetry_collection/index.ts similarity index 100% rename from x-pack/legacy/plugins/monitoring/server/telemetry_collection/index.ts rename to x-pack/plugins/monitoring/server/telemetry_collection/index.ts diff --git a/x-pack/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts b/x-pack/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts new file mode 100644 index 000000000000..7bc4e9cbf755 --- /dev/null +++ b/x-pack/plugins/monitoring/server/telemetry_collection/register_monitoring_collection.ts @@ -0,0 +1,33 @@ +/* + * 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 { ICustomClusterClient } from 'kibana/server'; +import { Cluster } from 'src/legacy/core_plugins/elasticsearch'; +// @ts-ignore +import { getAllStats } from './get_all_stats'; +import { getClusterUuids } from './get_cluster_uuids'; +import { getLicenses } from './get_licenses'; + +export function registerMonitoringCollection( + cluster: ICustomClusterClient, + telemetryCollectionManager: any +) { + // Create a legacy wrapper since telemetry is still in the legacy plugins + const legacyCluster: Cluster = { + callWithRequest: async (req: any, endpoint: string, params: any) => + cluster.asScoped(req).callAsCurrentUser(endpoint, params), + callWithInternalUser: (endpoint: string, params: any) => + cluster.callAsInternalUser(endpoint, params), + }; + telemetryCollectionManager.setCollection({ + esCluster: legacyCluster, + title: 'monitoring', + priority: 2, + statsGetter: getAllStats, + clusterDetailsGetter: getClusterUuids, + licenseGetter: getLicenses, + }); +} diff --git a/x-pack/plugins/monitoring/server/types.ts b/x-pack/plugins/monitoring/server/types.ts new file mode 100644 index 000000000000..9f30ed1ba503 --- /dev/null +++ b/x-pack/plugins/monitoring/server/types.ts @@ -0,0 +1,21 @@ +/* + * 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 { Observable } from 'rxjs'; +import { LicenseFeature, ILicense } from '../../licensing/server'; + +export interface MonitoringLicenseService { + refresh: () => Promise; + license$: Observable; + getMessage: () => string | undefined; + getWatcherFeature: () => LicenseFeature; + getMonitoringFeature: () => LicenseFeature; + getSecurityFeature: () => LicenseFeature; + stop: () => void; +} + +export interface MonitoringElasticsearchConfig { + hosts: string[]; +} diff --git a/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js b/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js index 73b3f5f97c6f..d5a72fa0ae3c 100644 --- a/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js +++ b/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js @@ -6,11 +6,11 @@ import expect from '@kbn/expect'; import { get } from 'lodash'; -import * as esMetrics from '../../../../../legacy/plugins/monitoring/server/lib/metrics/elasticsearch/metrics'; -import * as kibanaMetrics from '../../../../../legacy/plugins/monitoring/server/lib/metrics/kibana/metrics'; -import * as logstashMetrics from '../../../../../legacy/plugins/monitoring/server/lib/metrics/logstash/metrics'; -import * as beatsMetrics from '../../../../../legacy/plugins/monitoring/server/lib/metrics/beats/metrics'; -import * as apmMetrics from '../../../../../legacy/plugins/monitoring/server/lib/metrics/apm/metrics'; +import * as esMetrics from '../../../../../plugins/monitoring/server/lib/metrics/elasticsearch/metrics'; +import * as kibanaMetrics from '../../../../../plugins/monitoring/server/lib/metrics/kibana/metrics'; +import * as logstashMetrics from '../../../../../plugins/monitoring/server/lib/metrics/logstash/metrics'; +import * as beatsMetrics from '../../../../../plugins/monitoring/server/lib/metrics/beats/metrics'; +import * as apmMetrics from '../../../../../plugins/monitoring/server/lib/metrics/apm/metrics'; export default function({ getService }) { const es = getService('legacyEs');