-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] APM Latency Correlations: Fix empty state #109813
Merged
walterra
merged 16 commits into
elastic:master
from
walterra:ml-apm-correlations-fix-empty-state
Aug 27, 2021
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
01e3a9a
fix chart state for empty results.
walterra b30359d
unit tests
walterra 6e21c1b
[ML] Fix empty state for latency correlations.
walterra 5a8bfd7
Merge branch 'master' into ml-apm-correlations-fix-empty-state
walterra ca86f76
[ML] Fix tooltip text.
walterra 04bf2de
Merge branch 'master' into ml-apm-correlations-fix-empty-state
walterra cc7f8f1
[Ml] Trigger reload for log log histogram and analysis.
walterra 137b14e
[ML] Fix paragraph spacing.
walterra b17a0b9
Revert "[ML] Fix tooltip text."
walterra 08df940
Merge branch 'master' into ml-apm-correlations-fix-empty-state
walterra 22e1b9c
[ML] Fix typo.
walterra acc4caa
[ML] Fix latency chart legend label.
walterra 34e882c
[ML] Improve useEffects deps.
walterra cd871b2
[ML] Fix useEffects.
walterra f4c3c5f
[ML] Fix loading spinner of latency correlations chart when cancel wa…
walterra 3952f7b
Merge branch 'master' into ml-apm-correlations-fix-empty-state
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
131 changes: 131 additions & 0 deletions
131
x-pack/plugins/apm/public/components/app/correlations/latency_correlations.test.tsx
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,131 @@ | ||
/* | ||
* 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 { render, screen, waitFor } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import React, { ReactNode } from 'react'; | ||
import { of } from 'rxjs'; | ||
|
||
import { __IntlProvider as IntlProvider } from '@kbn/i18n/react'; | ||
|
||
import { CoreStart } from 'kibana/public'; | ||
import { merge } from 'lodash'; | ||
import { dataPluginMock } from 'src/plugins/data/public/mocks'; | ||
import type { IKibanaSearchResponse } from 'src/plugins/data/public'; | ||
import { EuiThemeProvider } from 'src/plugins/kibana_react/common'; | ||
import { createKibanaReactContext } from 'src/plugins/kibana_react/public'; | ||
import type { SearchServiceRawResponse } from '../../../../common/search_strategies/correlations/types'; | ||
import { MockUrlParamsContextProvider } from '../../../context/url_params_context/mock_url_params_context_provider'; | ||
import { ApmPluginContextValue } from '../../../context/apm_plugin/apm_plugin_context'; | ||
import { | ||
mockApmPluginContextValue, | ||
MockApmPluginContextWrapper, | ||
} from '../../../context/apm_plugin/mock_apm_plugin_context'; | ||
import { fromQuery } from '../../shared/Links/url_helpers'; | ||
|
||
import { LatencyCorrelations } from './latency_correlations'; | ||
|
||
function Wrapper({ | ||
children, | ||
dataSearchResponse, | ||
}: { | ||
children?: ReactNode; | ||
dataSearchResponse: IKibanaSearchResponse<SearchServiceRawResponse>; | ||
}) { | ||
const mockDataSearch = jest.fn(() => of(dataSearchResponse)); | ||
|
||
const dataPluginMockStart = dataPluginMock.createStartContract(); | ||
const KibanaReactContext = createKibanaReactContext({ | ||
data: { | ||
...dataPluginMockStart, | ||
search: { | ||
...dataPluginMockStart.search, | ||
search: mockDataSearch, | ||
}, | ||
}, | ||
usageCollection: { reportUiCounter: () => {} }, | ||
} as Partial<CoreStart>); | ||
|
||
const httpGet = jest.fn(); | ||
|
||
const history = createMemoryHistory(); | ||
jest.spyOn(history, 'push'); | ||
jest.spyOn(history, 'replace'); | ||
|
||
history.replace({ | ||
pathname: '/services/the-service-name/transactions/view', | ||
search: fromQuery({ transactionName: 'the-transaction-name' }), | ||
}); | ||
|
||
const mockPluginContext = (merge({}, mockApmPluginContextValue, { | ||
core: { http: { get: httpGet } }, | ||
}) as unknown) as ApmPluginContextValue; | ||
|
||
return ( | ||
<IntlProvider locale="en"> | ||
<EuiThemeProvider darkMode={false}> | ||
<KibanaReactContext.Provider> | ||
<MockApmPluginContextWrapper | ||
history={history} | ||
value={mockPluginContext} | ||
> | ||
<MockUrlParamsContextProvider | ||
params={{ | ||
rangeFrom: 'now-15m', | ||
rangeTo: 'now', | ||
start: 'mystart', | ||
end: 'myend', | ||
}} | ||
> | ||
{children} | ||
</MockUrlParamsContextProvider> | ||
</MockApmPluginContextWrapper> | ||
</KibanaReactContext.Provider> | ||
</EuiThemeProvider> | ||
</IntlProvider> | ||
); | ||
} | ||
|
||
describe('correlations', () => { | ||
describe('LatencyCorrelations', () => { | ||
it('shows loading indicator when the service is running and returned no results yet', async () => { | ||
render( | ||
<Wrapper | ||
dataSearchResponse={{ | ||
isRunning: true, | ||
rawResponse: { ccsWarning: false, took: 1234, values: [], log: [] }, | ||
}} | ||
> | ||
<LatencyCorrelations onFilter={jest.fn()} /> | ||
</Wrapper> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('apmCorrelationsChart')).toBeInTheDocument(); | ||
expect(screen.getByTestId('loading')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("doesn't show loading indicator when the service isn't running", async () => { | ||
render( | ||
<Wrapper | ||
dataSearchResponse={{ | ||
isRunning: false, | ||
rawResponse: { ccsWarning: false, took: 1234, values: [], log: [] }, | ||
}} | ||
> | ||
<LatencyCorrelations onFilter={jest.fn()} /> | ||
</Wrapper> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('apmCorrelationsChart')).toBeInTheDocument(); | ||
expect(screen.queryByTestId('loading')).toBeNull(); // it doesn't exist | ||
}); | ||
}); | ||
}); | ||
}); |
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
22 changes: 0 additions & 22 deletions
22
x-pack/plugins/apm/public/components/app/transaction_details/distribution/index.test.ts
This file was deleted.
Oops, something went wrong.
151 changes: 151 additions & 0 deletions
151
x-pack/plugins/apm/public/components/app/transaction_details/distribution/index.test.tsx
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,151 @@ | ||
/* | ||
* 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 { render, screen, waitFor } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import React, { ReactNode } from 'react'; | ||
import { of } from 'rxjs'; | ||
|
||
import { CoreStart } from 'kibana/public'; | ||
import { merge } from 'lodash'; | ||
import { dataPluginMock } from 'src/plugins/data/public/mocks'; | ||
import type { IKibanaSearchResponse } from 'src/plugins/data/public'; | ||
import { EuiThemeProvider } from 'src/plugins/kibana_react/common'; | ||
import { createKibanaReactContext } from 'src/plugins/kibana_react/public'; | ||
import type { SearchServiceRawResponse } from '../../../../../common/search_strategies/correlations/types'; | ||
import { MockUrlParamsContextProvider } from '../../../../context/url_params_context/mock_url_params_context_provider'; | ||
import { ApmPluginContextValue } from '../../../../context/apm_plugin/apm_plugin_context'; | ||
import { | ||
mockApmPluginContextValue, | ||
MockApmPluginContextWrapper, | ||
} from '../../../../context/apm_plugin/mock_apm_plugin_context'; | ||
import { fromQuery } from '../../../shared/Links/url_helpers'; | ||
|
||
import { getFormattedSelection, TransactionDistribution } from './index'; | ||
|
||
function Wrapper({ | ||
children, | ||
dataSearchResponse, | ||
}: { | ||
children?: ReactNode; | ||
dataSearchResponse: IKibanaSearchResponse<SearchServiceRawResponse>; | ||
}) { | ||
const mockDataSearch = jest.fn(() => of(dataSearchResponse)); | ||
|
||
const dataPluginMockStart = dataPluginMock.createStartContract(); | ||
const KibanaReactContext = createKibanaReactContext({ | ||
data: { | ||
...dataPluginMockStart, | ||
search: { | ||
...dataPluginMockStart.search, | ||
search: mockDataSearch, | ||
}, | ||
}, | ||
usageCollection: { reportUiCounter: () => {} }, | ||
} as Partial<CoreStart>); | ||
|
||
const httpGet = jest.fn(); | ||
|
||
const history = createMemoryHistory(); | ||
jest.spyOn(history, 'push'); | ||
jest.spyOn(history, 'replace'); | ||
|
||
history.replace({ | ||
pathname: '/services/the-service-name/transactions/view', | ||
search: fromQuery({ transactionName: 'the-transaction-name' }), | ||
}); | ||
|
||
const mockPluginContext = (merge({}, mockApmPluginContextValue, { | ||
core: { http: { get: httpGet } }, | ||
}) as unknown) as ApmPluginContextValue; | ||
|
||
return ( | ||
<EuiThemeProvider darkMode={false}> | ||
<KibanaReactContext.Provider> | ||
<MockApmPluginContextWrapper | ||
history={history} | ||
value={mockPluginContext} | ||
> | ||
<MockUrlParamsContextProvider | ||
params={{ | ||
rangeFrom: 'now-15m', | ||
rangeTo: 'now', | ||
start: 'mystart', | ||
end: 'myend', | ||
}} | ||
> | ||
{children} | ||
</MockUrlParamsContextProvider> | ||
</MockApmPluginContextWrapper> | ||
</KibanaReactContext.Provider> | ||
</EuiThemeProvider> | ||
); | ||
} | ||
|
||
describe('transaction_details/distribution', () => { | ||
describe('getFormattedSelection', () => { | ||
it('displays only one unit if from and to share the same unit', () => { | ||
expect(getFormattedSelection([10000, 100000])).toEqual('10 - 100 ms'); | ||
}); | ||
|
||
it('displays two units when from and to have different units', () => { | ||
expect(getFormattedSelection([100000, 1000000000])).toEqual( | ||
'100 ms - 17 min' | ||
); | ||
}); | ||
}); | ||
|
||
describe('TransactionDistribution', () => { | ||
it('shows loading indicator when the service is running and returned no results yet', async () => { | ||
const onHasData = jest.fn(); | ||
render( | ||
<Wrapper | ||
dataSearchResponse={{ | ||
isRunning: true, | ||
rawResponse: { ccsWarning: false, took: 1234, values: [], log: [] }, | ||
}} | ||
> | ||
<TransactionDistribution | ||
onChartSelection={jest.fn()} | ||
onClearSelection={jest.fn()} | ||
onHasData={onHasData} | ||
/> | ||
</Wrapper> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('apmCorrelationsChart')).toBeInTheDocument(); | ||
expect(screen.getByTestId('loading')).toBeInTheDocument(); | ||
expect(onHasData).toHaveBeenLastCalledWith(false); | ||
}); | ||
}); | ||
|
||
it("doesn't show loading indicator when the service isn't running", async () => { | ||
const onHasData = jest.fn(); | ||
render( | ||
<Wrapper | ||
dataSearchResponse={{ | ||
isRunning: false, | ||
rawResponse: { ccsWarning: false, took: 1234, values: [], log: [] }, | ||
}} | ||
> | ||
<TransactionDistribution | ||
onChartSelection={jest.fn()} | ||
onClearSelection={jest.fn()} | ||
onHasData={onHasData} | ||
/> | ||
</Wrapper> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('apmCorrelationsChart')).toBeInTheDocument(); | ||
expect(screen.queryByTestId('loading')).toBeNull(); // it doesn't exist | ||
expect(onHasData).toHaveBeenLastCalledWith(false); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bug occurred because we have eslint suppress errors. Why do we do that in the first place? Can we remove it?
Also: looking at this it looks like we are still missing
transactionName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved in 34e882c. We originally had it there because the callback
startFetch
/cancelFetch
were reinstantiated on every hook call. I wrapped them inuseCallback
so that doesn't happen anymore.