-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.8`: - [[APM] Check if metric fields exist (#145348)](#145348) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Katerina Patticha","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-04-27T12:55:14Z","message":"[APM] Check if metric fields exist (#145348)\n\nFixes the error \r\n```\r\n\"script_stack\": [\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues.throwIfEmpty(ScriptDocValues.java:92)\",\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:110)\",\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:105)\",\r\n \"\"\"total = useCgroupLimit ? doc[limitKey].value : doc['system.memory.total'].value;\r\n\r\n double \"\"\",\r\n \" ^---- HERE\"\r\n\r\n\r\n```\r\n\r\nconnected elastic/sdh-apm#765 (internal)\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Søren Louv-Jansen <[email protected]>","sha":"98165d26846367b98a259f76b664545a43d2434b","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:APM","backport:prev-minor","v8.8.0","v8.7.1","v8.9.0"],"number":145348,"url":"https://github.com/elastic/kibana/pull/145348","mergeCommit":{"message":"[APM] Check if metric fields exist (#145348)\n\nFixes the error \r\n```\r\n\"script_stack\": [\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues.throwIfEmpty(ScriptDocValues.java:92)\",\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:110)\",\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:105)\",\r\n \"\"\"total = useCgroupLimit ? doc[limitKey].value : doc['system.memory.total'].value;\r\n\r\n double \"\"\",\r\n \" ^---- HERE\"\r\n\r\n\r\n```\r\n\r\nconnected elastic/sdh-apm#765 (internal)\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Søren Louv-Jansen <[email protected]>","sha":"98165d26846367b98a259f76b664545a43d2434b"}},"sourceBranch":"main","suggestedTargetBranches":["8.8","8.7"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145348","number":145348,"mergeCommit":{"message":"[APM] Check if metric fields exist (#145348)\n\nFixes the error \r\n```\r\n\"script_stack\": [\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues.throwIfEmpty(ScriptDocValues.java:92)\",\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:110)\",\r\n \"[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:105)\",\r\n \"\"\"total = useCgroupLimit ? doc[limitKey].value : doc['system.memory.total'].value;\r\n\r\n double \"\"\",\r\n \" ^---- HERE\"\r\n\r\n\r\n```\r\n\r\nconnected elastic/sdh-apm#765 (internal)\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Søren Louv-Jansen <[email protected]>","sha":"98165d26846367b98a259f76b664545a43d2434b"}}]}] BACKPORT--> Co-authored-by: Katerina Patticha <[email protected]>
- Loading branch information
1 parent
e204707
commit b64f2f2
Showing
8 changed files
with
263 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 63 additions & 6 deletions
69
x-pack/plugins/apm/server/routes/metrics/__snapshots__/queries.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
x-pack/test/apm_api_integration/tests/metrics/memory/generate_data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { apm, timerange } from '@kbn/apm-synthtrace-client'; | ||
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; | ||
|
||
const gigabytesToBytes = (value: number) => value * Math.pow(1024, 3); | ||
|
||
export const config = { | ||
memoryTotal: gigabytesToBytes(64), | ||
memoryFree: gigabytesToBytes(5.5), | ||
cGroupMemoryLimit: gigabytesToBytes(8), | ||
cGroupMemoryUsage: gigabytesToBytes(1.5), | ||
}; | ||
|
||
export const expectedValues = { | ||
expectedMemoryUsedRate: (config.memoryTotal - config.memoryFree) / config.memoryTotal, | ||
expectedMemoryUsed: config.memoryTotal - config.memoryFree, | ||
}; | ||
|
||
export async function generateData({ | ||
synthtraceEsClient, | ||
start, | ||
end, | ||
}: { | ||
synthtraceEsClient: ApmSynthtraceEsClient; | ||
start: number; | ||
end: number; | ||
}) { | ||
const { memoryTotal, memoryFree, cGroupMemoryLimit, cGroupMemoryUsage } = config; | ||
|
||
const systemMetricOnlyInstance = apm | ||
.service({ name: 'system-metric-only-service', environment: 'production', agentName: 'go' }) | ||
.instance('system-metric-only-production'); | ||
|
||
const cGroupMemoryOnlyInstance = apm | ||
.service({ name: 'cgroup-memory-only-service', environment: 'production', agentName: 'go' }) | ||
.instance('cgroup-memory-only-production'); | ||
|
||
const cGroupMemoryWithLimitInstance = apm | ||
.service({ | ||
name: 'cgroup-memory-with-limit-production', | ||
environment: 'production', | ||
agentName: 'go', | ||
}) | ||
.instance('cgroup-memory-with-limit-production'); | ||
|
||
const transactionsEvents = timerange(start, end) | ||
.ratePerMinute(1) | ||
.generator((timestamp) => [ | ||
systemMetricOnlyInstance | ||
.appMetrics({ | ||
'system.memory.actual.free': memoryFree, | ||
'system.memory.total': memoryTotal, | ||
}) | ||
.timestamp(timestamp), | ||
cGroupMemoryOnlyInstance | ||
.appMetrics({ | ||
'system.process.cgroup.memory.mem.usage.bytes': cGroupMemoryUsage, | ||
}) | ||
.timestamp(timestamp), | ||
|
||
cGroupMemoryWithLimitInstance | ||
.appMetrics({ | ||
'system.process.cgroup.memory.mem.usage.bytes': cGroupMemoryUsage, | ||
'system.process.cgroup.memory.mem.limit.bytes': cGroupMemoryLimit, | ||
'system.memory.total': memoryTotal, | ||
'system.memory.actual.free': memoryFree, | ||
}) | ||
.timestamp(timestamp), | ||
]); | ||
|
||
await synthtraceEsClient.index(transactionsEvents); | ||
} |
83 changes: 83 additions & 0 deletions
83
x-pack/test/apm_api_integration/tests/metrics/memory/memory_metrics.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../common/ftr_provider_context'; | ||
import { config, generateData } from './generate_data'; | ||
|
||
export default function ApiTest({ getService }: FtrProviderContext) { | ||
const registry = getService('registry'); | ||
const apmApiClient = getService('apmApiClient'); | ||
const synthtraceEsClient = getService('synthtraceEsClient'); | ||
|
||
const start = new Date('2023-01-01T00:00:00.000Z').getTime(); | ||
const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; | ||
|
||
async function callMetricChartsAPI(serviceName: string) { | ||
return await apmApiClient.readUser({ | ||
endpoint: `GET /internal/apm/services/{serviceName}/metrics/charts`, | ||
params: { | ||
path: { serviceName }, | ||
query: { | ||
environment: 'production', | ||
start: new Date(start).toISOString(), | ||
end: new Date(end).toISOString(), | ||
kuery: '', | ||
agentName: 'go', | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
registry.when('Memory', { config: 'trial', archives: [] }, () => { | ||
before(async () => { | ||
await generateData({ start, end, synthtraceEsClient }); | ||
}); | ||
|
||
after(() => synthtraceEsClient.clean()); | ||
|
||
it('returns system memory stats', async () => { | ||
const expectedFreeMemory = 1 - config.memoryFree / config.memoryTotal; | ||
|
||
const { status, body } = await callMetricChartsAPI('system-metric-only-service'); | ||
const memoryChart = body.charts.find(({ key }) => key === 'memory_usage_chart'); | ||
|
||
expect(status).to.be(200); | ||
[ | ||
{ title: 'Max', expectedValue: expectedFreeMemory }, | ||
{ title: 'Average', expectedValue: expectedFreeMemory }, | ||
].map(({ title, expectedValue }) => { | ||
const series = memoryChart?.series.find((item) => item.title === title); | ||
expect(series?.overallValue).to.eql(expectedValue); | ||
}); | ||
}); | ||
|
||
it('returns cgroup memory with system.process.cgroup.memory.mem.limit.bytes', async () => { | ||
const expectedFreeMemory = config.cGroupMemoryUsage / config.cGroupMemoryLimit; | ||
|
||
const { status, body } = await callMetricChartsAPI('cgroup-memory-with-limit-production'); | ||
const memoryChart = body.charts.find(({ key }) => key === 'memory_usage_chart'); | ||
|
||
expect(status).to.be(200); | ||
[ | ||
{ title: 'Max', expectedValue: expectedFreeMemory }, | ||
{ title: 'Average', expectedValue: expectedFreeMemory }, | ||
].map(({ title, expectedValue }) => { | ||
const series = memoryChart?.series.find((item) => item.title === title); | ||
expect(series?.overallValue).to.eql(expectedValue); | ||
}); | ||
}); | ||
|
||
it('handles cgroup memory stats when system.process.cgroup.memory.mem.limit.bytes and system.memory.total are not present', async () => { | ||
const { status, body } = await callMetricChartsAPI('cgroup-memory-only-production'); | ||
expect(status).to.be(200); | ||
|
||
const memoryChart = body.charts.find(({ key }) => key === 'memory_usage_chart'); | ||
expect(memoryChart?.series).to.eql([]); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.