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
[metricbeat] Add memory.stat data to the docker/memory metricset #12916
[metricbeat] Add memory.stat data to the docker/memory metricset #12916
Conversation
Bah, broken test. Working on it. |
One thing I noticed while fixing the tests is that I'm passing the object to |
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.
This is looking good, will need a changelog
Was gonna leave off the changelog until we were otherwise ready to merge. |
@@ -79,6 +79,9 @@ func TestMemoryService_GetMemoryStats(t *testing.T) { | |||
}, | |||
} | |||
expectedFields := common.MapStr{ | |||
"stats": map[string]uint64{ | |||
"total_rss": 5, |
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.
Maybe, according to the naming conventions, this field should be called rss.count
https://www.elastic.co/guide/en/beats/devguide/current/event-conventions.html
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.
How much do we want to fiddle with the stuff being scraped from the kernel interface? The full list of total_*
events is generated programmatically by the kernel.
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.
Like, this is what's happening in the kernel:
for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
(u64)memcg_events(memcg, i));
for (i = 0; i < NR_LRU_LISTS; i++)
seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
(u64)memcg_page_state(memcg, NR_LRU_BASE + i) *
PAGE_SIZE);
Seems like a potential lost cause to figure out what possible fields we would need to re-parse?
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.
having that Docker doesn't document these fields and is just passing them in raw I think that we could fail if we try to convert them. Could you update data.json
? we should see how this looks by default there.
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.
Just another opinion. I think that for this case it'd be fine to copy the stats map, as they are values taken directly from the OS, and I don't think they are going to change a lot. Also they seem to follow a good enough format (lowercase, snake case...).
But it is true that we risk to have fields explosion or other problems if some fancy feature is merged into the kernel.
Some things that we could do to improve this:
- Apply an schema to these memory stats, so we control what variables we collect, and potentially we adapt them to some other schema as Mario proposed (although I am fine with keeping the naming given by docker/OS)
- Explicitly document the fields we know (even if we leave the wildcard to catch new fields)
And +1 to have a data.json
to have a better view of how it looks. It could be also nice to try it on Windows, to see if it has its own set of variables.
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.
Apply an schema to these memory stats
I initially thought of that, but schema.Apply seemed a bit like overkill considering everything is already a uint64
. Should we just not use the type conversion part of it?
Explicitly document the fields we know (even if we leave the wildcard to catch new fields)
How would that work? Is there some way to document this besides fields.yml
?
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.
passing this in raw sounds reasonable enough, worst case scenario at some point we discover this generates too much data, which seems unlikely anyway.
Updating data.json
will help to give a good example of what to expect there
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.
Explicitly document the fields we know (even if we leave the wildcard to catch new fields)
How would that work? Is there some way to document this besides
fields.yml
?
Yeah, I mean to add to fields.yml
the fields we know, but as they look like quite low level metrics, I am ok too with documenting the docker.memory.stats
group only.
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.
Yah, the fact that they're so low level but also consistently typed makes me not too worried about them. I don't think there's any downside to the wildcard yml entry from the perspective of mapping, is there?
For discussion only, I'm not a fan of |
Copying what we talked about on slack--there doesn't seem to be a pretty way to convert the values of the map without iterating over everything, which doesn't seem worth it in this case? I'm not set on it, though. |
Alright, updated |
thank you! this looks good to me, aside from the changelog |
a56aee0
to
f98f686
Compare
f98f686
to
7922e08
Compare
Alright @exekias Changelog added! |
Original issue here: #12855. This is an enhancement request from cloud that I figured could be fairly low-hanging so I'd like to get it out of the way.
I wasn't entirely sure how to implement this, and I chatted with a few folks about it, but I figured the best way to do it was to just put in a PR and we can debate about it here.
So, the issue is that the docker API returns a
map[string]uint64
, and the data itself is just scraped from the cgroupmemory.stat
interface, which is just in the kernel. The interface doesn't seem to be particularly well-documented, and there's a handful of ifdef statements and programmatic logic determining what is printed. The way I did it now is the simplest, with astat.*
type in fields.yml, and just passing the map into the MapStr object.A few other ideas:
schema.Apply
. This seems to be a bit of a heavy hammer, as we have a setuint64
type and don't need to do much processing to the data itselfstat.*
in favor of more explicit mapping.