-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Index Management] Support Hidden Indices #66422
Changes from all commits
ccd4f46
9ca7880
956d511
7b583c5
11d1ef9
7457ae6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ | |
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { CatIndicesParams } from 'elasticsearch'; | ||
import { IndexDataEnricher } from '../services'; | ||
import { Index, CallAsCurrentUser } from '../types'; | ||
import { fetchAliases } from './fetch_aliases'; | ||
|
||
interface Hit { | ||
health: string; | ||
|
@@ -17,20 +17,64 @@ interface Hit { | |
'docs.count': any; | ||
'store.size': any; | ||
sth: 'true' | 'false'; | ||
hidden: boolean; | ||
} | ||
|
||
interface Aliases { | ||
[key: string]: string[]; | ||
interface IndexInfo { | ||
aliases: { [aliasName: string]: unknown }; | ||
mappings: unknown; | ||
settings: { | ||
index: { | ||
hidden: 'true' | 'false'; | ||
}; | ||
}; | ||
} | ||
|
||
interface Params { | ||
format: string; | ||
h: string; | ||
index?: string[]; | ||
interface GetIndicesResponse { | ||
[indexName: string]: IndexInfo; | ||
} | ||
|
||
function formatHits(hits: Hit[], aliases: Aliases): Index[] { | ||
return hits.map((hit: Hit) => { | ||
async function fetchIndicesCall( | ||
callAsCurrentUser: CallAsCurrentUser, | ||
indexNames?: string[] | ||
): Promise<Index[]> { | ||
const indexNamesString = indexNames && indexNames.length ? indexNames.join(',') : '*'; | ||
|
||
// This call retrieves alias and settings (incl. hidden status) information about indices | ||
const indices: GetIndicesResponse = await callAsCurrentUser('transport.request', { | ||
method: 'GET', | ||
path: `/${indexNamesString}`, | ||
query: { | ||
expand_wildcards: 'hidden,all', | ||
}, | ||
}); | ||
|
||
if (!Object.keys(indices).length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we know that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spoke to @danhermann about this, he mentioned that both |
||
return []; | ||
} | ||
|
||
const catQuery: Pick<CatIndicesParams, 'format' | 'h'> & { | ||
expand_wildcards: string; | ||
index?: string; | ||
} = { | ||
format: 'json', | ||
h: 'health,status,index,uuid,pri,rep,docs.count,sth,store.size', | ||
expand_wildcards: 'hidden,all', | ||
index: indexNamesString, | ||
}; | ||
|
||
// This call retrieves health and other high-level information about indices. | ||
const catHits: Hit[] = await callAsCurrentUser('transport.request', { | ||
method: 'GET', | ||
path: '/_cat/indices', | ||
query: catQuery, | ||
}); | ||
|
||
// The two responses should be equal in the number of indices returned | ||
return catHits.map(hit => { | ||
const index = indices[hit.index]; | ||
const aliases = Object.keys(index.aliases); | ||
|
||
return { | ||
health: hit.health, | ||
status: hit.status, | ||
|
@@ -41,32 +85,17 @@ function formatHits(hits: Hit[], aliases: Aliases): Index[] { | |
documents: hit['docs.count'], | ||
size: hit['store.size'], | ||
isFrozen: hit.sth === 'true', // sth value coming back as a string from ES | ||
aliases: aliases.hasOwnProperty(hit.index) ? aliases[hit.index] : 'none', | ||
aliases: aliases.length ? aliases : 'none', | ||
hidden: index.settings.index.hidden === 'true', | ||
}; | ||
}); | ||
} | ||
|
||
async function fetchIndicesCall(callAsCurrentUser: CallAsCurrentUser, indexNames?: string[]) { | ||
const params: Params = { | ||
format: 'json', | ||
h: 'health,status,index,uuid,pri,rep,docs.count,sth,store.size', | ||
}; | ||
|
||
if (indexNames) { | ||
params.index = indexNames; | ||
} | ||
|
||
return await callAsCurrentUser('cat.indices', params); | ||
} | ||
|
||
export const fetchIndices = async ( | ||
callAsCurrentUser: CallAsCurrentUser, | ||
indexDataEnricher: IndexDataEnricher, | ||
indexNames?: string[] | ||
) => { | ||
const aliases = await fetchAliases(callAsCurrentUser); | ||
const hits = await fetchIndicesCall(callAsCurrentUser, indexNames); | ||
const indices = formatHits(hits, aliases); | ||
|
||
const indices = await fetchIndicesCall(callAsCurrentUser, indexNames); | ||
return await indexDataEnricher.enrichIndices(indices, callAsCurrentUser); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also feel like you're reading the docs? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂 quite!