From 946632c6f1dd03684629df60a0889d240720ca8c Mon Sep 17 00:00:00 2001 From: Ying Mao Date: Tue, 20 Sep 2022 14:16:17 -0400 Subject: [PATCH] Changing triggers actions ui routes to internal --- .../alert_types/threshold/index_threshold_api.ts | 2 +- x-pack/plugins/triggers_actions_ui/common/index.ts | 2 +- .../public/common/lib/config_api.test.ts | 2 +- .../public/common/lib/data_apis.test.ts | 4 ++-- .../public/common/lib/data_apis.ts | 2 +- .../public/common/lib/health_api.test.ts | 2 +- .../triggers_actions_ui/server/data/README.md | 14 +++++++------- .../server/routes/config.test.ts | 4 ++-- .../index_threshold/fields_endpoint.ts | 2 +- .../index_threshold/indices_endpoint.ts | 2 +- .../index_threshold/time_series_query_endpoint.ts | 3 ++- 11 files changed, 20 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/stack_alerts/public/alert_types/threshold/index_threshold_api.ts b/x-pack/plugins/stack_alerts/public/alert_types/threshold/index_threshold_api.ts index a884d2230c2b9..d1e5613c659f7 100644 --- a/x-pack/plugins/stack_alerts/public/alert_types/threshold/index_threshold_api.ts +++ b/x-pack/plugins/stack_alerts/public/alert_types/threshold/index_threshold_api.ts @@ -9,7 +9,7 @@ import { HttpSetup } from '@kbn/core/public'; import { TimeSeriesResult } from '@kbn/triggers-actions-ui-plugin/common'; import { IndexThresholdAlertParams } from './types'; -const INDEX_THRESHOLD_DATA_API_ROOT = '/api/triggers_actions_ui/data'; +const INDEX_THRESHOLD_DATA_API_ROOT = '/internal/triggers_actions_ui/data'; export interface GetThresholdAlertVisualizationDataParams { model: IndexThresholdAlertParams; diff --git a/x-pack/plugins/triggers_actions_ui/common/index.ts b/x-pack/plugins/triggers_actions_ui/common/index.ts index bc9592a2e49f7..1675dee6129d9 100644 --- a/x-pack/plugins/triggers_actions_ui/common/index.ts +++ b/x-pack/plugins/triggers_actions_ui/common/index.ts @@ -9,6 +9,6 @@ /* eslint-disable @kbn/eslint/no_export_all */ export * from './data'; -export const BASE_TRIGGERS_ACTIONS_UI_API_PATH = '/api/triggers_actions_ui'; +export const BASE_TRIGGERS_ACTIONS_UI_API_PATH = '/internal/triggers_actions_ui'; export * from './parse_interval'; export * from './experimental_features'; diff --git a/x-pack/plugins/triggers_actions_ui/public/common/lib/config_api.test.ts b/x-pack/plugins/triggers_actions_ui/public/common/lib/config_api.test.ts index 765c6b2b7b12e..9f117b51c9cf8 100644 --- a/x-pack/plugins/triggers_actions_ui/public/common/lib/config_api.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/common/lib/config_api.test.ts @@ -17,7 +17,7 @@ describe('triggersActionsUiConfig', () => { expect(http.get.mock.calls).toMatchInlineSnapshot(` Array [ Array [ - "/api/triggers_actions_ui/_config", + "/internal/triggers_actions_ui/_config", ], ] `); diff --git a/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.test.ts b/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.test.ts index 178c891dc3a34..3f08c3e5f8449 100644 --- a/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.test.ts @@ -38,7 +38,7 @@ describe('Data API', () => { http.post.mockResolvedValueOnce(mockFields); const fields = await getESIndexFields({ indexes, http }); - expect(http.post).toHaveBeenCalledWith('/api/triggers_actions_ui/data/_fields', { + expect(http.post).toHaveBeenCalledWith('/internal/triggers_actions_ui/data/_fields', { body: `{"indexPatterns":${JSON.stringify(indexes)}}`, }); expect(fields).toEqual(mockFields.fields); @@ -50,7 +50,7 @@ describe('Data API', () => { http.post.mockResolvedValueOnce(mockIndices); const indices = await getMatchingIndices({ pattern, http }); - expect(http.post).toHaveBeenCalledWith('/api/triggers_actions_ui/data/_indices', { + expect(http.post).toHaveBeenCalledWith('/internal/triggers_actions_ui/data/_indices', { body: `{"pattern":"*${mockPattern}*"}`, }); expect(indices).toEqual(mockIndices.indices); diff --git a/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.ts b/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.ts index 90f80dd3dc2f0..fa4bf0a869861 100644 --- a/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.ts +++ b/x-pack/plugins/triggers_actions_ui/public/common/lib/data_apis.ts @@ -8,7 +8,7 @@ import { HttpSetup } from '@kbn/core/public'; import { DataViewsContract, DataView } from '@kbn/data-views-plugin/public'; -const DATA_API_ROOT = '/api/triggers_actions_ui/data'; +const DATA_API_ROOT = '/internal/triggers_actions_ui/data'; const formatPattern = (pattern: string) => { let formattedPattern = pattern; diff --git a/x-pack/plugins/triggers_actions_ui/public/common/lib/health_api.test.ts b/x-pack/plugins/triggers_actions_ui/public/common/lib/health_api.test.ts index 6454f726e934b..b668d58f5b7da 100644 --- a/x-pack/plugins/triggers_actions_ui/public/common/lib/health_api.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/common/lib/health_api.test.ts @@ -17,7 +17,7 @@ describe('triggersActionsUiHealth', () => { expect(http.get.mock.calls).toMatchInlineSnapshot(` Array [ Array [ - "/api/triggers_actions_ui/_health", + "/internal/triggers_actions_ui/_health", ], ] `); diff --git a/x-pack/plugins/triggers_actions_ui/server/data/README.md b/x-pack/plugins/triggers_actions_ui/server/data/README.md index 78577f0783008..696232d5a680a 100644 --- a/x-pack/plugins/triggers_actions_ui/server/data/README.md +++ b/x-pack/plugins/triggers_actions_ui/server/data/README.md @@ -6,9 +6,9 @@ The TriggersActionsUi plugin's Data Apis back the functionality needed by the In The following endpoints are provided for this alert type: -- `POST /api/triggers_actions_ui/data/_indices` -- `POST /api/triggers_actions_ui/data/_fields` -- `POST /api/triggers_actions_ui/data/_time_series_query` +- `POST /internal/triggers_actions_ui/data/_indices` +- `POST /internal/triggers_actions_ui/data/_fields` +- `POST /internal/triggers_actions_ui/data/_time_series_query` ### `POST .../_indices` @@ -79,7 +79,7 @@ provide a "preview" of the alert during creation/editing based on recent data, and could be used to show a "simulation" of the the alert over an arbitrary range of time. -The endpoint is `POST /api/triggers_actions_ui/data/_time_series_query`. +The endpoint is `POST /internal/triggers_actions_ui/data/_time_series_query`. The request and response bodies are specifed in [`lib/core_query_types.ts`][it-core-query] and @@ -93,7 +93,7 @@ for the last 10 seconds. This example uses [now-iso][] to generate iso date strings. ```console -curl -k "https://elastic:changeme@localhost:5601/api/triggers_actions_ui/data/_time_series_query" \ +curl -k "https://elastic:changeme@localhost:5601/internal/triggers_actions_ui/data/_time_series_query" \ -H "kbn-xsrf: foo" -H "content-type: application/json" -d "{ \"index\": \"es-hb-sim\", \"timeField\": \"@timestamp\", @@ -136,7 +136,7 @@ curl -k "https://elastic:changeme@localhost:5601/api/triggers_actions_ui/data/_ To get the current value of the calculated metric, you can leave off the date: ``` -curl -k "https://elastic:changeme@localhost:5601/api/triggers_actions_ui/data/_time_series_query" \ +curl -k "https://elastic:changeme@localhost:5601/internal/triggers_actions_ui/data/_time_series_query" \ -H "kbn-xsrf: foo" -H "content-type: application/json" -d '{ "index": "es-hb-sim", "timeField": "@timestamp", @@ -169,7 +169,7 @@ curl -k "https://elastic:changeme@localhost:5601/api/triggers_actions_ui/data/_ ## service functions A single service function is available that provides the functionality -of the http endpoint `POST /api/triggers_actions_ui/data/_time_series_query`, +of the http endpoint `POST /internal/triggers_actions_ui/data/_time_series_query`, but as an API for Kibana plugins. The function is available as `triggersActionsUi.data.timeSeriesQuery()` on the plugin's _Start_ contract diff --git a/x-pack/plugins/triggers_actions_ui/server/routes/config.test.ts b/x-pack/plugins/triggers_actions_ui/server/routes/config.test.ts index 79b5f6f85d4eb..9c32256f91bcc 100644 --- a/x-pack/plugins/triggers_actions_ui/server/routes/config.test.ts +++ b/x-pack/plugins/triggers_actions_ui/server/routes/config.test.ts @@ -12,13 +12,13 @@ describe('createConfigRoute', () => { it('registers the route', async () => { const router = httpServiceMock.createRouter(); const logger = loggingSystemMock.create().get(); - createConfigRoute(logger, router, `/api/triggers_actions_ui`, () => ({ + createConfigRoute(logger, router, `/internal/triggers_actions_ui`, () => ({ isUsingSecurity: true, minimumScheduleInterval: { value: '1m', enforce: false }, })); const [config, handler] = router.get.mock.calls[0]; - expect(config.path).toMatchInlineSnapshot(`"/api/triggers_actions_ui/_config"`); + expect(config.path).toMatchInlineSnapshot(`"/internal/triggers_actions_ui/_config"`); const mockResponse = httpServerMock.createResponseFactory(); await handler({}, httpServerMock.createKibanaRequest(), mockResponse); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/fields_endpoint.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/fields_endpoint.ts index 0a48e206e020e..37e71ac0e1a16 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/fields_endpoint.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/fields_endpoint.ts @@ -11,7 +11,7 @@ import { Spaces } from '../../../../scenarios'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; import { ESTestIndexTool, ES_TEST_INDEX_NAME, getUrlPrefix } from '../../../../../common/lib'; -const API_URI = 'api/triggers_actions_ui/data/_fields'; +const API_URI = 'internal/triggers_actions_ui/data/_fields'; // eslint-disable-next-line import/no-default-export export default function fieldsEndpointTests({ getService }: FtrProviderContext) { diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/indices_endpoint.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/indices_endpoint.ts index 894dd5848ee7e..fb70420d5f452 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/indices_endpoint.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/indices_endpoint.ts @@ -13,7 +13,7 @@ import { ESTestIndexTool, ES_TEST_INDEX_NAME, getUrlPrefix } from '../../../../. import { createEsDocumentsWithGroups } from '../lib/create_test_data'; import { createDataStream, deleteDataStream } from '../lib/create_test_data'; -const API_URI = 'api/triggers_actions_ui/data/_indices'; +const API_URI = 'internal/triggers_actions_ui/data/_indices'; // eslint-disable-next-line import/no-default-export export default function indicesEndpointTests({ getService }: FtrProviderContext) { diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/time_series_query_endpoint.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/time_series_query_endpoint.ts index 52fae5766e86e..5eee05a916da3 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/time_series_query_endpoint.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/builtin_alert_types/index_threshold/time_series_query_endpoint.ts @@ -14,7 +14,8 @@ import { ESTestIndexTool, ES_TEST_INDEX_NAME, getUrlPrefix } from '../../../../. import { createEsDocumentsWithGroups } from '../lib/create_test_data'; -const INDEX_THRESHOLD_TIME_SERIES_QUERY_URL = 'api/triggers_actions_ui/data/_time_series_query'; +const INDEX_THRESHOLD_TIME_SERIES_QUERY_URL = + 'internal/triggers_actions_ui/data/_time_series_query'; const START_DATE_MM_DD_HH_MM_SS_MS = '01-01T00:00:00.000Z'; const START_DATE = `2020-${START_DATE_MM_DD_HH_MM_SS_MS}`;