8
8
import { LogicMounter } from '../../../../../__mocks__/kea_logic' ;
9
9
10
10
import { HttpResponse } from '@kbn/core/public' ;
11
+ import { TrainedModelConfigResponse } from '@kbn/ml-plugin/common/types/trained_models' ;
11
12
12
13
import { ErrorResponse , HttpError , Status } from '../../../../../../../common/types/api' ;
13
14
import { TrainedModelState } from '../../../../../../../common/types/pipelines' ;
@@ -18,6 +19,7 @@ import { AttachMlInferencePipelineApiLogic } from '../../../../api/pipelines/att
18
19
import { CreateMlInferencePipelineApiLogic } from '../../../../api/pipelines/create_ml_inference_pipeline' ;
19
20
import { FetchMlInferencePipelineProcessorsApiLogic } from '../../../../api/pipelines/fetch_ml_inference_pipeline_processors' ;
20
21
import { FetchMlInferencePipelinesApiLogic } from '../../../../api/pipelines/fetch_ml_inference_pipelines' ;
22
+ import { SimulateExistingMlInterfacePipelineApiLogic } from '../../../../api/pipelines/simulate_existing_ml_inference_pipeline' ;
21
23
import { SimulateMlInterfacePipelineApiLogic } from '../../../../api/pipelines/simulate_ml_inference_pipeline_processors' ;
22
24
23
25
import {
@@ -69,6 +71,8 @@ const DEFAULT_VALUES: MLInferenceProcessorsValues = {
69
71
mlInferencePipelinesData : undefined ,
70
72
mlModelsData : undefined ,
71
73
mlModelsStatus : 0 ,
74
+ simulateExistingPipelineData : undefined ,
75
+ simulateExistingPipelineStatus : 0 ,
72
76
simulatePipelineData : undefined ,
73
77
simulatePipelineErrors : [ ] ,
74
78
simulatePipelineResult : undefined ,
@@ -81,6 +85,9 @@ describe('MlInferenceLogic', () => {
81
85
const { mount } = new LogicMounter ( MLInferenceLogic ) ;
82
86
const { mount : mountMappingApiLogic } = new LogicMounter ( MappingsApiLogic ) ;
83
87
const { mount : mountMLModelsApiLogic } = new LogicMounter ( MLModelsApiLogic ) ;
88
+ const { mount : mountSimulateExistingMlInterfacePipelineApiLogic } = new LogicMounter (
89
+ SimulateExistingMlInterfacePipelineApiLogic
90
+ ) ;
84
91
const { mount : mountSimulateMlInterfacePipelineApiLogic } = new LogicMounter (
85
92
SimulateMlInterfacePipelineApiLogic
86
93
) ;
@@ -103,6 +110,7 @@ describe('MlInferenceLogic', () => {
103
110
mountMLModelsApiLogic ( ) ;
104
111
mountFetchMlInferencePipelineProcessorsApiLogic ( ) ;
105
112
mountFetchMlInferencePipelinesApiLogic ( ) ;
113
+ mountSimulateExistingMlInterfacePipelineApiLogic ( ) ;
106
114
mountSimulateMlInterfacePipelineApiLogic ( ) ;
107
115
mountCreateMlInferencePipelineApiLogic ( ) ;
108
116
mountAttachMlInferencePipelineApiLogic ( ) ;
@@ -245,6 +253,44 @@ describe('MlInferenceLogic', () => {
245
253
} ;
246
254
SimulateMlInterfacePipelineApiLogic . actions . apiSuccess ( simulateResponse ) ;
247
255
256
+ expect ( MLInferenceLogic . values . simulatePipelineResult ) . toEqual ( simulateResponse ) ;
257
+ } ) ;
258
+ it ( 'returns existing simulation result when API is successful' , ( ) => {
259
+ const simulateResponse = {
260
+ docs : [
261
+ {
262
+ doc : {
263
+ _id : 'id' ,
264
+ _index : 'index' ,
265
+ _ingest : { timestamp : '2022-10-06T10:28:54.3326245Z' } ,
266
+ _source : {
267
+ _ingest : {
268
+ inference_errors : [
269
+ {
270
+ message :
271
+ "Processor 'inference' in pipeline 'test' failed with message 'Input field [text_field] does not exist in the source document'" ,
272
+ pipeline : 'guy' ,
273
+ timestamp : '2022-10-06T10:28:54.332624500Z' ,
274
+ } ,
275
+ ] ,
276
+ processors : [
277
+ {
278
+ model_version : '8.6.0' ,
279
+ pipeline : 'guy' ,
280
+ processed_timestamp : '2022-10-06T10:28:54.332624500Z' ,
281
+ types : [ 'pytorch' , 'ner' ] ,
282
+ } ,
283
+ ] ,
284
+ } ,
285
+ _version : '-3' ,
286
+ foo : 'bar' ,
287
+ } ,
288
+ } ,
289
+ } ,
290
+ ] ,
291
+ } ;
292
+ SimulateExistingMlInterfacePipelineApiLogic . actions . apiSuccess ( simulateResponse ) ;
293
+
248
294
expect ( MLInferenceLogic . values . simulatePipelineResult ) . toEqual ( simulateResponse ) ;
249
295
} ) ;
250
296
} ) ;
@@ -322,7 +368,7 @@ describe('MlInferenceLogic', () => {
322
368
} ,
323
369
] ) ;
324
370
} ) ;
325
- it ( 'returns disabled pipeline option if model is redacted' , ( ) => {
371
+ it ( 'returns enabled pipeline option if model is redacted' , ( ) => {
326
372
FetchMlInferencePipelinesApiLogic . actions . apiSuccess ( {
327
373
'unit-test' : {
328
374
processors : [
@@ -343,8 +389,7 @@ describe('MlInferenceLogic', () => {
343
389
expect ( MLInferenceLogic . values . existingInferencePipelines ) . toEqual ( [
344
390
{
345
391
destinationField : 'test-field' ,
346
- disabled : true ,
347
- disabledReason : expect . any ( String ) ,
392
+ disabled : false ,
348
393
pipelineName : 'unit-test' ,
349
394
modelType : '' ,
350
395
modelId : '' ,
@@ -518,5 +563,127 @@ describe('MlInferenceLogic', () => {
518
563
} ) ;
519
564
} ) ;
520
565
} ) ;
566
+ describe ( 'simulatePipeline' , ( ) => {
567
+ const mockModelConfiguration = {
568
+ ...DEFAULT_VALUES . addInferencePipelineModal ,
569
+ configuration : {
570
+ destinationField : '' ,
571
+ modelID : 'mock-model-id' ,
572
+ pipelineName : 'mock-pipeline-name' ,
573
+ sourceField : 'mock_text_field' ,
574
+ } ,
575
+ indexName : 'my-index-123' ,
576
+ } ;
577
+ const mlModelsData : TrainedModelConfigResponse [ ] = [
578
+ {
579
+ inference_config : {
580
+ text_classification : { } ,
581
+ } ,
582
+ input : {
583
+ field_names : [ 'text_field' ] ,
584
+ } ,
585
+ model_id : 'mock-model-id' ,
586
+ model_type : 'pytorch' ,
587
+ tags : [ 'test_tag' ] ,
588
+ version : '1' ,
589
+ } ,
590
+ ] ;
591
+ it ( 'does nothing if mlInferencePipeline is undefined' , ( ) => {
592
+ mount ( {
593
+ ...DEFAULT_VALUES ,
594
+ } ) ;
595
+
596
+ jest . spyOn ( MLInferenceLogic . actions , 'setSimulatePipelineErrors' ) ;
597
+ jest . spyOn ( MLInferenceLogic . actions , 'simulateExistingPipelineApiReset' ) ;
598
+ jest . spyOn ( MLInferenceLogic . actions , 'simulatePipelineApiReset' ) ;
599
+ jest . spyOn ( MLInferenceLogic . actions , 'makeSimulateExistingPipelineRequest' ) ;
600
+ jest . spyOn ( MLInferenceLogic . actions , 'makeSimulatePipelineRequest' ) ;
601
+
602
+ MLInferenceLogic . actions . simulatePipeline ( ) ;
603
+
604
+ expect ( MLInferenceLogic . actions . setSimulatePipelineErrors ) . toHaveBeenCalledTimes ( 0 ) ;
605
+ expect ( MLInferenceLogic . actions . simulateExistingPipelineApiReset ) . toHaveBeenCalledTimes ( 0 ) ;
606
+ expect ( MLInferenceLogic . actions . simulatePipelineApiReset ) . toHaveBeenCalledTimes ( 0 ) ;
607
+ expect ( MLInferenceLogic . actions . makeSimulateExistingPipelineRequest ) . toHaveBeenCalledTimes (
608
+ 0
609
+ ) ;
610
+ expect ( MLInferenceLogic . actions . makeSimulatePipelineRequest ) . toHaveBeenCalledTimes ( 0 ) ;
611
+ } ) ;
612
+ it ( 'clears simulate errors' , ( ) => {
613
+ mount ( {
614
+ ...DEFAULT_VALUES ,
615
+ addInferencePipelineModal : {
616
+ ...mockModelConfiguration ,
617
+ } ,
618
+ } ) ;
619
+ MLModelsApiLogic . actions . apiSuccess ( mlModelsData ) ;
620
+ jest . spyOn ( MLInferenceLogic . actions , 'setSimulatePipelineErrors' ) ;
621
+ MLInferenceLogic . actions . simulatePipeline ( ) ;
622
+ expect ( MLInferenceLogic . actions . setSimulatePipelineErrors ) . toHaveBeenCalledWith ( [ ] ) ;
623
+ } ) ;
624
+ it ( 'resets API logics' , ( ) => {
625
+ mount ( {
626
+ ...DEFAULT_VALUES ,
627
+ addInferencePipelineModal : {
628
+ ...mockModelConfiguration ,
629
+ } ,
630
+ } ) ;
631
+ MLModelsApiLogic . actions . apiSuccess ( mlModelsData ) ;
632
+
633
+ jest . spyOn ( MLInferenceLogic . actions , 'simulateExistingPipelineApiReset' ) ;
634
+ jest . spyOn ( MLInferenceLogic . actions , 'simulatePipelineApiReset' ) ;
635
+
636
+ MLInferenceLogic . actions . simulatePipeline ( ) ;
637
+
638
+ expect ( MLInferenceLogic . actions . simulateExistingPipelineApiReset ) . toHaveBeenCalledTimes ( 1 ) ;
639
+ expect ( MLInferenceLogic . actions . simulatePipelineApiReset ) . toHaveBeenCalledTimes ( 1 ) ;
640
+ } ) ;
641
+ it ( 'calls simulate with new pipeline' , ( ) => {
642
+ mount ( {
643
+ ...DEFAULT_VALUES ,
644
+ addInferencePipelineModal : {
645
+ ...mockModelConfiguration ,
646
+ } ,
647
+ } ) ;
648
+ MLModelsApiLogic . actions . apiSuccess ( mlModelsData ) ;
649
+
650
+ jest . spyOn ( MLInferenceLogic . actions , 'makeSimulateExistingPipelineRequest' ) ;
651
+ jest . spyOn ( MLInferenceLogic . actions , 'makeSimulatePipelineRequest' ) ;
652
+
653
+ MLInferenceLogic . actions . simulatePipeline ( ) ;
654
+
655
+ expect ( MLInferenceLogic . actions . makeSimulatePipelineRequest ) . toHaveBeenCalledTimes ( 1 ) ;
656
+ expect ( MLInferenceLogic . actions . makeSimulateExistingPipelineRequest ) . toHaveBeenCalledTimes (
657
+ 0
658
+ ) ;
659
+ } ) ;
660
+ it ( 'calls simulate existing with existing pipeline' , ( ) => {
661
+ mount ( {
662
+ ...DEFAULT_VALUES ,
663
+ addInferencePipelineModal : {
664
+ ...mockModelConfiguration ,
665
+ configuration : {
666
+ ...mockModelConfiguration . configuration ,
667
+ existingPipeline : true ,
668
+ pipelineName : 'my-test-pipeline' ,
669
+ } ,
670
+ } ,
671
+ } ) ;
672
+ MLModelsApiLogic . actions . apiSuccess ( mlModelsData ) ;
673
+ FetchMlInferencePipelinesApiLogic . actions . apiSuccess ( {
674
+ 'my-test-pipeline' : { } ,
675
+ } ) ;
676
+
677
+ jest . spyOn ( MLInferenceLogic . actions , 'makeSimulateExistingPipelineRequest' ) ;
678
+ jest . spyOn ( MLInferenceLogic . actions , 'makeSimulatePipelineRequest' ) ;
679
+
680
+ MLInferenceLogic . actions . simulatePipeline ( ) ;
681
+
682
+ expect ( MLInferenceLogic . actions . makeSimulateExistingPipelineRequest ) . toHaveBeenCalledTimes (
683
+ 1
684
+ ) ;
685
+ expect ( MLInferenceLogic . actions . makeSimulatePipelineRequest ) . toHaveBeenCalledTimes ( 0 ) ;
686
+ } ) ;
687
+ } ) ;
521
688
} ) ;
522
689
} ) ;
0 commit comments