Skip to content

Commit

Permalink
[Onboarding] Increasing telemetry coverage (elastic#195741)
Browse files Browse the repository at this point in the history
## Summary

Adding telemetry coverage for onboarding.

Also adds the eslint rule which warns of elements that do not have a
data-test-subj for telemetry needs.

![Screenshot 2024-10-10 at 20 07
20](https://github.com/user-attachments/assets/5ea449d9-01da-4a1c-8b5a-da727e0f2c49)

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 4aa491d)
  • Loading branch information
joemcelroy committed Oct 11, 2024
1 parent 8f86639 commit 58e83cb
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,12 @@ module.exports = {
'@kbn/telemetry/event_generating_elements_should_be_instrumented': 'error',
},
},
{
files: ['x-pack/plugins/search*/**/*.tsx', 'x-pack/packages/search/**/*.tsx'],
rules: {
'@kbn/telemetry/event_generating_elements_should_be_instrumented': 'warn',
},
},
{
files: [
'x-pack/plugins/observability_solution/**/!(*.stories.tsx|*.test.tsx|*.storybook_decorator.tsx|*.mock.tsx)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ApiKeyForm: React.FC<ApiKeyFormProps> = ({ hasTitle = true }) => {
value={displayedApiKey}
copyValue={apiKey}
dataTestSubj="apiKeyFormAPIKey"
copyValueDataTestSubj="APIKeyButtonCopy"
actions={[
<EuiButtonIcon
iconType={apiKeyIsVisible ? 'eyeClosed' : 'eye'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface TryInConsoleButtonProps {
content?: string | React.ReactElement;
showIcon?: boolean;
type?: 'link' | 'button' | 'emptyButton';
telemetryId?: string;
onClick?: () => void;
}
export const TryInConsoleButton = ({
request,
Expand All @@ -38,6 +40,8 @@ export const TryInConsoleButton = ({
content = RUN_IN_CONSOLE,
showIcon = true,
type = 'emptyButton',
telemetryId,
onClick: onClickProp,
}: TryInConsoleButtonProps) => {
const url = sharePlugin?.url;
const canShowDevtools = !!application?.capabilities?.dev_tools?.show;
Expand Down Expand Up @@ -65,6 +69,7 @@ export const TryInConsoleButton = ({
} else {
window.open(consolePreviewLink, '_blank', 'noreferrer');
}
onClickProp?.();
};

const getAriaLabel = () => {
Expand All @@ -84,6 +89,7 @@ export const TryInConsoleButton = ({
const commonProps = {
'data-test-subj': type === 'link' ? 'tryInConsoleLink' : 'tryInConsoleButton',
'aria-label': getAriaLabel(),
'data-telemetry-id': telemetryId,
onClick,
};
const iconType = showIcon ? 'play' : undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface FormInfoFieldProps {
value: string;
copyValue?: string;
dataTestSubj?: string;
copyValueDataTestSubj?: string;
}

export const FormInfoField: React.FC<FormInfoFieldProps> = ({
Expand All @@ -31,6 +32,7 @@ export const FormInfoField: React.FC<FormInfoFieldProps> = ({
value,
copyValue,
dataTestSubj,
copyValueDataTestSubj,
}) => {
const { euiTheme } = useEuiTheme();

Expand Down Expand Up @@ -71,6 +73,7 @@ export const FormInfoField: React.FC<FormInfoFieldProps> = ({
<EuiButtonIcon
onClick={copy}
iconType="copy"
data-test-subj={copyValueDataTestSubj}
aria-label={i18n.translate('xpack.searchSharedUI.formInfoField.copyMessage', {
defaultMessage: 'Copy to clipboard',
})}
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/search_indices/public/analytics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ export enum AnalyticsEvents {
startPageOpened = 'start_page_opened',
startPageShowCodeClick = 'start_page_show_code',
startPageShowCreateIndexUIClick = 'start_page_show_create_index_ui',
startCreateIndexPageModifyIndexName = 'start_modify_index_name',
startCreateIndexClick = 'start_create_index',
startCreateIndexLanguageSelect = 'start_code_lang_select',
startCreateIndexCodeCopyInstall = 'start_code_copy_install',
startCreateIndexCodeCopy = 'start_code_copy',
startCreateIndexRunInConsole = 'start_cta_run_in_console',
startCreateIndexCreatedRedirect = 'start_index_created_api',
startFileUploadClick = 'start_file_upload',
indexDetailsInstallCodeCopy = 'index_details_code_copy_install',
indexDetailsAddMappingsCodeCopy = 'index_details_add_mappings_code_copy',
indexDetailsIngestDocumentsCodeCopy = 'index_details_ingest_documents_code_copy',
indexDetailsNavDataTab = 'index_details_nav_data_tab',
indexDetailsNavSettingsTab = 'index_details_nav_settings_tab',
indexDetailsNavMappingsTab = 'index_details_nav_mappings_tab',
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const ConnectionDetails: React.FC = () => {
value={elasticsearchUrl}
copyValue={elasticsearchUrl}
dataTestSubj="connectionDetailsEndpoint"
copyValueDataTestSubj="connectionDetailsEndpointCopy"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { SearchIndexDetailsMappings } from './details_page_mappings';
import { SearchIndexDetailsSettings } from './details_page_settings';
import { SearchIndexDetailsPageMenuItemPopover } from './details_page_menu_item';
import { useIndexDocumentSearch } from '../../hooks/api/use_document_search';
import { useUsageTracker } from '../../contexts/usage_tracker_context';
import { AnalyticsEvents } from '../../analytics/constants';

export const SearchIndexDetailsPage = () => {
const indexName = decodeURIComponent(useParams<{ indexName: string }>().indexName);
Expand Down Expand Up @@ -69,6 +71,7 @@ export const SearchIndexDetailsPage = () => {
setDocumentsLoading(isInitialLoading);
setDocumentsExists(!(!isInitialLoading && indexDocuments?.results?.data.length === 0));
}, [indexDocuments, isInitialLoading, setDocumentsExists, setDocumentsLoading]);
const usageTracker = useUsageTracker();

const detailsPageTabs: EuiTabbedContentTab[] = useMemo(() => {
return [
Expand Down Expand Up @@ -114,9 +117,19 @@ export const SearchIndexDetailsPage = () => {
const handleTabClick = useCallback(
(tab: EuiTabbedContentTab) => {
history.push(`index_details/${indexName}/${tab.id}`);

const tabEvent = {
[SearchIndexDetailsTabs.DATA]: AnalyticsEvents.indexDetailsNavDataTab,
[SearchIndexDetailsTabs.MAPPINGS]: AnalyticsEvents.indexDetailsNavMappingsTab,
[SearchIndexDetailsTabs.SETTINGS]: AnalyticsEvents.indexDetailsNavSettingsTab,
}[tab.id];

if (tabEvent) {
usageTracker.click(tabEvent);
}
},

[history, indexName]
[history, indexName, usageTracker]
);
const embeddableConsole = useMemo(
() => (consolePlugin?.EmbeddableConsole ? <consolePlugin.EmbeddableConsole /> : null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ export const CreateIndexForm = ({
return;
}
usageTracker.click(AnalyticsEvents.startCreateIndexClick);

if (formState.defaultIndexName !== formState.indexName) {
usageTracker.click(AnalyticsEvents.startCreateIndexPageModifyIndexName);
}

createIndex({ indexName: formState.indexName });
},
[usageTracker, createIndex, formState.indexName]
[usageTracker, createIndex, formState.indexName, formState.defaultIndexName]
);
const onIndexNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newIndexName = e.target.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const CreateIndexCodeView = ({
application={application}
sharePlugin={share}
consolePlugin={consolePlugin}
telemetryId={`${selectedLanguage}_create_index`}
onClick={() => {
usageTracker.click([
AnalyticsEvents.startCreateIndexRunInConsole,
`${AnalyticsEvents.startCreateIndexRunInConsole}_${selectedLanguage}`,
]);
}}
/>
</EuiFlexItem>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import { CreateIndexFormState } from './types';
import { useKibana } from '../../hooks/use_kibana';

function initCreateIndexState(): CreateIndexFormState {
const defaultIndexName = generateRandomIndexName();
return {
indexName: generateRandomIndexName(),
indexName: defaultIndexName,
defaultIndexName,
codingLanguage: getDefaultCodingLanguage(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import type { IndicesStatusResponse } from '../../../../common';
import { useKibana } from '../../../hooks/use_kibana';

import { navigateToIndexDetails } from './utils';
import { useUsageTracker } from '../../../contexts/usage_tracker_context';
import { AnalyticsEvents } from '../../../analytics/constants';

export const useIndicesRedirect = (indicesStatus?: IndicesStatusResponse) => {
const { application, http } = useKibana().services;
const [lastStatus, setLastStatus] = useState<IndicesStatusResponse | undefined>(() => undefined);
const [hasDoneRedirect, setHasDoneRedirect] = useState(() => false);
const usageTracker = useUsageTracker();
return useEffect(() => {
if (hasDoneRedirect) {
return;
Expand All @@ -36,9 +39,18 @@ export const useIndicesRedirect = (indicesStatus?: IndicesStatusResponse) => {
if (indicesStatus.indexNames.length === 1) {
navigateToIndexDetails(application, http, indicesStatus.indexNames[0]);
setHasDoneRedirect(true);
usageTracker.click(AnalyticsEvents.startCreateIndexCreatedRedirect);
return;
}
application.navigateToApp('management', { deepLinkId: 'index_management' });
setHasDoneRedirect(true);
}, [application, http, indicesStatus, lastStatus, hasDoneRedirect]);
}, [
application,
http,
indicesStatus,
lastStatus,
setHasDoneRedirect,
usageTracker,
hasDoneRedirect,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import type { AvailableLanguages } from '../../code_examples';

export interface CreateIndexFormState {
indexName: string;
defaultIndexName: string;
codingLanguage: AvailableLanguages;
}

0 comments on commit 58e83cb

Please sign in to comment.