diff --git a/x-pack/platform/plugins/private/watcher/common/constants/index_names.ts b/x-pack/platform/plugins/private/watcher/common/constants/index_names.ts index b854ecd047483..64425387dc138 100644 --- a/x-pack/platform/plugins/private/watcher/common/constants/index_names.ts +++ b/x-pack/platform/plugins/private/watcher/common/constants/index_names.ts @@ -5,7 +5,6 @@ * 2.0. */ -export const INDEX_NAMES: { [key: string]: string } = { - WATCHES: '.watches', +export const INDEX_NAMES = { WATCHER_HISTORY: '.watcher-history-*', }; diff --git a/x-pack/platform/plugins/private/watcher/server/plugin.ts b/x-pack/platform/plugins/private/watcher/server/plugin.ts index 75afac5c4d1f2..7572a63368d47 100644 --- a/x-pack/platform/plugins/private/watcher/server/plugin.ts +++ b/x-pack/platform/plugins/private/watcher/server/plugin.ts @@ -60,7 +60,6 @@ export class WatcherServerPlugin implements Plugin { { requiredClusterPrivileges: ['manage_watcher'], requiredIndexPrivileges: { - [INDEX_NAMES.WATCHES]: ['read'], [INDEX_NAMES.WATCHER_HISTORY]: ['read'], }, ui: [], @@ -68,7 +67,6 @@ export class WatcherServerPlugin implements Plugin { { requiredClusterPrivileges: ['monitor_watcher'], requiredIndexPrivileges: { - [INDEX_NAMES.WATCHES]: ['read'], [INDEX_NAMES.WATCHER_HISTORY]: ['read'], }, ui: [], diff --git a/x-pack/platform/plugins/private/watcher/server/routes/api/watches/register_list_route.ts b/x-pack/platform/plugins/private/watcher/server/routes/api/watches/register_list_route.ts index 9951da819e9e0..56affd6be154e 100644 --- a/x-pack/platform/plugins/private/watcher/server/routes/api/watches/register_list_route.ts +++ b/x-pack/platform/plugins/private/watcher/server/routes/api/watches/register_list_route.ts @@ -5,29 +5,9 @@ * 2.0. */ -import { IScopedClusterClient } from '@kbn/core/server'; -import { get } from 'lodash'; -import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll'; -import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../common/constants'; import { RouteDependencies } from '../../../types'; -// @ts-ignore import { Watch } from '../../../models/watch'; -function fetchWatches(dataClient: IScopedClusterClient) { - return dataClient.asCurrentUser - .search( - { - index: INDEX_NAMES.WATCHES, - scroll: ES_SCROLL_SETTINGS.KEEPALIVE, - body: { - size: ES_SCROLL_SETTINGS.PAGE_SIZE, - }, - }, - { ignore: [404] } - ) - .then((body) => fetchAllFromScroll(body, dataClient)); -} - export function registerListRoute({ router, license, lib: { handleEsError } }: RouteDependencies) { router.get( { @@ -37,17 +17,13 @@ export function registerListRoute({ router, license, lib: { handleEsError } }: R license.guardApiRoute(async (ctx, request, response) => { try { const esClient = (await ctx.core).elasticsearch.client; - const hits = await fetchWatches(esClient); - const watches = hits.map((hit: any) => { - const id = get(hit, '_id'); - const watchJson = get(hit, '_source'); - const watchStatusJson = get(hit, '_source.status'); - + const { watches: hits } = await esClient.asCurrentUser.watcher.queryWatches(); + const watches = hits.map(({ _id, watch, status }) => { return Watch.fromUpstreamJson( { - id, - watchJson, - watchStatusJson, + id: _id, + watchJson: watch, + watchStatusJson: status, }, { throwExceptions: { diff --git a/x-pack/test/functional/apps/index_management/feature_controls/index_management_security.ts b/x-pack/test/functional/apps/index_management/feature_controls/index_management_security.ts index 9d267f2ed7c33..8458ad6991541 100644 --- a/x-pack/test/functional/apps/index_management/feature_controls/index_management_security.ts +++ b/x-pack/test/functional/apps/index_management/feature_controls/index_management_security.ts @@ -73,7 +73,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { // The index_management_user has been given permissions to advanced settings for Stack Management Tests. // https://github.com/elastic/kibana/pull/113078/ - expect(sections).to.have.length(2); + expect(sections).to.have.length(3); expect(sections[0]).to.eql({ sectionId: 'data', sectionLinks: ['index_management', 'transform'],