Skip to content
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] Fix custom index name settings, functional tests for APM Latency Correlation. #105200

Merged
merged 16 commits into from
Jul 19, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface ResponseHit {
}

export interface SearchServiceParams {
index: string;
environment?: string;
kuery?: string;
serviceName?: string;
Expand All @@ -31,6 +30,10 @@ export interface SearchServiceParams {
percentileThresholdValue?: number;
}

export interface SearchServiceFetchParams extends SearchServiceParams {
index: string;
}

export interface SearchServiceValue {
histogram: HistogramItem[];
value: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ const chartTheme: PartialTheme = {
},
};

// Log based axis cannot start a 0. Use a small positive number instead.
const yAxisDomain = {
min: 0.00001,
};

interface CorrelationsChartProps {
field?: string;
value?: string;
Expand Down Expand Up @@ -140,7 +145,10 @@ export function CorrelationsChart({
const histogram = replaceHistogramDotsWithBars(originalHistogram);

return (
<div style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>
<div
data-test-subj="apmCorrelationsChart"
style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}
>
<Chart
size={{
height: '250px',
Expand Down Expand Up @@ -168,6 +176,7 @@ export function CorrelationsChart({
/>
<Axis
id="y-axis"
domain={yAxisDomain}
title={i18n.translate(
'xpack.apm.correlations.latency.chart.numberOfTransactionsLabel',
{ defaultMessage: '# transactions' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function Correlations() {
return (
<>
<EuiButton
data-test-subj="apmViewCorrelationsButton"
fill
onClick={() => {
setIsFlyoutVisible(true);
Expand All @@ -146,13 +147,17 @@ export function Correlations() {
{isFlyoutVisible && (
<EuiPortal>
<EuiFlyout
data-test-subj="apmCorrelationsFlyout"
size="l"
ownFocus
onClose={() => setIsFlyoutVisible(false)}
>
<EuiFlyoutHeader hasBorder aria-labelledby="correlations-flyout">
<EuiTitle>
<h2 id="correlations-flyout">
<h2
data-test-subj="apmCorrelationsFlyoutHeader"
id="correlations-flyout"
>
{CORRELATIONS_TITLE}
&nbsp;
<EuiBetaBadge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/

import React, { useEffect, useMemo, useState } from 'react';
import { useHistory, useParams } from 'react-router-dom';
import { useHistory, useLocation, useParams } from 'react-router-dom';
import {
EuiCode,
EuiAccordion,
EuiPanel,
EuiIcon,
EuiBasicTableColumn,
EuiButton,
Expand Down Expand Up @@ -72,7 +75,11 @@ export function MlLatencyCorrelations({ onClose }: Props) {
},
} = useUrlParams();

const location = useLocation();
const displayLog = location.search.includes('debug=true');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this, we should use the existing observability:enableInspectEsQueries UI setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion, fixed in 1a63809.


const {
log,
error,
histograms,
percentileThresholdValue,
Expand All @@ -82,7 +89,6 @@ export function MlLatencyCorrelations({ onClose }: Props) {
cancelFetch,
overallHistogram: originalOverallHistogram,
} = useCorrelations({
index: 'apm-*',
...{
...{
environment,
Expand Down Expand Up @@ -292,9 +298,10 @@ export function MlLatencyCorrelations({ onClose }: Props) {
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="none">
<EuiFlexItem>
<EuiFlexItem data-test-subj="apmCorrelationsLatencyCorrelationsProgressTitle">
<EuiText size="xs" color="subdued">
<FormattedMessage
data-test-subj="apmCorrelationsLatencyCorrelationsProgressTitle"
id="xpack.apm.correlations.latencyCorrelations.progressTitle"
defaultMessage="Progress: {progress}%"
values={{ progress: Math.round(progress * 100) }}
Expand Down Expand Up @@ -323,7 +330,7 @@ export function MlLatencyCorrelations({ onClose }: Props) {
{overallHistogram !== undefined ? (
<>
<EuiTitle size="xxs">
<h4>
<h4 data-test-subj="apmCorrelationsLatencyCorrelationsChartTitle">
{i18n.translate(
'xpack.apm.correlations.latencyCorrelations.chartTitle',
{
Expand All @@ -347,32 +354,50 @@ export function MlLatencyCorrelations({ onClose }: Props) {
</>
) : null}

{histograms.length > 0 && selectedHistogram !== undefined && (
<CorrelationsTable
// @ts-ignore correlations don't have the same column format other tables have
columns={mlCorrelationColumns}
// @ts-expect-error correlations don't have the same significant term other tables have
significantTerms={histogramTerms}
status={FETCH_STATUS.SUCCESS}
setSelectedSignificantTerm={setSelectedSignificantTerm}
selectedTerm={{
fieldName: selectedHistogram.field,
fieldValue: selectedHistogram.value,
}}
onFilter={onClose}
/>
<div data-test-subj="apmCorrelationsTable">
{histograms.length > 0 && selectedHistogram !== undefined && (
<CorrelationsTable
// @ts-ignore correlations don't have the same column format other tables have
columns={mlCorrelationColumns}
// @ts-expect-error correlations don't have the same significant term other tables have
significantTerms={histogramTerms}
status={FETCH_STATUS.SUCCESS}
setSelectedSignificantTerm={setSelectedSignificantTerm}
selectedTerm={{
fieldName: selectedHistogram.field,
fieldValue: selectedHistogram.value,
}}
onFilter={onClose}
/>
)}
{histograms.length < 1 && progress > 0.99 ? (
<>
<EuiSpacer size="m" />
<EuiText textAlign="center">
<FormattedMessage
id="xpack.apm.correlations.latencyCorrelations.noCorrelationsText"
defaultMessage="No significant correlations found"
/>
</EuiText>
</>
) : null}
</div>
{log.length > 0 && displayLog && (
<EuiAccordion id="accordion1" buttonContent="Log">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Log here needs internationalization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed translation in 7592578.

<EuiPanel color="subdued">
{log.map((d, i) => {
const splitItem = d.split(': ');
return (
<p key={i}>
<small>
<EuiCode>{splitItem[0]}</EuiCode> {splitItem[1]}
</small>
</p>
);
})}
</EuiPanel>
</EuiAccordion>
)}
{histograms.length < 1 && progress > 0.99 ? (
<>
<EuiSpacer size="m" />
<EuiText textAlign="center">
<FormattedMessage
id="xpack.apm.correlations.latencyCorrelations.noCorrelationsText"
defaultMessage="No significant correlations found"
/>
</EuiText>
</>
) : null}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'
import { ApmPluginStartDeps } from '../../../plugin';

interface CorrelationsOptions {
index: string;
environment?: string;
kuery?: string;
serviceName?: string;
Expand Down Expand Up @@ -106,6 +105,7 @@ export const useCorrelations = (params: CorrelationsOptions) => {
};

return {
log: rawResponse?.log ?? [],
error,
histograms: rawResponse?.values ?? [],
percentileThresholdValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export function getServiceColumns({
)}
<EuiFlexItem className="apmServiceList__serviceNameContainer">
<AppLink
data-test-subj="apmServiceListAppLink"
serviceName={serviceName}
transactionType={transactionType}
className="eui-textTruncate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function TemplateWithContext({
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiTitle size="l">
<h1>{serviceName}</h1>
<h1 data-test-subj="apmMainTemplateHeaderServiceName">
{serviceName}
</h1>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { shuffle, range } from 'lodash';
import type { ElasticsearchClient } from 'src/core/server';
import type { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
import { fetchTransactionDurationFieldCandidates } from './query_field_candidates';
import { fetchTransactionDurationFieldValuePairs } from './query_field_value_pairs';
import { fetchTransactionDurationPercentiles } from './query_percentiles';
Expand All @@ -16,6 +17,7 @@ import { fetchTransactionDurationRanges, HistogramItem } from './query_ranges';
import type {
AsyncSearchProviderProgress,
SearchServiceParams,
SearchServiceFetchParams,
SearchServiceValue,
} from '../../../../common/search_strategies/correlations/types';
import { computeExpectationsAndRanges } from './utils/aggregation_utils';
Expand All @@ -28,7 +30,9 @@ const currentTimeAsString = () => new Date().toISOString();

export const asyncSearchServiceProvider = (
esClient: ElasticsearchClient,
params: SearchServiceParams
getApmIndices: () => Promise<ApmIndicesConfig>,
searchServiceParams: SearchServiceParams,
includeFrozen: boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is includeFrozen being used here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just re-read the post description and my question is redundant here :) Sorry the noise

) => {
let isCancelled = false;
let isRunning = true;
Expand Down Expand Up @@ -64,6 +68,12 @@ export const asyncSearchServiceProvider = (

const fetchCorrelations = async () => {
try {
const indices = await getApmIndices();
const params: SearchServiceFetchParams = {
...searchServiceParams,
index: indices['apm_oss.transactionIndices'],
};

// 95th percentile to be displayed as a marker in the log log chart
const {
totalDocs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as t from 'io-ts';

import type { estypes } from '@elastic/elasticsearch';
import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames';
import type { SearchServiceParams } from '../../../../common/search_strategies/correlations/types';
import type { SearchServiceFetchParams } from '../../../../common/search_strategies/correlations/types';
import { rangeRt } from '../../../routes/default_api_types';

import { Setup, SetupTimeRange } from '../../helpers/setup_request';
Expand Down Expand Up @@ -43,7 +43,7 @@ export const getTermsQuery = (
};

interface QueryParams {
params: SearchServiceParams;
params: SearchServiceFetchParams;
fieldName?: string;
fieldValue?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { estypes } from '@elastic/elasticsearch';
import type { ElasticsearchClient } from 'src/core/server';

import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames';
import type { SearchServiceParams } from '../../../../common/search_strategies/correlations/types';
import type { SearchServiceFetchParams } from '../../../../common/search_strategies/correlations/types';

import { getQueryWithParams } from './get_query_with_params';

Expand Down Expand Up @@ -40,7 +40,7 @@ export interface BucketCorrelation {
}

export const getTransactionDurationCorrelationRequest = (
params: SearchServiceParams,
params: SearchServiceFetchParams,
expectations: number[],
ranges: estypes.AggregationsAggregationRange[],
fractions: number[],
Expand Down Expand Up @@ -95,7 +95,7 @@ export const getTransactionDurationCorrelationRequest = (

export const fetchTransactionDurationCorrelation = async (
esClient: ElasticsearchClient,
params: SearchServiceParams,
params: SearchServiceFetchParams,
expectations: number[],
ranges: estypes.AggregationsAggregationRange[],
fractions: number[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { estypes } from '@elastic/elasticsearch';

import type { ElasticsearchClient } from 'src/core/server';

import type { SearchServiceParams } from '../../../../common/search_strategies/correlations/types';
import type { SearchServiceFetchParams } from '../../../../common/search_strategies/correlations/types';

import { getQueryWithParams } from './get_query_with_params';
import { Field } from './query_field_value_pairs';
Expand Down Expand Up @@ -37,7 +37,7 @@ export const hasPrefixToInclude = (fieldName: string) => {
};

export const getRandomDocsRequest = (
params: SearchServiceParams
params: SearchServiceFetchParams
): estypes.SearchRequest => ({
index: params.index,
body: {
Expand All @@ -56,7 +56,7 @@ export const getRandomDocsRequest = (

export const fetchTransactionDurationFieldCandidates = async (
esClient: ElasticsearchClient,
params: SearchServiceParams
params: SearchServiceFetchParams
): Promise<{ fieldCandidates: Field[] }> => {
const { index } = params;
// Get all fields with keyword mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { estypes } from '@elastic/elasticsearch';

import type {
AsyncSearchProviderProgress,
SearchServiceParams,
SearchServiceFetchParams,
} from '../../../../common/search_strategies/correlations/types';

import { getQueryWithParams } from './get_query_with_params';
Expand All @@ -26,7 +26,7 @@ type FieldValuePairs = FieldValuePair[];
export type Field = string;

export const getTermsAggRequest = (
params: SearchServiceParams,
params: SearchServiceFetchParams,
fieldName: string
): estypes.SearchRequest => ({
index: params.index,
Expand All @@ -46,7 +46,7 @@ export const getTermsAggRequest = (

export const fetchTransactionDurationFieldValuePairs = async (
esClient: ElasticsearchClient,
params: SearchServiceParams,
params: SearchServiceFetchParams,
fieldCandidates: Field[],
progress: AsyncSearchProviderProgress
): Promise<FieldValuePairs> => {
Expand Down
Loading