Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
[Search jobs]: Add logs to the search jobs UI (#56745)
Browse files Browse the repository at this point in the history
* Add telemetry events for the search jobs UI

* Add search job usage pings aggregation

* Connect search jobs usage handler

* Fix telemetry service props drilling

* usagestats: correctly unmarshal errors in GetWeeklySearchFormViews

* Fix client mocks and stories

* Fix updatecheck tests
  • Loading branch information
vovakulikov authored Sep 22, 2023
1 parent 42976e3 commit 1e25781
Show file tree
Hide file tree
Showing 22 changed files with 485 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Meta, Story } from '@storybook/react'
import { spy } from 'sinon'

import { NOOP_TELEMETRY_SERVICE } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { H2 } from '@sourcegraph/wildcard'
import { BrandedStory } from '@sourcegraph/wildcard/src/stories'

Expand Down Expand Up @@ -33,6 +34,7 @@ const render = () => (
skipped: [],
}}
state="loading"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand All @@ -48,6 +50,7 @@ const render = () => (
trace: 'https://sourcegraph.test:3443/-/debug/jaeger/trace/abcdefg',
}}
state="loading"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
showTrace={true}
/>
Expand All @@ -64,6 +67,7 @@ const render = () => (
skipped: [],
}}
state="loading"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand All @@ -79,6 +83,7 @@ const render = () => (
skipped: [],
}}
state="complete"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand All @@ -95,6 +100,7 @@ const render = () => (
trace: 'https://sourcegraph.test:3443/-/debug/jaeger/trace/abcdefg',
}}
state="complete"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
showTrace={true}
/>
Expand Down Expand Up @@ -132,6 +138,7 @@ const render = () => (
],
}}
state="complete"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand Down Expand Up @@ -168,6 +175,7 @@ const render = () => (
],
}}
state="loading"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand Down Expand Up @@ -214,6 +222,7 @@ const render = () => (
],
}}
state="complete"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand Down Expand Up @@ -262,6 +271,7 @@ const render = () => (
}}
state="complete"
onSearchAgain={onSearchAgain}
telemetryService={NOOP_TELEMETRY_SERVICE}
showTrace={true}
/>
</div>
Expand Down Expand Up @@ -308,6 +318,7 @@ const render = () => (
],
}}
state="loading"
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { mdiClipboardPulseOutline } from '@mdi/js'
import classNames from 'classnames'

import type { Progress, StreamingResultsState } from '@sourcegraph/shared/src/search/stream'
import { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { Icon, Link } from '@sourcegraph/wildcard'

import { StreamingProgressCount } from './StreamingProgressCount'
import { StreamingProgressSkippedButton } from './StreamingProgressSkippedButton'

import styles from './StreamingProgressCount.module.scss'

export interface StreamingProgressProps {
export interface StreamingProgressProps extends TelemetryProps {
query: string
state: StreamingResultsState
progress: Progress
Expand All @@ -27,6 +28,7 @@ export const StreamingProgress: React.FunctionComponent<React.PropsWithChildren<
showTrace,
onSearchAgain,
isSearchJobsEnabled,
telemetryService,
}) => {
const isLoading = state === 'loading'

Expand All @@ -39,6 +41,7 @@ export const StreamingProgress: React.FunctionComponent<React.PropsWithChildren<
progress={progress}
isSearchJobsEnabled={isSearchJobsEnabled}
onSearchAgain={onSearchAgain}
telemetryService={telemetryService}
/>
)}
<TraceLink showTrace={showTrace} trace={progress.trace} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

import type { Progress } from '@sourcegraph/shared/src/search/stream'
import { NOOP_TELEMETRY_SERVICE } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'

import { StreamingProgressSkippedButton } from './StreamingProgressSkippedButton'
Expand Down Expand Up @@ -49,7 +50,12 @@ describe('StreamingProgressSkippedButton', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedButton query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedButton
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)
expect(screen.getByTestId('streaming-progress-skipped')).toBeInTheDocument()
expect(screen.queryByTestId('streaming-progress-skipped')).not.toHaveClass('outline-danger')
Expand Down Expand Up @@ -95,7 +101,12 @@ describe('StreamingProgressSkippedButton', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedButton query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedButton
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)
expect(screen.getByTestId('streaming-progress-skipped')).toHaveClass('btnOutline btnDanger')
expect(screen.queryByTestId('streaming-progress-skipped')).not.toHaveClass('btnOutline btnSecondary')
Expand Down Expand Up @@ -131,7 +142,12 @@ describe('StreamingProgressSkippedButton', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedButton query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedButton
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)

const button = screen.getByTestId('streaming-progress-skipped')
Expand Down Expand Up @@ -179,7 +195,12 @@ describe('StreamingProgressSkippedButton', () => {
const onSearchAgain = sinon.spy()

renderWithBrandedContext(
<StreamingProgressSkippedButton query="" progress={progress} onSearchAgain={onSearchAgain} />
<StreamingProgressSkippedButton
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={onSearchAgain}
/>
)
const toggleButton = screen.getByTestId('streaming-progress-skipped')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import { useCallback, useMemo, useState, FC } from 'react'
import { mdiAlertCircle, mdiChevronDown, mdiInformationOutline } from '@mdi/js'

import { Progress } from '@sourcegraph/shared/src/search/stream'
import { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { Button, Popover, PopoverContent, PopoverTrigger, Position, Icon } from '@sourcegraph/wildcard'

import { CountContent, getProgressText } from './StreamingProgressCount'
import { StreamingProgressSkippedPopover } from './StreamingProgressSkippedPopover'

import styles from './StreamingProgressSkippedButton.module.scss'

interface StreamingProgressSkippedButtonProps {
interface StreamingProgressSkippedButtonProps extends TelemetryProps {
query: string
progress: Progress
isSearchJobsEnabled?: boolean
onSearchAgain: (additionalFilters: string[]) => void
}

export const StreamingProgressSkippedButton: FC<StreamingProgressSkippedButtonProps> = props => {
const { query, progress, isSearchJobsEnabled, onSearchAgain } = props
const { query, progress, isSearchJobsEnabled, onSearchAgain, telemetryService } = props
const [isOpen, setIsOpen] = useState(false)

const skippedWithWarningOrError = useMemo(
Expand Down Expand Up @@ -66,6 +67,7 @@ export const StreamingProgressSkippedButton: FC<StreamingProgressSkippedButtonPr
progress={progress}
isSearchJobsEnabled={isSearchJobsEnabled}
onSearchAgain={onSearchAgainWithPopupClose}
telemetryService={telemetryService}
/>
</PopoverContent>
</Popover>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Meta, Story } from '@storybook/react'

import type { Progress } from '@sourcegraph/shared/src/search/stream'
import { NOOP_TELEMETRY_SERVICE } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { BrandedStory } from '@sourcegraph/wildcard/src/stories'

import { StreamingProgressSkippedPopover } from './StreamingProgressSkippedPopover'
Expand Down Expand Up @@ -67,7 +68,14 @@ export const Popover: Story = () => {

return (
<BrandedStory>
{() => <StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={() => {}} />}
{() => (
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={() => {}}
/>
)}
</BrandedStory>
)
}
Expand Down Expand Up @@ -103,7 +111,14 @@ export const ShouldCloseAllInfo: Story = () => {

return (
<BrandedStory>
{() => <StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={() => {}} />}
{() => (
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={() => {}}
/>
)}
</BrandedStory>
)
}
Expand Down Expand Up @@ -131,7 +146,14 @@ export const ShouldOpenOneInfo: Story = () => {

return (
<BrandedStory>
{() => <StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={() => {}} />}
{() => (
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={() => {}}
/>
)}
</BrandedStory>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

import type { Progress } from '@sourcegraph/shared/src/search/stream'
import { NOOP_TELEMETRY_SERVICE } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { assertAriaDisabled, assertAriaEnabled } from '@sourcegraph/testing'
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'

Expand Down Expand Up @@ -67,7 +68,12 @@ describe('StreamingProgressSkippedPopover', () => {
}
expect(
renderWithBrandedContext(
<StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
).asFragment()
).toMatchSnapshot()
})
Expand All @@ -88,7 +94,12 @@ describe('StreamingProgressSkippedPopover', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)
expect(screen.queryByTestId('popover-form')).not.toBeInTheDocument()
})
Expand All @@ -113,7 +124,12 @@ describe('StreamingProgressSkippedPopover', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)
const form = screen.getByTestId('popover-form')
const searchAgainButton = within(form).getByRole('button')
Expand Down Expand Up @@ -161,7 +177,12 @@ describe('StreamingProgressSkippedPopover', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)

const checkboxes = screen.getAllByTestId(/^streaming-progress-skipped-suggest-check/)
Expand Down Expand Up @@ -214,7 +235,12 @@ describe('StreamingProgressSkippedPopover', () => {
}

renderWithBrandedContext(
<StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={sinon.spy()} />
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={sinon.spy()}
/>
)

const checkboxes = screen.getAllByTestId(/^streaming-progress-skipped-suggest-check/)
Expand Down Expand Up @@ -271,7 +297,12 @@ describe('StreamingProgressSkippedPopover', () => {
const searchAgain = sinon.spy()

renderWithBrandedContext(
<StreamingProgressSkippedPopover query="" progress={progress} onSearchAgain={searchAgain} />
<StreamingProgressSkippedPopover
query=""
progress={progress}
telemetryService={NOOP_TELEMETRY_SERVICE}
onSearchAgain={searchAgain}
/>
)

const checkboxes = screen.getAllByTestId(/^streaming-progress-skipped-suggest-check/)
Expand Down
Loading

0 comments on commit 1e25781

Please sign in to comment.