ENT-6511: Increase cf-monitord measurement slots from 100 to 300#6239
ENT-6511: Increase cf-monitord measurement slots from 100 to 300#6239nickanderson wants to merge 2 commits into
Conversation
50d4f8a to
2fbdc3d
Compare
|
@cf-bottom jenkins please. |
|
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/14244/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14244/ |
1a91252 to
5f4e187
Compare
|
@cf-bottom jenkins please. |
|
Alright, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/14253/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14253/ |
| // Fall back to simple printing in release builds: | ||
| // Fall back to simple printing in release builds. Records written | ||
| // before CF_OBSERVABLES was raised are shorter, but a running agent | ||
| // migrates them (see dbm_migration_observations.c) before they are read. |
There was a problem hiding this comment.
Feels like this change does not belong here anymore
There was a problem hiding this comment.
Reverted to the original // Fall back to simple printing in release builds:.
| // Migration version scalar (dbm_migration_observations.c), a short | ||
| // string rather than an Averages struct. |
There was a problem hiding this comment.
I'm not sure I understand this comment
There was a problem hiding this comment.
Reworded. The migration stores a version bookkeeping key in these DBs; its value is a short version string, not an Averages struct, so it is printed as a string rather than falling through to print_struct_averages() (which would trip the struct-size assertion).
| @@ -0,0 +1,113 @@ | |||
| /* | |||
| Copyright 2024 Northern.tech AS | |||
There was a problem hiding this comment.
| Copyright 2024 Northern.tech AS | |
| Copyright 2026 Northern.tech AS |
| /* The ts_key has fewer entries than CF_OBSERVABLES -- e.g. it | ||
| * was written by an older agent with a smaller CF_OBSERVABLES. | ||
| * Fill the remaining names so the returned array keeps its | ||
| * documented non-NULL guarantee (callers index all | ||
| * CF_OBSERVABLES entries). */ | ||
| for (int j = i; j < CF_OBSERVABLES; ++j) | ||
| { | ||
| snprintf(buf, CF_MAXVARSIZE, "spare[%d]", j); | ||
| temp[j] = xstrdup(buf); | ||
| } |
There was a problem hiding this comment.
Is this still needed post migration fix ?
There was a problem hiding this comment.
Yes — this is about the ts_key text file, which the DB migration does not touch. GetObservableNames() is documented to return a CF_OBSERVABLES-sized array of non-NULL strings. A ts_key written by an older agent has only 100 lines, so after the bump fgets hits EOF at slot 100 and, without this fill, temp[100..299] stay uninitialized (xmalloc, not zeroed); the sole caller (dump.c:179) then indexes and free()s all 300 → uninitialized read + invalid free. So it is an independent correctness fix.
There was a problem hiding this comment.
And, just FYI, I have a follow-up PR waiting to changes the storage to only require what is used
| char cmd[CF_BUFSIZE]; | ||
| xsnprintf(cmd, CF_BUFSIZE, "rm -rf '%s'/*", GetStateDir()); | ||
| system(cmd); |
There was a problem hiding this comment.
I know, I know... Recursively deleting a directory is not as easy as one would think in C. However, there probably is a function you can use in libntech or libpromises so that you don't have to run a command.
There was a problem hiding this comment.
Although I get the argument that the unit tests should be as lightweight as possible. Either way is fine by me.
There was a problem hiding this comment.
Switched to DeleteDirectoryTree() from libntech (empties the tree, keeps the top dir), plus a trailing rmdir() in teardown.
| system(cmd); | ||
|
|
||
| DBHandle *db; | ||
| assert_int_equal(OpenDB(&db, dbid_observations), true); |
There was a problem hiding this comment.
Use assert_true instead of treating bool as an int, even though it really is. It will also give more descriptive error messages.
| assert_int_equal(OpenDB(&db, dbid_observations), true); | |
| assert_true(OpenDB(&db, dbid_observations)); |
There was a problem hiding this comment.
Done — converted the bool-returning assertions (OpenDB/WriteDB/ReadDB/HasKeyDB/NewDBCursor/DeleteDBCursor) to assert_true.
|
|
||
| /* STUBS */ | ||
|
|
||
| void FatalError(ARG_UNUSED char *s, ...) |
There was a problem hiding this comment.
Please add a comment explaining why this STUB is here
There was a problem hiding this comment.
Added a comment: OpenDB() pulls in libpromises DB code that references FatalError(), whose real implementation lives in the daemons, not the test binary — so the stub is there to let the test link, and reaching it is itself a failure.
5f4e187 to
fa550dd
Compare
~80 of the 100 slots are consumed by default measurements, leaving little room for custom ones. Raise the limit to 300. Kept in sync: CF_OBSERVABLES and the two cf-check copies of the on-disk struct, plus the OBSERVABLES name table (GetObservable() indexes it for unregistered slots, so a short table crashes cf-monitord). cf-check also pads a pre-upgrade ts_key that has fewer entries than CF_OBSERVABLES. Ticket: ENT-6511 Changelog: Increased the maximum number of cf-monitord measurement slots (CF_OBSERVABLES) from 100 to 300
Raising CF_OBSERVABLES enlarges the fixed-size Averages record, so records written by an older agent are shorter than the current struct. Added a migration (modelled on dbm_migration_lastseen.c) that rewrites old records to the current size, zero-filling the new slots, registered for the observations and history DBs. cf-check dump only needs to recognise the new "version" key the migration writes. Ticket: ENT-6511 Changelog: None
fa550dd to
d278e7e
Compare
| if (structs) | ||
| { | ||
| if (StringContains(file, "cf_lastseen.lmdb") | ||
| if ((StringContains(file, "cf_observations.lmdb") |
There was a problem hiding this comment.
Pre-existing. But, should probably be StringEndsWith()? Could be a follow-up commit.
There was a problem hiding this comment.
in this PR or completely separately?
There was a problem hiding this comment.
Up to you. I'm OK with leaving it as is as well
There was a problem hiding this comment.
I think I will leave it for now. Seems to have been intentionally changed from StringsEndsWith to StringContains 3e98366c3
|
@cf-bottom Jenkins please :) |
|
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/14272/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14272/ |
Raises
CF_OBSERVABLESfrom 100 to 300. Previously out of the box ~80 of the 100 slots are consumed by default measurements, leaving only ~19 for custommeasurements:promises.Notably, this change does increase the disk footprint required by an agent by
60MB (.27MB per slot). That storage is required even if the slots are not in active use (Ref: ENT-14329)Ticket: ENT-6511