Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2f429c5
Add logtypedetection server changes
bhapas Aug 9, 2024
4bff2b8
Add logtypedetection graph
bhapas Aug 13, 2024
bb36343
Remove JSON/NDJSON from UI
bhapas Aug 13, 2024
b8dde3f
Increase upload file size to 9MB
bhapas Aug 14, 2024
6fb1fc2
Add unit tests
bhapas Aug 14, 2024
71c2c74
Fix string docs and truncate logfile to 10 lines
bhapas Aug 14, 2024
84521de
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 14, 2024
cb5df15
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 14, 2024
7ad70fa
Merge branch 'main' into automatic_log_type_detection
elasticmachine Aug 15, 2024
8a9e4d1
fix i18n translations
bhapas Aug 15, 2024
25f824d
Move AnalyseLogs into own API call
bhapas Aug 20, 2024
791f6ed
Add samplesFormat to state
bhapas Aug 22, 2024
ccca0dd
Merge remote-tracking branch 'upstream/main' into automatic_log_type_…
bhapas Aug 22, 2024
e606bd1
rollback unwanted changes
bhapas Aug 22, 2024
bf2d773
add and fix tests
bhapas Aug 22, 2024
baedbaf
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 22, 2024
fe47446
minor fixes
bhapas Aug 22, 2024
e15a9bb
fix eslint errors
bhapas Aug 22, 2024
5779abe
Merge branch 'main' into automatic_log_type_detection
elasticmachine Aug 22, 2024
2b4b21f
Merge branch 'main' into automatic_log_type_detection
elasticmachine Aug 23, 2024
46ef731
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 23, 2024
c9cd54e
Fix typo
bhapas Aug 23, 2024
5d84e2e
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 23, 2024
67c214c
Merge branch 'main' into automatic_log_type_detection
elasticmachine Aug 23, 2024
d6191a5
Merge branch 'main' into automatic_log_type_detection
elasticmachine Aug 23, 2024
cfb7fa9
fix UI related comments
bhapas Aug 23, 2024
0aa14ec
Modify Parsing logic
bhapas Aug 26, 2024
1cfba1a
Make it analyze
bhapas Aug 26, 2024
aae4c11
fix server side
bhapas Aug 26, 2024
7238fc2
remove truncation
bhapas Aug 26, 2024
50473e4
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 26, 2024
2bfd50c
fix comments
bhapas Aug 26, 2024
ff07a4e
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 26, 2024
62d7978
more fixes
bhapas Aug 27, 2024
bfb9c81
Merge branch 'main' into automatic_log_type_detection
bhapas Aug 27, 2024
bb8b4fe
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 27, 2024
615e2e2
fix samplesFormat
bhapas Aug 27, 2024
23dfbef
Update log parsing
bhapas Aug 27, 2024
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
@@ -0,0 +1,20 @@
/*
* 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 { SamplesFormatName } from '../../common/api/model/common_attributes';

export const logFormatDetectionTestState = {
lastExecutedChain: 'testchain',
logSamples: ['{"test1": "test1"}'],
exAnswer: 'testanswer',
packageName: 'testPackage',
dataStreamName: 'testDatastream',
finalized: false,
samplesFormat: { name: SamplesFormatName.Values.json },
ecsVersion: 'testVersion',
results: { test1: 'test1' },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.0.3
info:
title: Auto Import Analyze Logs API endpoint
version: "1"
paths:
/api/integration_assistant/analyzelogs:
post:
summary: Analyzes log samples and processes them.
operationId: AnalyzeLogs
x-codegen-enabled: false
description: Analyzes log samples and processes them
tags:
- Analyze Logs API
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- logSamples
- connectorId
properties:
logSamples:
$ref: "../model/common_attributes.schema.yaml#/components/schemas/LogSamples"
connectorId:
$ref: "../model/common_attributes.schema.yaml#/components/schemas/Connector"
langSmithOptions:
$ref: "../model/common_attributes.schema.yaml#/components/schemas/LangSmithOptions"
responses:
200:
description: Indicates a successful call.
content:
application/json:
schema:
$ref: "../model/response_schemas.schema.yaml#/components/schemas/AnalyzeLogsAPIResponse"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Auto Import Analyze Logs API endpoint
* version: 1
*/

import { z } from '@kbn/zod';

import { LogSamples, Connector, LangSmithOptions } from '../model/common_attributes';
import { AnalyzeLogsAPIResponse } from '../model/response_schemas';

export type AnalyzeLogsRequestBody = z.infer<typeof AnalyzeLogsRequestBody>;
export const AnalyzeLogsRequestBody = z.object({
logSamples: LogSamples,
connectorId: Connector,
langSmithOptions: LangSmithOptions.optional(),
});
export type AnalyzeLogsRequestBodyInput = z.input<typeof AnalyzeLogsRequestBody>;

export type AnalyzeLogsResponse = z.infer<typeof AnalyzeLogsResponse>;
export const AnalyzeLogsResponse = AnalyzeLogsAPIResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ components:
minLength: 1
description: DataStream name for the integration to be built.

LogSamples:
type: array
items:
type: string
description: String form of the input logsamples.

RawSamples:
type: array
items:
Expand All @@ -42,6 +48,10 @@ components:
enum:
- ndjson
- json
- csv
- structured
- unstructured
- unsupported

SamplesFormat:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export const PackageName = z.string().min(1);
export type DataStreamName = z.infer<typeof DataStreamName>;
export const DataStreamName = z.string().min(1);

/**
* String form of the input logsamples.
*/
export type LogSamples = z.infer<typeof LogSamples>;
export const LogSamples = z.array(z.string());

/**
* String array containing the json raw samples that are used for ecs mapping.
*/
Expand Down Expand Up @@ -49,7 +55,14 @@ export const Docs = z.array(z.object({}).passthrough());
* The name of the log samples format.
*/
export type SamplesFormatName = z.infer<typeof SamplesFormatName>;
export const SamplesFormatName = z.enum(['ndjson', 'json']);
export const SamplesFormatName = z.enum([
'ndjson',
'json',
'csv',
'structured',
'unstructured',
'unsupported',
]);
export type SamplesFormatNameEnum = typeof SamplesFormatName.enum;
export const SamplesFormatNameEnum = SamplesFormatName.enum;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,20 @@ components:
properties:
docs:
$ref: "./common_attributes.schema.yaml#/components/schemas/Docs"

AnalyzeLogsAPIResponse:
type: object
required:
- results
properties:
results:
type: object
required:
- parsedSamples
properties:
samplesFormat:
$ref: "./common_attributes.schema.yaml#/components/schemas/SamplesFormat"
parsedSamples:
type: array
items:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { z } from '@kbn/zod';

import { Docs, Mapping, Pipeline } from './common_attributes';
import { Docs, Mapping, Pipeline, SamplesFormat } from './common_attributes';

export type EcsMappingAPIResponse = z.infer<typeof EcsMappingAPIResponse>;
export const EcsMappingAPIResponse = z.object({
Expand Down Expand Up @@ -48,3 +48,11 @@ export const CheckPipelineAPIResponse = z.object({
docs: Docs,
}),
});

export type AnalyzeLogsAPIResponse = z.infer<typeof AnalyzeLogsAPIResponse>;
export const AnalyzeLogsAPIResponse = z.object({
results: z.object({
samplesFormat: SamplesFormat,
parsedSamples: z.array(z.string()),
}),
});
1 change: 1 addition & 0 deletions x-pack/plugins/integration_assistant/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const INTEGRATION_ASSISTANT_BASE_PATH = '/api/integration_assistant';

export const ECS_GRAPH_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/ecs`;
export const CATEGORIZATION_GRAPH_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/categorization`;
export const ANALYZE_LOGS_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/analyzelogs`;
export const RELATED_GRAPH_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/related`;
export const CHECK_PIPELINE_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/pipeline`;
export const INTEGRATION_BUILDER_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/build`;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/integration_assistant/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {
} from './api/check_pipeline/check_pipeline';
export { EcsMappingRequestBody, EcsMappingResponse } from './api/ecs/ecs_route';
export { RelatedRequestBody, RelatedResponse } from './api/related/related_route';
export { AnalyzeLogsRequestBody, AnalyzeLogsResponse } from './api/analyze_logs/analyze_logs_route';

export type {
DataStream,
Expand All @@ -35,4 +36,5 @@ export {
PLUGIN_ID,
RELATED_GRAPH_PATH,
CHECK_PIPELINE_PATH,
ANALYZE_LOGS_PATH,
} from './constants';
14 changes: 13 additions & 1 deletion x-pack/plugins/integration_assistant/public/common/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import type {
CheckPipelineRequestBody,
CheckPipelineResponse,
BuildIntegrationRequestBody,
AnalyzeLogsRequestBody,
AnalyzeLogsResponse,
} from '../../../common';
import {
INTEGRATION_BUILDER_PATH,
Expand All @@ -24,7 +26,7 @@ import {
RELATED_GRAPH_PATH,
CHECK_PIPELINE_PATH,
} from '../../../common';
import { FLEET_PACKAGES_PATH } from '../../../common/constants';
import { ANALYZE_LOGS_PATH, FLEET_PACKAGES_PATH } from '../../../common/constants';

export interface EpmPackageResponse {
response: [{ id: string; name: string }];
Expand All @@ -42,6 +44,16 @@ export interface RequestDeps {
abortSignal: AbortSignal;
}

export const runAnalyzeLogsGraph = async (
body: AnalyzeLogsRequestBody,
{ http, abortSignal }: RequestDeps
): Promise<AnalyzeLogsResponse> =>
http.post<AnalyzeLogsResponse>(ANALYZE_LOGS_PATH, {
headers: defaultHeaders,
body: JSON.stringify(body),
signal: abortSignal,
});

export const runEcsGraph = async (
body: EcsMappingRequestBody,
{ http, abortSignal }: RequestDeps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import type { Pipeline, Docs } from '../../../../../common';
import type { Pipeline, Docs, SamplesFormat } from '../../../../../common';
import type { Actions, State } from '../state';
import type { AIConnector } from '../types';

const result: { pipeline: Pipeline; docs: Docs } = {
const result: { pipeline: Pipeline; docs: Docs; samplesFormat: SamplesFormat } = {
pipeline: {
description: 'Pipeline to process my_integration my_data_stream_title logs',
processors: [
Expand Down Expand Up @@ -389,6 +389,7 @@ const result: { pipeline: Pipeline; docs: Docs } = {
],
},
],
samplesFormat: { name: 'json' },
};

const rawSamples = [
Expand Down Expand Up @@ -419,8 +420,7 @@ export const mockState: State = {
dataStreamName: 'mocked_datastream_name',
dataStreamDescription: 'Mocked Data Stream Description',
inputTypes: ['filestream'],
logsSampleParsed: rawSamples,
samplesFormat: { name: 'ndjson', multiline: false },
logSamples: rawSamples,
},
isGenerating: false,
result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { createContext, useContext } from 'react';
import type { Pipeline, Docs } from '../../../../common';
import type { Pipeline, Docs, SamplesFormat } from '../../../../common';
import type { AIConnector, IntegrationSettings } from './types';

export interface State {
Expand All @@ -16,6 +16,7 @@ export interface State {
result?: {
pipeline: Pipeline;
docs: Docs;
samplesFormat?: SamplesFormat;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ import { TelemetryEventType } from '../../../../../services/telemetry/types';
const integrationSettings = mockState.integrationSettings!;
const connector = mockState.connector!;

const mockAnalyzeLogsResults = {
parsedSamples: [{ test: 'analyzeLogsResponse' }],
sampleLogsFormat: { name: 'json' },
};
const mockEcsMappingResults = { pipeline: { test: 'ecsMappingResponse' }, docs: [] };
const mockCategorizationResults = { pipeline: { test: 'categorizationResponse' }, docs: [] };
const mockRelatedResults = { pipeline: { test: 'relatedResponse' }, docs: [] };
const mockRunAnalyzeLogsGraph = jest.fn((_: unknown) => ({ results: mockAnalyzeLogsResults }));
const mockRunEcsGraph = jest.fn((_: unknown) => ({ results: mockEcsMappingResults }));
const mockRunCategorizationGraph = jest.fn((_: unknown) => ({
results: mockCategorizationResults,
}));
const mockRunRelatedGraph = jest.fn((_: unknown) => ({ results: mockRelatedResults }));

const defaultRequest = {
packageName: integrationSettings.name ?? '',
dataStreamName: integrationSettings.dataStreamName ?? '',
rawSamples: integrationSettings.logsSampleParsed ?? [],
connectorId: connector.id,
LangSmithOptions: undefined,
};

jest.mock('../../../../../common/lib/api', () => ({
runAnalyzeLogsGraph: (params: unknown) => mockRunAnalyzeLogsGraph(params),
runEcsGraph: (params: unknown) => mockRunEcsGraph(params),
runCategorizationGraph: (params: unknown) => mockRunCategorizationGraph(params),
runRelatedGraph: (params: unknown) => mockRunRelatedGraph(params),
Expand Down Expand Up @@ -74,21 +78,39 @@ describe('GenerationModal', () => {
expect(result.queryByTestId('generationModal')).toBeInTheDocument();
});

it('should call runAnalyzeLogsGraph with correct parameters', () => {
expect(mockRunAnalyzeLogsGraph).toHaveBeenCalledWith({
...defaultRequest,
logSamples: integrationSettings.logSamples ?? [],
});
});

it('should call runEcsGraph with correct parameters', () => {
expect(mockRunEcsGraph).toHaveBeenCalledWith(defaultRequest);
expect(mockRunEcsGraph).toHaveBeenCalledWith({
...defaultRequest,
rawSamples: mockAnalyzeLogsResults.parsedSamples,
packageName: integrationSettings.name ?? '',
dataStreamName: integrationSettings.dataStreamName ?? '',
});
});

it('should call runCategorizationGraph with correct parameters', () => {
expect(mockRunCategorizationGraph).toHaveBeenCalledWith({
...defaultRequest,
currentPipeline: mockEcsMappingResults.pipeline,
rawSamples: mockAnalyzeLogsResults.parsedSamples,
packageName: integrationSettings.name ?? '',
dataStreamName: integrationSettings.dataStreamName ?? '',
});
});

it('should call runRelatedGraph with correct parameters', () => {
expect(mockRunRelatedGraph).toHaveBeenCalledWith({
...defaultRequest,
currentPipeline: mockCategorizationResults.pipeline,
rawSamples: mockAnalyzeLogsResults.parsedSamples,
packageName: integrationSettings.name ?? '',
dataStreamName: integrationSettings.dataStreamName ?? '',
});
});

Expand All @@ -101,7 +123,7 @@ describe('GenerationModal', () => {
TelemetryEventType.IntegrationAssistantGenerationComplete,
{
sessionId: expect.any(String),
sampleRows: integrationSettings.logsSampleParsed?.length ?? 0,
sampleRows: integrationSettings.logSamples?.length ?? 0,
actionTypeId: connector.actionTypeId,
model: expect.anything(),
provider: connector.apiProvider ?? 'unknown',
Expand Down Expand Up @@ -147,7 +169,7 @@ describe('GenerationModal', () => {
TelemetryEventType.IntegrationAssistantGenerationComplete,
{
sessionId: expect.any(String),
sampleRows: integrationSettings.logsSampleParsed?.length ?? 0,
sampleRows: integrationSettings.logSamples?.length ?? 0,
actionTypeId: connector.actionTypeId,
model: expect.anything(),
provider: connector.apiProvider ?? 'unknown',
Expand Down
Loading