-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add an IngestService stats test #93120
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
Changes from 2 commits
4f855d2
daabd4f
c33063e
0bc58d2
0345647
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1389,6 +1389,83 @@ public void testBulkRequestExecution() throws Exception { | |
| } | ||
| } | ||
|
|
||
| public void testIngestAndPipelineStats() throws Exception { | ||
| final Processor processor = mock(Processor.class); | ||
| final Processor processorFailure = mock(Processor.class); | ||
joegallo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| when(processor.getType()).thenReturn("mock"); | ||
| when(processor.getTag()).thenReturn("mockTag"); | ||
| when(processor.isAsync()).thenReturn(true); | ||
|
|
||
| // avoid returning null and dropping the document | ||
| doAnswer(args -> { | ||
| @SuppressWarnings("unchecked") | ||
| BiConsumer<IngestDocument, Exception> handler = (BiConsumer) args.getArguments()[1]; | ||
| handler.accept(RandomDocumentPicks.randomIngestDocument(random()), null); | ||
| return null; | ||
| }).when(processor).execute(any(IngestDocument.class), any()); | ||
|
|
||
| IngestService ingestService = createWithProcessors(Map.of("mock", (factories, tag, description, config) -> processor)); | ||
|
|
||
| { | ||
| // all zeroes since nothing has executed | ||
| final IngestStats ingestStats = ingestService.stats(); | ||
| assertThat(ingestStats.getPipelineStats().size(), equalTo(0)); | ||
| assertStats(ingestStats.getTotalStats(), 0, 0, 0); | ||
| } | ||
|
|
||
| // put some pipelines, and now there are pipeline and processor stats, too | ||
| PutPipelineRequest putRequest1 = new PutPipelineRequest( | ||
| "_id1", | ||
| new BytesArray("{\"processors\": [{\"mock\" : {}}]}"), | ||
| XContentType.JSON | ||
| ); | ||
| PutPipelineRequest putRequest2 = new PutPipelineRequest( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth including a nested pipeline here? I know you and I have discussed that previously, but I'm not sure whether it actually makes the counters any more complex.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take a time-boxed swing at it, I do think it's worth adding (assuming it doesn't blow up the size or complexity of the test extraordinarily).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added via 0bc58d2. It's a bit janky, because there's a chicken and egg problem of the mock ingest service needing the processor factory, but the factory needing an ingest service. I'm game to take a swing at golfing it, though, if you'd like to join up for 10-15 minutes.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks reasonable enough to me. |
||
| "_id2", | ||
| new BytesArray("{\"processors\": [{\"mock\" : {}}]}"), | ||
| XContentType.JSON | ||
| ); | ||
| ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build(); // Start empty | ||
| ClusterState previousClusterState = clusterState; | ||
| clusterState = executePut(putRequest1, clusterState); | ||
| clusterState = executePut(putRequest2, clusterState); | ||
| ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); | ||
|
|
||
| { | ||
| final IngestStats ingestStats = ingestService.stats(); | ||
| assertThat(ingestStats.getPipelineStats().size(), equalTo(2)); | ||
|
|
||
| // total | ||
| assertStats(ingestStats.getTotalStats(), 0, 0, 0); | ||
| // pipeline | ||
| assertPipelineStats(ingestStats.getPipelineStats(), "_id1", 0, 0, 0); | ||
| assertPipelineStats(ingestStats.getPipelineStats(), "_id2", 0, 0, 0); | ||
| // processor | ||
| assertProcessorStats(0, ingestStats, "_id1", 0, 0, 0); | ||
| assertProcessorStats(0, ingestStats, "_id2", 0, 0, 0); | ||
| } | ||
|
|
||
| // put a single document through ingest processing | ||
| final IndexRequest indexRequest = new IndexRequest("_index"); | ||
| indexRequest.setPipeline("_id1").setFinalPipeline("_id2"); | ||
| indexRequest.source(randomAlphaOfLength(10), randomAlphaOfLength(10)); | ||
| ingestService.executeBulkRequest(1, List.of(indexRequest), indexReq -> {}, (integer, e) -> {}, (thread, e) -> {}, Names.WRITE); | ||
|
|
||
| { | ||
| final IngestStats ingestStats = ingestService.stats(); | ||
| assertThat(ingestStats.getPipelineStats().size(), equalTo(2)); | ||
|
|
||
| // total | ||
| // see https://github.com/elastic/elasticsearch/issues/92843 -- this should be 1, but it's actually 2 | ||
| // assertStats(ingestStats.getTotalStats(), 1, 0, 0); | ||
| // pipeline | ||
| assertPipelineStats(ingestStats.getPipelineStats(), "_id1", 1, 0, 0); | ||
| assertPipelineStats(ingestStats.getPipelineStats(), "_id2", 1, 0, 0); | ||
| // processor | ||
| assertProcessorStats(0, ingestStats, "_id1", 1, 0, 0); | ||
| assertProcessorStats(0, ingestStats, "_id2", 1, 0, 0); | ||
| } | ||
| } | ||
|
|
||
| public void testStats() throws Exception { | ||
| final Processor processor = mock(Processor.class); | ||
| final Processor processorFailure = mock(Processor.class); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.