-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Check if metric fields exist #145348
Conversation
This number represents the max possible value for the limit field. | ||
*/ | ||
double CGROUP_LIMIT_MAX_VALUE = 9223372036854771712L; | ||
if(doc.containsKey('${METRIC_CGROUP_MEMORY_LIMIT_BYTES}') && doc.containsKey('${METRIC_CGROUP_MEMORY_USAGE_BYTES}')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about doc['${METRIC_SYSTEM_TOTAL_MEMORY}']
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I was trying different things and forgot to add the one that was causing issue 🙈
good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can get rid of METRIC_CGROUP_MEMORY_LIMIT_BYTES
as it's already checking if it exists in this line https://github.com/elastic/kibana/pull/145348/files/41f4588a1e4a64e71e909d303d284cb8eaece403#diff-741ca25328532c18284b64412f95043bb968f82b1ca17fc64193317d41337460R75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpatticha can you reach out to the agents or server devs to figure out which fields are available in what scenarios? I'm hoping we can figure out something like "if METRIC_CGROUP_MEMORY_LIMIT_BYTES is available, then METRIC_CGROUP_MEMORY_USAGE_BYTES must be too, and if it's not available, we should use METRIC_SYSTEM_TOTAL_MEMORY, which is always available". Doesn't necessarily have to happen in this PR but I feel like with each change we understand how memory usage is recorded less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure I can try that, it will be really useful 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started gathering information on how system memory work here but it should not block this PR
Pinging @elastic/apm-ui (Team:APM) |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
x-pack/test/apm_api_integration/tests/service_overview/instances_main_statistics.spec.ts
Show resolved
Hide resolved
a84fcc0
to
87fa356
Compare
This number represents the max possible value for the limit field. | ||
*/ | ||
double CGROUP_LIMIT_MAX_VALUE = 9223372036854771712L; | ||
if(doc.containsKey('${METRIC_SYSTEM_TOTAL_MEMORY}') && doc.containsKey('${METRIC_CGROUP_MEMORY_USAGE_BYTES}')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is the way to go about it... will this not unnecessarily return null in some cases? In all honesty it's a little hard to wrap my head around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm putting the PR back to draft. I've noticed recent changes in memory I need to take into consideration. https://github.com/elastic/kibana/blob/main/x-pack/plugins/apm/server/routes/metrics/by_agent/shared/memory/index.ts#L134-L179
note for me Another case was reported when using APM dotnet agent. 8.7.2 is in 2 weeks |
@kpatticha Did you talk to the server/agent folks about this one? |
@sqren yes.
so generally there is no guarantee that any of the system metrics will be available |
774d47e
to
d8fe9df
Compare
Co-authored-by: Søren Louv-Jansen <[email protected]>
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @kpatticha |
Fixes the error ``` "script_stack": [ "[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues.throwIfEmpty(ScriptDocValues.java:92)", "[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:110)", "[email protected]/org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:105)", """total = useCgroupLimit ? doc[limitKey].value : doc['system.memory.total'].value; double """, " ^---- HERE" ``` connected elastic/sdh-apm#765 (internal) --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Søren Louv-Jansen <[email protected]> (cherry picked from commit 98165d2)
💔 Some backports could not be created
Note: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
# 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]>
export const systemMemoryFilter = { | ||
bool: { | ||
filter: [ | ||
{ exists: { field: METRIC_SYSTEM_FREE_MEMORY } }, | ||
{ exists: { field: METRIC_SYSTEM_TOTAL_MEMORY } }, | ||
], | ||
}, | ||
}; | ||
|
||
export const percentSystemMemoryUsedScript = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpatticha any reason for the difference in naming "systemMemoryFilter" and "percentSystemMemoryUsedScript"? What about "systemMemoryFilter" and "systemMemoryScript"?
Ideally I think they should be co-located in an object:
const systemMemory = {
filter: {...},
script: {...}
}
This will provide a strong signal that they belong together, and will make it less likely that somebody changing the code will make changes to the filter and not the script, and vice-versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sqren I can't remember any particular reason for the naming 🤔 .
As for the object, that's a really good point and I think we initially discussed doing it like that but somehow I missed it.
Let me fix it in a follow-up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const cgroupMemoryFilter = { | ||
bool: { | ||
filter: [{ exists: { field: METRIC_CGROUP_MEMORY_USAGE_BYTES } }], | ||
should: [ | ||
{ exists: { field: METRIC_CGROUP_MEMORY_LIMIT_BYTES } }, | ||
{ exists: { field: METRIC_SYSTEM_TOTAL_MEMORY } }, | ||
], | ||
minimum_should_match: 1, | ||
}, | ||
}; | ||
|
||
export const percentCgroupMemoryUsedScript = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above (naming)
Fixes the error
connected https://github.com/elastic/sdh-apm/issues/765 (internal)