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
Report model change annotations via result stream #1247
Conversation
b67cf88
to
c7b4443
Compare
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.
The memory of m_CurrentBucketStats.s_Annotations
needs to be accounted for. So everywhere where we have this:
bash-3.2$ grep 'mem += core::CMemory::dynamicSize(m_CurrentBucketStats.s_InterimCorrections);' *
CEventRateModel.cc: mem += core::CMemory::dynamicSize(m_CurrentBucketStats.s_InterimCorrections);
CEventRatePopulationModel.cc: mem += core::CMemory::dynamicSize(m_CurrentBucketStats.s_InterimCorrections);
CMetricModel.cc: mem += core::CMemory::dynamicSize(m_CurrentBucketStats.s_InterimCorrections);
CMetricPopulationModel.cc: mem += core::CMemory::dynamicSize(m_CurrentBucketStats.s_InterimCorrections);
and this:
bash-3.2$ grep 'core::CMemoryDebug::dynamicSize("m_CurrentBucketStats.s_InterimCorrections",' *
CEventRateModel.cc: core::CMemoryDebug::dynamicSize("m_CurrentBucketStats.s_InterimCorrections",
CEventRatePopulationModel.cc: core::CMemoryDebug::dynamicSize("m_CurrentBucketStats.s_InterimCorrections",
CMetricModel.cc: core::CMemoryDebug::dynamicSize("m_CurrentBucketStats.s_InterimCorrections",
CMetricPopulationModel.cc: core::CMemoryDebug::dynamicSize("m_CurrentBucketStats.s_InterimCorrections",
we need equivalent lines for m_CurrentBucketStats.s_Annotations
.
TODO1: when to clear s_Annotations vector?
Am I correct that at the moment it's never cleared?
One option might be to have a method that allows the annotations to be taken instead of got as a const reference. Then after outputting what's been built up they are all gone - no danger of outputting duplicates and no memory build up as long as the output method is called reasonably frequently.
For example:
CEventRateModel::TAnnotationVec CEventRateModel::takeAnnotations() {
CEventRateModel::TAnnotationVec result;
result.swap(m_CurrentBucketStats.s_Annotations);
return result;
}
Maybe Tom has a better idea though.
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've done a first pass through. I've made a few suggestions. Aside from defaulting the add annotation callback better, my biggest suggested change is to rejig where the annotations for new decomposition components are written. Also, this should be capturing when a trend is detected and when calendar components are detected. It is probably easiest to discuss this offline.
@@ -113,6 +114,7 @@ const core_t::TTime HOUR = core::constants::HOUR; | |||
const core_t::TTime DAY = core::constants::DAY; | |||
const core_t::TTime WEEK = core::constants::WEEK; | |||
const core_t::TTime YEAR = core::constants::YEAR; | |||
const ml::maths::CModelAddSamplesParams::TModelChangeCallback NOOP; |
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.
It would be good to test, in at least one test, that the annotations are actually created.
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 should I go about the unit testing in this case? Should I call addPoint
method with a model annotation callback and verify it got called?
Could you point me at the test case which I can take as a base?
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 PR needs a changelog entry to make the changelog PR check succeed.
Done.
Done.
I've added clearing in the beginning of the IIUC this solution is equivalent to the one you outlined (using swap). |
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.
Thanks @przemekwitek! This looks really close. I have some suggestions on naming: the current choices I think are easy to confuse with change point detection. Other than that I think this looks ready.
8efbafe
to
f8466d1
Compare
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.
Good stuff @przemekwitek. Thanks for iterating on this! LGTM.
e714d65
to
4328be7
Compare
This PR makes model change annotations reported via result stream.
It is achieved the following way:
maths
module report model changes viaTModelChangeCallback
functional typeTModelChangeCallback
creates aCAnnotation
object and puts it into in-memory collectionm_CurrentBucketStats.s_Annotations
s_Annotations
are collected byCAnomalyJob
and written out to the stream usingCAnnotationJsonWriter
classRelates elastic/elasticsearch#55781