Skip to content

Commit 188a33c

Browse files
committed
[Indices Metadata] Support metering stats in serverless (#244882)
## Summary Override index stats `docs_total_size_in_bytes`, `docs_total_size_in_bytes_primaries`, `docs_count`, and `docs_count_primaries` values with serverless metering info when running on serverless. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. (cherry picked from commit 6cedb56)
1 parent 03fdd40 commit 188a33c

5 files changed

Lines changed: 366 additions & 140 deletions

File tree

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ describe('Indices Metadata - IndicesMetadataService', () => {
197197
});
198198

199199
it('should initialize receiver and sender', () => {
200-
service.start(taskManagerStart, analytics, esClient);
200+
service.start(taskManagerStart, analytics, esClient, false);
201201

202-
expect(MetadataReceiver).toHaveBeenCalledWith(expect.any(Object), esClient);
202+
expect(MetadataReceiver).toHaveBeenCalledWith(expect.any(Object), esClient, false);
203203
expect(MetadataSender).toHaveBeenCalledWith(expect.any(Object), analytics);
204204
});
205205

@@ -209,14 +209,14 @@ describe('Indices Metadata - IndicesMetadataService', () => {
209209
subscribe: mockSubscribe,
210210
} as any);
211211

212-
service.start(taskManagerStart, analytics, esClient);
212+
service.start(taskManagerStart, analytics, esClient, false);
213213

214214
expect(configurationService.getIndicesMetadataConfiguration$).toHaveBeenCalled();
215215
expect(mockSubscribe).toHaveBeenCalledWith(expect.any(Function));
216216
});
217217

218218
it('should schedule indices metadata task', async () => {
219-
service.start(taskManagerStart, analytics, esClient);
219+
service.start(taskManagerStart, analytics, esClient, false);
220220

221221
await new Promise((resolve) => setTimeout(resolve, 0));
222222

@@ -235,7 +235,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
235235
const error = new Error('Failed to schedule task');
236236
taskManagerStart.ensureScheduled.mockRejectedValue(error);
237237

238-
service.start(taskManagerStart, analytics, esClient);
238+
service.start(taskManagerStart, analytics, esClient, false);
239239

240240
await new Promise((resolve) => setTimeout(resolve, 0));
241241

@@ -250,7 +250,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
250250
subscribe: mockSubscribe,
251251
} as any);
252252

253-
service.start(taskManagerStart, analytics, esClient);
253+
service.start(taskManagerStart, analytics, esClient, false);
254254

255255
const configurationCallback = mockSubscribe.mock.calls[0][0];
256256
configurationCallback(mockConfiguration);
@@ -267,7 +267,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
267267
subscribe: jest.fn().mockReturnValue(subscription),
268268
} as any);
269269

270-
service.start(taskManagerStart, analytics, esClient);
270+
service.start(taskManagerStart, analytics, esClient, false);
271271
service.stop();
272272

273273
expect(subscription.unsubscribe).toHaveBeenCalled();
@@ -288,7 +288,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
288288
}),
289289
} as any);
290290

291-
service.start(taskManagerStart, analytics, esClient);
291+
service.start(taskManagerStart, analytics, esClient, false);
292292

293293
receiver.getIndices.mockResolvedValue(mockIndexSettings);
294294
receiver.getDataStreams.mockResolvedValue(mockDataStreams);
@@ -394,7 +394,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
394394
}),
395395
} as any);
396396

397-
service.start(taskManagerStart, analytics, esClient);
397+
service.start(taskManagerStart, analytics, esClient, false);
398398
});
399399

400400
it('should run publishIndicesMetadata and return state', async () => {
@@ -424,7 +424,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
424424
}),
425425
} as any);
426426

427-
service.start(taskManagerStart, analytics, esClient);
427+
service.start(taskManagerStart, analytics, esClient, false);
428428
});
429429

430430
describe('publishDatastreamsStats', () => {
@@ -574,7 +574,7 @@ describe('Indices Metadata - IndicesMetadataService', () => {
574574
}),
575575
} as any);
576576

577-
service.start(taskManagerStart, analytics, esClient);
577+
service.start(taskManagerStart, analytics, esClient, false);
578578
});
579579

580580
it('should handle receiver errors during publishIndicesMetadata', async () => {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ export class IndicesMetadataService {
6464
public start(
6565
taskManager: TaskManagerStartContract,
6666
analytics: AnalyticsServiceStart,
67-
esClient: ElasticsearchClient
67+
esClient: ElasticsearchClient,
68+
isServerless: boolean
6869
) {
6970
this.logger.debug('Starting indices metadata service');
7071

71-
this.receiver = new MetadataReceiver(this.logger, esClient);
72+
this.receiver = new MetadataReceiver(this.logger, esClient, isServerless);
7273
this.sender = new MetadataSender(this.logger, analytics);
7374

7475
this.subscription$ = this.configurationService
@@ -241,7 +242,9 @@ export class IndicesMetadataService {
241242
indicesStats.items.push(stat);
242243
}
243244
this.sender.reportEBT(INDEX_STATS_EVENT, indicesStats);
244-
this.logger.debug('Indices stats sent', { count: indicesStats.items.length } as LogMeta);
245+
this.logger.debug('Indices stats sent', {
246+
count: indicesStats.items.length,
247+
} as LogMeta);
245248
return indicesStats.items.length;
246249
}
247250

0 commit comments

Comments
 (0)