Skip to content
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

[ML] Init AD model config from JSON config #1602

Merged
merged 3 commits into from
Dec 3, 2020

Conversation

edsavage
Copy link
Contributor

@edsavage edsavage commented Dec 1, 2020

Initialise CAnomalyDetectorModelConfig with values from
the JSON config file parsed by CAnomalyJobConfig.

Relates to #1253

Initialise CAnomalyDetectorModelConfig with values from
the JSON config file parsed by CAnomalyJobConfig.

Relates to elastic#1253
Keep the Java REST integration tests happy by ensuring that the
detector rules are correctly updated with changes to the
filter configuration.
Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I saw a few very minor things, but am happy to merge without further review if you could fix those.

Comment on lines +212 to +222
const std::string& summaryCountFieldName = analysisConfig.summaryCountFieldName();
ml::core_t::TTime bucketSpan = analysisConfig.bucketSpan();
ml::core_t::TTime latency = analysisConfig.latency();
bool multivariateByFields = analysisConfig.multivariateByFields();

ml::model_t::ESummaryMode summaryMode{
summaryCountFieldName.empty() ? ml::model_t::E_None : ml::model_t::E_Manual};
ml::model::CAnomalyDetectorModelConfig modelConfig{ml::model::CAnomalyDetectorModelConfig::defaultConfig(
bucketSpan, summaryMode, summaryCountFieldName, latency, multivariateByFields)};
modelConfig.detectionRules(ml::model::CAnomalyDetectorModelConfig::TIntDetectionRuleVecUMapCRef(
fieldConfig.detectionRules()));
analysisConfig.detectionRules()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long term this could be encapsulated in a method of CAnomalyJobConfig, say CAnomalyJobConfig::makeModelConfig(). But since you're doing a series of PRs you can save this for the next one.

@@ -424,6 +426,10 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
//! Object to which the output is passed
CJsonOutputWriter m_JsonOutputWriter;

//! Configuration settings for the analysis parsed from
//! JSON configuration file.
Copy link
Contributor

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 say why this is non-const. It's because it gets updated by job updates right? And of course since it's a reference that will also affect everywhere else that has a reference.

@@ -68,7 +67,7 @@ class API_EXPORT CAnomalyJobConfig {
std::string m_PartitionFieldName{};
std::string m_ExcludeFrequent{};
std::string m_DetectorDescription{};
CDetectionRulesJsonParser::TDetectionRuleVec m_CustomRules{};
std::size_t m_DetectorIndex{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although probably not the best choice originally, detector index is an int everywhere else, so it's best if it's an int here too. (I think originally it was some generic "identifier" instead of an array index, and -1 indicated "unknown". That's so far in the past that -1 never exists now, but it's still probably best to keep the types consistent across the codebase.)

@@ -234,7 +257,7 @@ class API_EXPORT CAnomalyJobConfig {

std::string jobId() const { return m_JobId; }
std::string jobType() const { return m_JobType; }
const CAnalysisConfig& analysisConfig() const { return m_AnalysisConfig; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could provide both const and non-const accessors. In future as this class gets used more widely some places may hold a const reference to the CAnomalyJobConfig, and it's annoying for those places to have to cast away constness just to get a const reference to one of the sub-objects.

@edsavage edsavage merged commit 4e0eaa0 into elastic:master Dec 3, 2020
edsavage added a commit to edsavage/ml-cpp that referenced this pull request Dec 3, 2020
Initialise CAnomalyDetectorModelConfig with values from
the JSON config file parsed by CAnomalyJobConfig.

Relates to elastic#1253
edsavage added a commit that referenced this pull request Dec 3, 2020
Initialise CAnomalyDetectorModelConfig with values from
the JSON config file parsed by CAnomalyJobConfig.

Relates to #1253
Backports #1602
@edsavage edsavage deleted the anomaly_job_config_model_config branch December 3, 2020 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants