From 52d890fed7126eb2a154b0b9e9de13bd619d9c60 Mon Sep 17 00:00:00 2001 From: spalger Date: Sun, 3 Feb 2019 08:49:04 -0800 Subject: [PATCH] [beatscm] update to use seqNo/primaryTerm, remove unused method --- .../lib/adapters/database/adapter_types.ts | 50 ++++++++----------- .../database/kibana_database_adapter.ts | 39 --------------- 2 files changed, 22 insertions(+), 67 deletions(-) diff --git a/x-pack/plugins/beats_management/server/lib/adapters/database/adapter_types.ts b/x-pack/plugins/beats_management/server/lib/adapters/database/adapter_types.ts index 40642fb56359f..c56bc6d72c7a7 100644 --- a/x-pack/plugins/beats_management/server/lib/adapters/database/adapter_types.ts +++ b/x-pack/plugins/beats_management/server/lib/adapters/database/adapter_types.ts @@ -100,8 +100,8 @@ export interface DatabaseSearchResponse { _id: string; _score: number; _source: T; - // TODO-VERSION - _version?: number; + _seq_no?: number; + _primary_term?: number; _explanation?: DatabaseExplanation; fields?: any; highlight?: any; @@ -129,8 +129,8 @@ export interface DatabaseGetDocumentResponse { _index: string; _type: string; _id: string; - // TODO-VERSION - _version: number; + _seq_no: number; + _primary_term: number; found: boolean; _source: Source; } @@ -184,9 +184,8 @@ export interface DatabaseDeleteDocumentParams extends DatabaseGenericParams { refresh?: DatabaseRefresh; routing?: string; timeout?: string; - // TODO-VERSION - version?: number; - versionType?: DatabaseVersionType; + ifSeqNo?: number; + ifPrimaryTerm?: number; index: string; type: string; id: string; @@ -197,8 +196,8 @@ export interface DatabaseIndexDocumentResponse { _index: string; _type: string; _id: string; - // TODO-VERSION - _version: number; + _seq_no: number; + _primary_term: number; result: string; } @@ -207,8 +206,8 @@ export interface DatabaseUpdateDocumentResponse { _index: string; _type: string; _id: string; - // TODO-VERSION - _version: number; + _seq_no: number; + _primary_term: number; result: string; } @@ -217,8 +216,8 @@ export interface DatabaseDeleteDocumentResponse { _index: string; _type: string; _id: string; - // TODO-VERSION - _version: number; + _seq_no: number; + _primary_term: number; result: string; } @@ -231,9 +230,8 @@ export interface DatabaseIndexDocumentParams extends DatabaseGenericParams { timeout?: string; timestamp?: Date | number; ttl?: string; - // TODO-VERSION - version?: number; - versionType?: DatabaseVersionType; + ifSeqNo?: number; + ifPrimaryTerm?: number; pipeline?: string; id?: string; index: string; @@ -253,9 +251,8 @@ export interface DatabaseCreateDocumentParams extends DatabaseGenericParams { timeout?: string; timestamp?: Date | number; ttl?: string; - // TODO-VERSION - version?: number; - versionType?: DatabaseVersionType; + ifSeqNo?: number; + ifPrimaryTerm?: number; pipeline?: string; id?: string; index: string; @@ -273,9 +270,8 @@ export interface DatabaseDeleteDocumentParams extends DatabaseGenericParams { refresh?: DatabaseRefresh; routing?: string; timeout?: string; - // TODO-VERSION - version?: number; - versionType?: DatabaseVersionType; + ifSeqNo?: number; + ifPrimaryTerm?: number; index: string; type: string; id: string; @@ -291,9 +287,8 @@ export interface DatabaseGetParams extends DatabaseGenericParams { _source?: DatabaseNameList; _sourceExclude?: DatabaseNameList; _source_includes?: DatabaseNameList; - // TODO-VERSION - version?: number; - versionType?: DatabaseVersionType; + ifSeqNo?: number; + ifPrimaryTerm?: number; id: string; index: string; type: string; @@ -301,7 +296,6 @@ export interface DatabaseGetParams extends DatabaseGenericParams { export type DatabaseNameList = string | string[] | boolean; export type DatabaseRefresh = boolean | 'true' | 'false' | 'wait_for' | ''; -export type DatabaseVersionType = 'internal' | 'external' | 'external_gte' | 'force'; export type ExpandWildcards = 'open' | 'closed' | 'none' | 'all'; export type DefaultOperator = 'AND' | 'OR'; export type DatabaseConflicts = 'abort' | 'proceed'; @@ -320,7 +314,7 @@ export interface DatabaseDeleteDocumentResponse { _index: string; _type: string; _id: string; - // TODO-VERSION - _version: number; + _seq_no: number; + _primary_term: number; result: string; } diff --git a/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts b/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts index 2aab29417559c..8bec4307d46eb 100644 --- a/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts +++ b/x-pack/plugins/beats_management/server/lib/adapters/database/kibana_database_adapter.ts @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { get } from 'lodash'; import { INDEX_NAMES } from 'x-pack/plugins/beats_management/common/constants'; import { beatsIndexTemplate } from '../../../utils/index_templates'; import { FrameworkUser } from '../framework/adapter_types'; @@ -120,44 +119,6 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter { return result; } - private async fetchAllFromScroll( - user: FrameworkUser, - response: DatabaseSearchResponse, - hits: DatabaseSearchResponse['hits']['hits'] = [] - ): Promise< - Array<{ - _index: string; - _type: string; - _id: string; - _score: number; - _source: Source; - // TODO-VERSION - _version?: number; - fields?: any; - highlight?: any; - inner_hits?: any; - sort?: string[]; - }> - > { - const newHits = get(response, 'hits.hits', []); - const scrollId = get(response, '_scroll_id'); - - if (newHits.length > 0) { - hits.push(...newHits); - - return this.callWithUser(user, 'scroll', { - body: { - scroll: '30s', - scroll_id: scrollId, - }, - }).then((innerResponse: DatabaseSearchResponse) => { - return this.fetchAllFromScroll(user, innerResponse, hits); - }); - } - - return Promise.resolve(hits); - } - private callWithUser(user: FrameworkUser, esMethod: string, options: any = {}): any { if (user.kind === 'authenticated') { return this.es.callWithRequest(