-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Observability Onboarding] Add new telemetry hook for auto-detect flow (
#191028) ## Summary Resolves elastic/observability-dev#3856. Adds a new field to the onboarding telemetry event type and ships two new events, one for awaiting data and the other for receiving data. The new field is a string array that will indicate the integration package names the user has chosen. ~NOTE: I was unsure how much detail to include about the integrations in question. Right now, the event would ship `integration.title`, but perhaps we want to re-define the new field to include all the integration fields and have it contain that?~ There's information in the [comment below](#191028 (comment)) showing the types of data we will collect with these changes.
- Loading branch information
1 parent
fbe2da0
commit 1ad8851
Showing
5 changed files
with
233 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...oarding/public/application/quickstart_flows/auto_detect/use_auto_detect_telemetry.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { useAutoDetectTelemetry } from './use_auto_detect_telemetry'; | ||
import { ObservabilityOnboardingFlowStatus } from './get_onboarding_status'; | ||
import { OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT } from '../../../../common/telemetry_events'; | ||
|
||
jest.mock('@kbn/kibana-react-plugin/public', () => ({ | ||
useKibana: jest.fn(), | ||
})); | ||
|
||
describe('useAutoDetectTelemetry', () => { | ||
let reportEventMock: any; | ||
|
||
beforeEach(() => { | ||
reportEventMock = jest.fn(); | ||
(useKibana as jest.Mock).mockReturnValue({ | ||
services: { | ||
analytics: { | ||
reportEvent: reportEventMock, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it(`should report "awaiting_data" event when status is "awaitingData"`, () => { | ||
const expectedIntegration = { | ||
installSource: 'source1', | ||
pkgName: 'pkgName1', | ||
pkgVersion: 'pkgVersion1', | ||
title: 'title', | ||
}; | ||
renderHook(() => useAutoDetectTelemetry('awaitingData', [expectedIntegration])); | ||
|
||
expect(reportEventMock).toHaveBeenCalledWith( | ||
OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT.eventType, | ||
{ | ||
uses_legacy_onboarding_page: false, | ||
flow: 'auto_detect', | ||
step: 'awaiting_data', | ||
integrations: [expectedIntegration], | ||
} | ||
); | ||
}); | ||
|
||
it(`should report "data_shipped" event when status is "dataReceived"`, () => { | ||
const expectedIntegration = { | ||
installSource: 'source2', | ||
pkgName: 'pkgName2', | ||
pkgVersion: 'pkgVersion2', | ||
title: 'title2', | ||
}; | ||
renderHook(() => useAutoDetectTelemetry('dataReceived', [expectedIntegration])); | ||
|
||
// The effect runs after initial render | ||
expect(reportEventMock).toHaveBeenCalledWith( | ||
OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT.eventType, | ||
{ | ||
uses_legacy_onboarding_page: false, | ||
flow: 'auto_detect', | ||
step: 'data_shipped', | ||
integrations: [expectedIntegration], | ||
} | ||
); | ||
}); | ||
|
||
it('should not report the same event more than once', () => { | ||
const expectedIntegration = { | ||
installSource: 'source1', | ||
pkgName: 'pkgName1', | ||
pkgVersion: 'pkgVersion1', | ||
title: 'title', | ||
}; | ||
const { rerender } = renderHook( | ||
({ status }: { status: ObservabilityOnboardingFlowStatus }) => | ||
useAutoDetectTelemetry(status, [expectedIntegration]), | ||
{ initialProps: { status: 'awaitingData' } } | ||
); | ||
|
||
expect(reportEventMock).toHaveBeenCalledWith( | ||
OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT.eventType, | ||
{ | ||
uses_legacy_onboarding_page: false, | ||
flow: 'auto_detect', | ||
step: 'awaiting_data', | ||
integrations: [expectedIntegration], | ||
} | ||
); | ||
|
||
rerender({ status: 'awaitingData' }); | ||
expect(reportEventMock).toHaveBeenCalledTimes(1); | ||
|
||
rerender({ status: 'dataReceived' }); | ||
expect(reportEventMock).toHaveBeenCalledWith( | ||
OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT.eventType, | ||
{ | ||
uses_legacy_onboarding_page: false, | ||
flow: 'auto_detect', | ||
step: 'data_shipped', | ||
integrations: [expectedIntegration], | ||
} | ||
); | ||
expect(reportEventMock).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
...y_onboarding/public/application/quickstart_flows/auto_detect/use_auto_detect_telemetry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { ObservabilityOnboardingFlowStatus } from './get_onboarding_status'; | ||
import { OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT } from '../../../../common/telemetry_events'; | ||
|
||
interface IntegrationFields { | ||
installSource: string; | ||
pkgName: string; | ||
pkgVersion: string; | ||
title: string; | ||
} | ||
|
||
export function useAutoDetectTelemetry( | ||
status: ObservabilityOnboardingFlowStatus, | ||
integrations: IntegrationFields[] | ||
) { | ||
const [waitingMessageSent, setWaitingMessageSent] = useState(false); | ||
const [dataShippedMessageSent, setDataShippedMessageSent] = useState(false); | ||
const { | ||
services: { analytics }, | ||
} = useKibana(); | ||
|
||
useEffect(() => { | ||
if (status === 'awaitingData' && !waitingMessageSent) { | ||
analytics?.reportEvent(OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT.eventType, { | ||
uses_legacy_onboarding_page: false, | ||
flow: 'auto_detect', | ||
step: 'awaiting_data', | ||
integrations, | ||
}); | ||
setWaitingMessageSent(true); | ||
} | ||
if (status === 'dataReceived' && !dataShippedMessageSent) { | ||
analytics?.reportEvent(OBSERVABILITY_ONBOARDING_AUTODETECT_TELEMETRY_EVENT.eventType, { | ||
uses_legacy_onboarding_page: false, | ||
flow: 'auto_detect', | ||
step: 'data_shipped', | ||
integrations, | ||
}); | ||
setDataShippedMessageSent(true); | ||
} | ||
}, [analytics, dataShippedMessageSent, integrations, status, waitingMessageSent]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters