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

[8.6] [ML] Explain Log Rate Spikes: Fix field candidate selection. (#147614) #147792

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ export const ExplainLogRateSpikesAnalysis: FC<ExplainLogRateSpikesAnalysisProps>
const { loaded, remainingFieldCandidates, groupsMissing } = data;

if (
(Array.isArray(remainingFieldCandidates) && remainingFieldCandidates.length > 0) ||
groupsMissing
loaded < 1 &&
((Array.isArray(remainingFieldCandidates) && remainingFieldCandidates.length > 0) ||
groupsMissing)
) {
setOverrides({ loaded, remainingFieldCandidates, changePoints: data.changePoints });
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ describe('fetch_index_info', () => {
it('returns field candidates and total hits', async () => {
const esClientFieldCapsMock = jest.fn(() => ({
fields: {
myIpFieldName: { ip: {} },
myKeywordFieldName: { keyword: {} },
myUnpopulatedKeywordFieldName: { keyword: {} },
// Should end up as a field candidate
myIpFieldName: { ip: { aggregatable: true } },
// Should end up as a field candidate
myKeywordFieldName: { keyword: { aggregatable: true } },
// Should not end up as a field candidate, it's a keyword but non-aggregatable
myKeywordFieldNameToBeIgnored: { keyword: { aggregatable: false } },
// Should not end up as a field candidate, based on this field caps result it would be
// but it will not be part of the mocked search result so will count as unpopulated.
myUnpopulatedKeywordFieldName: { keyword: { aggregatable: true } },
// Should not end up as a field candidate since fields of type number will not be considered
myNumericFieldName: { number: {} },
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export const fetchIndexInfo = async (
Object.entries(respMapping.fields).forEach(([key, value]) => {
const fieldTypes = Object.keys(value) as ES_FIELD_TYPES[];
const isSupportedType = fieldTypes.some((type) => SUPPORTED_ES_FIELD_TYPES.includes(type));
const isAggregatable = fieldTypes.some((type) => value[type].aggregatable);

// Check if fieldName is something we can aggregate on
if (isSupportedType) {
if (isSupportedType && isAggregatable) {
acceptableFields.add(key);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface GeneratedDoc {
url: string;
version: string;
'@timestamp': number;
should_ignore_this_field: string;
}

const REFERENCE_TS = 1669018354793;
Expand Down Expand Up @@ -50,6 +51,7 @@ function getArtificialLogsWithSpike(index: string) {
url,
version: 'v1.0.0',
'@timestamp': ts + tsOffset,
should_ignore_this_field: 'should_ignore_this_field',
};

bulkBody.push(action);
Expand All @@ -74,6 +76,7 @@ function getArtificialLogsWithSpike(index: string) {
url,
version: 'v1.0.0',
'@timestamp': DEVIATION_TS + tsOffset,
should_ignore_this_field: 'should_ignore_this_field',
});
});
});
Expand All @@ -91,6 +94,7 @@ function getArtificialLogsWithSpike(index: string) {
url,
version: 'v1.0.0',
'@timestamp': DEVIATION_TS + tsOffset,
should_ignore_this_field: 'should_ignore_this_field',
});
});
});
Expand Down Expand Up @@ -158,6 +162,7 @@ export function ExplainLogRateSpikesDataGeneratorProvider({ getService }: FtrPro
url: { type: 'keyword' },
version: { type: 'keyword' },
'@timestamp': { type: 'date' },
should_ignore_this_field: { type: 'keyword', doc_values: false, index: false },
},
},
});
Expand Down