Skip to content

Commit bedd1a5

Browse files
[9.0] [Telemetry][Indices Metadata] Update index stats query (elastic#233500) (elastic#233512)
# Backport This will backport the following commits from `main` to `9.0`: - [[Telemetry][Indices Metadata] Update index stats query (elastic#233500)](elastic#233500) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sebastián Zaffarano","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-08-29T16:06:45Z","message":"[Telemetry][Indices Metadata] Update index stats query (elastic#233500)\n\n## Summary\n\nInclude per-primaries data in index stats query.\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"f6f24122daeb79e9e326fc823a0bde10bee61df8","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","backport:prev-major","backport:current-major","v9.2.0"],"title":"[Telemetry][Indices Metadata] Update index stats query","number":233500,"url":"https://github.com/elastic/kibana/pull/233500","mergeCommit":{"message":"[Telemetry][Indices Metadata] Update index stats query (elastic#233500)\n\n## Summary\n\nInclude per-primaries data in index stats query.\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"f6f24122daeb79e9e326fc823a0bde10bee61df8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/233500","number":233500,"mergeCommit":{"message":"[Telemetry][Indices Metadata] Update index stats query (elastic#233500)\n\n## Summary\n\nInclude per-primaries data in index stats query.\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"f6f24122daeb79e9e326fc823a0bde10bee61df8"}}]}] BACKPORT--> Co-authored-by: Sebastián Zaffarano <[email protected]>
1 parent e14f1c7 commit bedd1a5

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed

x-pack/platform/plugins/private/indices_metadata/server/lib/services/receiver.test.ts

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ describe('Indices Metadata - MetadataReceiver', () => {
405405
store: {
406406
size_in_bytes: 1024000,
407407
},
408+
indexing: {
409+
index_failed: 5,
410+
index_failed_due_to_version_conflict: 2,
411+
},
412+
},
413+
primaries: {
414+
docs: {
415+
count: 250,
416+
deleted: 5,
417+
},
418+
store: {
419+
size_in_bytes: 512000,
420+
},
408421
},
409422
},
410423
},
@@ -426,9 +439,17 @@ describe('Indices Metadata - MetadataReceiver', () => {
426439
filter_path: [
427440
'indices.*.total.search.query_total',
428441
'indices.*.total.search.query_time_in_millis',
442+
429443
'indices.*.total.docs.count',
430444
'indices.*.total.docs.deleted',
431445
'indices.*.total.store.size_in_bytes',
446+
447+
'indices.*.primaries.docs.count',
448+
'indices.*.primaries.docs.deleted',
449+
'indices.*.primaries.store.size_in_bytes',
450+
451+
'indices.*.total.indexing.index_failed',
452+
'indices.*.total.indexing.index_failed_due_to_version_conflict',
432453
],
433454
});
434455

@@ -440,6 +461,11 @@ describe('Indices Metadata - MetadataReceiver', () => {
440461
docs_count: 500,
441462
docs_deleted: 10,
442463
docs_total_size_in_bytes: 1024000,
464+
index_failed: 5,
465+
index_failed_due_to_version_conflict: 2,
466+
docs_count_primaries: 250,
467+
docs_deleted_primaries: 5,
468+
docs_total_size_in_bytes_primaries: 512000,
443469
},
444470
]);
445471
});
@@ -500,6 +526,143 @@ describe('Indices Metadata - MetadataReceiver', () => {
500526
await expect(iterator.next()).rejects.toThrow('Elasticsearch error');
501527
expect(logger.error).toHaveBeenCalledWith('Error fetching indices stats', { error });
502528
});
529+
530+
it('should handle response with missing primaries data', async () => {
531+
const mockResponseWithoutPrimaries = {
532+
indices: {
533+
'test-index-1': {
534+
total: {
535+
search: {
536+
query_total: 100,
537+
query_time_in_millis: 1000,
538+
},
539+
docs: {
540+
count: 500,
541+
deleted: 10,
542+
},
543+
store: {
544+
size_in_bytes: 1024000,
545+
},
546+
indexing: {
547+
index_failed: 5,
548+
index_failed_due_to_version_conflict: 2,
549+
},
550+
},
551+
},
552+
},
553+
};
554+
555+
(esClient.indices.stats as jest.Mock).mockResolvedValue(mockResponseWithoutPrimaries);
556+
557+
const results = [];
558+
for await (const stat of receiver.getIndicesStats(['test-index-1'], 10)) {
559+
results.push(stat);
560+
}
561+
562+
expect(results).toEqual([
563+
{
564+
index_name: 'test-index-1',
565+
query_total: 100,
566+
query_time_in_millis: 1000,
567+
docs_count: 500,
568+
docs_deleted: 10,
569+
docs_total_size_in_bytes: 1024000,
570+
index_failed: 5,
571+
index_failed_due_to_version_conflict: 2,
572+
docs_count_primaries: undefined,
573+
docs_deleted_primaries: undefined,
574+
docs_total_size_in_bytes_primaries: undefined,
575+
},
576+
]);
577+
});
578+
579+
it('should handle response with missing indexing failure data', async () => {
580+
const mockResponseWithoutIndexingFailures = {
581+
indices: {
582+
'test-index-1': {
583+
total: {
584+
search: {
585+
query_total: 100,
586+
query_time_in_millis: 1000,
587+
},
588+
docs: {
589+
count: 500,
590+
deleted: 10,
591+
},
592+
store: {
593+
size_in_bytes: 1024000,
594+
},
595+
},
596+
primaries: {
597+
docs: {
598+
count: 250,
599+
deleted: 5,
600+
},
601+
store: {
602+
size_in_bytes: 512000,
603+
},
604+
},
605+
},
606+
},
607+
};
608+
609+
(esClient.indices.stats as jest.Mock).mockResolvedValue(mockResponseWithoutIndexingFailures);
610+
611+
const results = [];
612+
for await (const stat of receiver.getIndicesStats(['test-index-1'], 10)) {
613+
results.push(stat);
614+
}
615+
616+
expect(results).toEqual([
617+
{
618+
index_name: 'test-index-1',
619+
query_total: 100,
620+
query_time_in_millis: 1000,
621+
docs_count: 500,
622+
docs_deleted: 10,
623+
docs_total_size_in_bytes: 1024000,
624+
index_failed: undefined,
625+
index_failed_due_to_version_conflict: undefined,
626+
docs_count_primaries: 250,
627+
docs_deleted_primaries: 5,
628+
docs_total_size_in_bytes_primaries: 512000,
629+
},
630+
]);
631+
});
632+
633+
it('should continue processing when receiver methods return empty results', async () => {
634+
const mockResponseMinimalData = {
635+
indices: {
636+
'test-index-1': {
637+
total: {},
638+
primaries: {},
639+
},
640+
},
641+
};
642+
643+
(esClient.indices.stats as jest.Mock).mockResolvedValue(mockResponseMinimalData);
644+
645+
const results = [];
646+
for await (const stat of receiver.getIndicesStats(['test-index-1'], 10)) {
647+
results.push(stat);
648+
}
649+
650+
expect(results).toEqual([
651+
{
652+
index_name: 'test-index-1',
653+
query_total: undefined,
654+
query_time_in_millis: undefined,
655+
docs_count: undefined,
656+
docs_deleted: undefined,
657+
docs_total_size_in_bytes: undefined,
658+
index_failed: undefined,
659+
index_failed_due_to_version_conflict: undefined,
660+
docs_count_primaries: undefined,
661+
docs_deleted_primaries: undefined,
662+
docs_total_size_in_bytes_primaries: undefined,
663+
},
664+
]);
665+
});
503666
});
504667

505668
describe('isIlmStatsAvailable', () => {

x-pack/platform/plugins/private/indices_metadata/server/lib/services/receiver.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,17 @@ export class MetadataReceiver {
121121
filter_path: [
122122
'indices.*.total.search.query_total',
123123
'indices.*.total.search.query_time_in_millis',
124+
124125
'indices.*.total.docs.count',
125126
'indices.*.total.docs.deleted',
126127
'indices.*.total.store.size_in_bytes',
128+
129+
'indices.*.primaries.docs.count',
130+
'indices.*.primaries.docs.deleted',
131+
'indices.*.primaries.store.size_in_bytes',
132+
133+
'indices.*.total.indexing.index_failed',
134+
'indices.*.total.indexing.index_failed_due_to_version_conflict',
127135
],
128136
};
129137

@@ -137,6 +145,14 @@ export class MetadataReceiver {
137145
docs_count: stats.total?.docs?.count,
138146
docs_deleted: stats.total?.docs?.deleted,
139147
docs_total_size_in_bytes: stats.total?.store?.size_in_bytes,
148+
149+
index_failed: stats.total?.indexing?.index_failed,
150+
index_failed_due_to_version_conflict: (stats.total?.indexing as any)
151+
?.index_failed_due_to_version_conflict,
152+
153+
docs_count_primaries: stats.primaries?.docs?.count,
154+
docs_deleted_primaries: stats.primaries?.docs?.deleted,
155+
docs_total_size_in_bytes_primaries: stats.primaries?.store?.size_in_bytes,
140156
} as IndexStats;
141157
}
142158
} catch (error) {

0 commit comments

Comments
 (0)