import { IScopedClusterClient } from 'kibana/server' ; import { mlLog } from '../../lib/log' ; import { ML_ANNOTATIONS_INDEX_ALIAS_READ , ML_ANNOTATIONS_INDEX_ALIAS_WRITE , } from '../../../common/constants/index_patterns' ; export async function isAnnotationsFeatureAvailable ( { asInternalUser } ) { try { const { body : annotationsReadAliasExists } = await asInternalUser . indices . existsAlias ( { index : ML_ANNOTATIONS_INDEX_ALIAS_READ , name : ML_ANNOTATIONS_INDEX_ALIAS_READ , } ) ; if ( ! annotationsReadAliasExists ) { return false ; } const { body : annotationsWriteAliasExists } = await asInternalUser . indices . existsAlias ( { index : ML_ANNOTATIONS_INDEX_ALIAS_WRITE , name : ML_ANNOTATIONS_INDEX_ALIAS_WRITE , } ) ; if ( ! annotationsWriteAliasExists ) { return false ; } } catch ( err ) { mlLog . info ( 'Disabling ML annotations feature because the index/alias integrity check failed.' ) ; return false ; } return true ; }