mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [Register resident set size and limit bytes metrics in APM (#215458)](https://github.com/elastic/kibana/pull/215458) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Jesus Wahrman","email":"41008968+jesuswr@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-23T21:22:30Z","message":"Register resident set size and limit bytes metrics in APM (#215458)\n\n## Summary\n\nResolves https://github.com/elastic/kibana-team/issues/1565\n\nRegister resident set size and limit bytes metrics in APM.\n\n<img width=\"1614\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d5f1caf5-da4f-4acd-a63f-2b5256a91307\"\n/>\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\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- [x] 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)","sha":"04772fcc456aa6b03d9ecec540cc927c23c0dd9a","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","backport:prev-major","backport:current-major","v9.1.0"],"title":"Register resident set size and limit bytes metrics in APM","number":215458,"url":"https://github.com/elastic/kibana/pull/215458","mergeCommit":{"message":"Register resident set size and limit bytes metrics in APM (#215458)\n\n## Summary\n\nResolves https://github.com/elastic/kibana-team/issues/1565\n\nRegister resident set size and limit bytes metrics in APM.\n\n<img width=\"1614\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d5f1caf5-da4f-4acd-a63f-2b5256a91307\"\n/>\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\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- [x] 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)","sha":"04772fcc456aa6b03d9ecec540cc927c23c0dd9a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215458","number":215458,"mergeCommit":{"message":"Register resident set size and limit bytes metrics in APM (#215458)\n\n## Summary\n\nResolves https://github.com/elastic/kibana-team/issues/1565\n\nRegister resident set size and limit bytes metrics in APM.\n\n<img width=\"1614\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d5f1caf5-da4f-4acd-a63f-2b5256a91307\"\n/>\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\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- [x] 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)","sha":"04772fcc456aa6b03d9ecec540cc927c23c0dd9a"}}]}] BACKPORT--> Co-authored-by: Jesus Wahrman <41008968+jesuswr@users.noreply.github.com>
This commit is contained in:
parent
4d53520eea
commit
95782f6d3a
8 changed files with 55 additions and 2 deletions
|
@ -10,6 +10,7 @@
|
|||
import v8, { HeapInfo } from 'v8';
|
||||
import { mockEventLoopDelayMonitor, mockEventLoopUtilizationMonitor } from './process.test.mocks';
|
||||
import { ProcessMetricsCollector } from './process';
|
||||
import apm from 'elastic-apm-node';
|
||||
|
||||
describe('ProcessMetricsCollector', () => {
|
||||
let collector: ProcessMetricsCollector;
|
||||
|
@ -103,4 +104,24 @@ describe('ProcessMetricsCollector', () => {
|
|||
expect(mockEventLoopUtilizationMonitor.reset).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('register metrics in apm', () => {
|
||||
it('calls registerMetric in the constructor', () => {
|
||||
const apmSpy = jest.spyOn(apm, 'registerMetric');
|
||||
|
||||
collector.registerMetrics();
|
||||
|
||||
expect(apmSpy).toHaveBeenCalledTimes(2);
|
||||
expect(apmSpy).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'nodejs.memory.resident_set_size.bytes',
|
||||
expect.any(Function)
|
||||
);
|
||||
expect(apmSpy).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'nodejs.heap.size_limit.bytes',
|
||||
expect.any(Function)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
import v8 from 'v8';
|
||||
import type { OpsProcessMetrics, MetricsCollector } from '@kbn/core-metrics-server';
|
||||
import apm from 'elastic-apm-node';
|
||||
import { EventLoopDelaysMonitor } from './event_loop_delays_monitor';
|
||||
import { EventLoopUtilizationMonitor } from './event_loop_utilization_monitor';
|
||||
|
||||
|
@ -54,6 +55,14 @@ export class ProcessMetricsCollector implements MetricsCollector<OpsProcessMetri
|
|||
return [this.getCurrentPidMetrics()];
|
||||
}
|
||||
|
||||
public registerMetrics() {
|
||||
apm.registerMetric('nodejs.memory.resident_set_size.bytes', () => process.memoryUsage().rss);
|
||||
apm.registerMetric(
|
||||
'nodejs.heap.size_limit.bytes',
|
||||
() => v8.getHeapStatistics().heap_size_limit
|
||||
);
|
||||
}
|
||||
|
||||
public reset() {
|
||||
this.eventLoopDelayMonitor.reset();
|
||||
this.eventLoopUtilizationMonitor.reset();
|
||||
|
|
|
@ -21,7 +21,13 @@ const createMock = () => {
|
|||
return mocked;
|
||||
};
|
||||
|
||||
const createMockProcessMetricsCollector = () => ({
|
||||
...createMock(),
|
||||
registerMetrics: jest.fn().mockResolvedValue({}),
|
||||
});
|
||||
|
||||
export const collectorMock = {
|
||||
create: createMock,
|
||||
createOpsProcessMetrics: createMockOpsProcessMetrics,
|
||||
createProcessMetricsCollector: createMockProcessMetricsCollector,
|
||||
};
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
import { collectorMock } from '@kbn/core-metrics-collectors-server-mocks';
|
||||
|
||||
export const mockOpsCollector = collectorMock.create();
|
||||
export const mockOpsCollector = {
|
||||
...collectorMock.create(),
|
||||
registerMetrics: jest.fn(),
|
||||
};
|
||||
|
||||
jest.doMock('./ops_metrics_collector', () => ({
|
||||
OpsMetricsCollector: jest.fn().mockImplementation(() => mockOpsCollector),
|
||||
|
|
|
@ -78,6 +78,8 @@ export class MetricsService
|
|||
}
|
||||
);
|
||||
|
||||
this.metricsCollector.registerMetrics();
|
||||
|
||||
await this.refreshMetrics();
|
||||
|
||||
this.collectInterval = setInterval(() => {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
import { collectorMock } from '@kbn/core-metrics-collectors-server-mocks';
|
||||
|
||||
export const mockOsCollector = collectorMock.create();
|
||||
export const mockProcessCollector = collectorMock.create();
|
||||
export const mockProcessCollector = collectorMock.createProcessMetricsCollector();
|
||||
export const mockServerCollector = collectorMock.create();
|
||||
export const mockEsClientCollector = collectorMock.create();
|
||||
|
||||
|
|
|
@ -80,4 +80,12 @@ describe('OpsMetricsCollector', () => {
|
|||
expect(mockServerCollector.reset).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#registerMetrics', () => {
|
||||
it('call registerMetrics on the underlying collectors', () => {
|
||||
collector.registerMetrics();
|
||||
|
||||
expect(mockProcessCollector.registerMetrics).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -64,6 +64,10 @@ export class OpsMetricsCollector implements MetricsCollector<OpsMetrics> {
|
|||
};
|
||||
}
|
||||
|
||||
public registerMetrics() {
|
||||
this.processCollector.registerMetrics();
|
||||
}
|
||||
|
||||
public reset() {
|
||||
this.processCollector.reset();
|
||||
this.osCollector.reset();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue