Skip to content

Commit

Permalink
Revert "[8.17] [search profiler] Move profile button inline with inde…
Browse files Browse the repository at this point in the history
…x field (#202253)" (#208650)

Reverts #207877

Too many changes for a patch release. Going to backport a subset of
#202253
  • Loading branch information
mattkime authored Jan 29, 2025
1 parent 890f48f commit a50aa46
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 117 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/searchprofiler/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { LicenseType } from '@kbn/licensing-plugin/common/types';

const basicLicense: LicenseType = 'basic';

export const API_BASE_PATH = '/api/searchprofiler';

/** @internal */
export const PLUGIN = Object.freeze({
id: 'searchprofiler',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import {
EuiForm,
EuiFieldText,
EuiFormRow,
EuiButtonIcon,
EuiButton,
EuiText,
EuiFlexGroup,
EuiSpacer,
EuiFlexItem,
EuiToolTip,
} from '@elastic/eui';

import { decompressFromEncodedURIComponent } from 'lz-string';

import { useHasIndices, useRequestProfile } from '../../hooks';
import { useRequestProfile } from '../../hooks';
import { useAppContext } from '../../contexts/app_context';
import { useProfilerActionContext } from '../../contexts/profiler_context';
import { Editor, type EditorProps } from './editor';
Expand All @@ -46,8 +47,6 @@ export const ProfileQueryEditor = memo(() => {

const { getLicenseStatus, notifications, location } = useAppContext();

const { data: indicesData, isLoading, error: indicesDataError } = useHasIndices();

const queryParams = new URLSearchParams(location.search);
const indexName = queryParams.get('index');
const searchProfilerQueryURI = queryParams.get('load_from');
Expand Down Expand Up @@ -88,26 +87,6 @@ export const ProfileQueryEditor = memo(() => {
);
const licenseEnabled = getLicenseStatus().valid;

const hasIndices = isLoading || indicesDataError ? false : indicesData?.hasIndices;

const isDisabled = !licenseEnabled || !hasIndices;
const tooltipContentDisabled = !licenseEnabled
? i18n.translate('xpack.searchProfiler.formProfileButton.noLicenseTooltip', {
defaultMessage: 'You need an active license to use Search Profiler',
})
: i18n.translate('xpack.searchProfiler.formProfileButton.noIndicesTooltip', {
defaultMessage: 'You must have at least one index to use Search Profiler',
});

const tooltipContentEnabled = i18n.translate(
'xpack.searchProfiler.sendRequestButtonTooltipContent',
{
defaultMessage: 'Click to send request',
}
);

const tooltipContent = isDisabled ? tooltipContentDisabled : tooltipContentEnabled;

return (
<EuiFlexGroup
responsive={false}
Expand All @@ -120,17 +99,15 @@ export const ProfileQueryEditor = memo(() => {
{/* Form */}
<EuiFlexItem grow={false}>
<EuiForm>
<EuiFlexGroup responsive={false} direction="row" gutterSize="s" alignItems="flexEnd">
<EuiFlexGroup direction="row" gutterSize="s">
<EuiFlexItem>
<EuiFormRow
fullWidth
label={i18n.translate('xpack.searchProfiler.formIndexLabel', {
defaultMessage: 'Index',
})}
>
<EuiFieldText
data-test-subj="indexName"
fullWidth
disabled={!licenseEnabled}
inputRef={(ref) => {
if (ref) {
Expand All @@ -141,21 +118,6 @@ export const ProfileQueryEditor = memo(() => {
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiToolTip content={tooltipContent}>
<EuiButtonIcon
iconType={'playFilled'}
data-test-subj={isDisabled ? 'disabledProfileButton' : 'profileButton'}
disabled={isDisabled}
onClick={!isDisabled ? handleProfileClick : undefined}
size="m"
display="base"
aria-label={i18n.translate('xpack.searchProfiler.formProfileButtonLabel', {
defaultMessage: 'Profile',
})}
/>
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiForm>
</EuiFlexItem>
Expand All @@ -174,6 +136,33 @@ export const ProfileQueryEditor = memo(() => {
licenseEnabled={licenseEnabled}
/>
</EuiFlexItem>

{/* Button */}
<EuiFlexItem grow={false}>
<EuiFlexGroup
className="prfDevTool__profileButtonContainer"
gutterSize="none"
direction="row"
>
<EuiFlexItem grow={5}>
<EuiSpacer size="s" />
</EuiFlexItem>
<EuiFlexItem grow={5}>
<EuiButton
data-test-subj="profileButton"
fill
disabled={!licenseEnabled}
onClick={() => handleProfileClick()}
>
<EuiText>
{i18n.translate('xpack.searchProfiler.formProfileButtonLabel', {
defaultMessage: 'Profile',
})}
</EuiText>
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
*/

export { useRequestProfile } from './use_request_profile';
export { useHasIndices } from './use_has_indices';

This file was deleted.

49 changes: 0 additions & 49 deletions x-pack/plugins/searchprofiler/server/routes/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { schema } from '@kbn/config-schema';
import { API_BASE_PATH } from '../../common/constants';
import { RouteDependencies } from '../types';

export const register = ({ router, getLicenseStatus, log }: RouteDependencies) => {
Expand Down Expand Up @@ -57,54 +56,6 @@ export const register = ({ router, getLicenseStatus, log }: RouteDependencies) =
log.error(err);
const { statusCode, body: errorBody } = err;

return response.customError({
statusCode: statusCode || 500,
body: errorBody
? {
message: errorBody.error?.reason,
attributes: errorBody,
}
: err,
});
}
}
);
router.get(
{
path: `${API_BASE_PATH}/has_indices`,
security: {
authz: {
enabled: false,
reason: 'Relies on es client for authorization',
},
},
validate: false,
},
async (ctx, _request, response) => {
const currentLicenseStatus = getLicenseStatus();
if (!currentLicenseStatus.valid) {
return response.forbidden({
body: {
message: currentLicenseStatus.message!,
},
});
}

try {
const client = (await ctx.core).elasticsearch.client.asCurrentUser;
const resp = await client.cat.indices({ format: 'json' });

const hasIndices = resp.length > 0;

return response.ok({
body: {
hasIndices,
},
});
} catch (err) {
log.error(err);
const { statusCode, body: errorBody } = err;

return response.customError({
statusCode: statusCode || 500,
body: errorBody
Expand Down

0 comments on commit a50aa46

Please sign in to comment.