Skip to content

Commit 16c75c3

Browse files
authored
[ML] Update C++ standard to 20 and refine clang-tidy checks (elastic#2777)
Upgrade the C++ standard to version 20 and refine clang-tidy checks by removing unnecessary warnings and adjusting configurations for better code quality.
1 parent 6a95501 commit 16c75c3

File tree

7 files changed

+207
-176
lines changed

7 files changed

+207
-176
lines changed

.buildkite/pipelines/sonarqube.yml.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ steps:
1515
soft_fail: true
1616
agents:
1717
cpu: 6
18-
ephemeralStorage: "20G"
19-
memory: "8G"
18+
ephemeralStorage: "40G"
19+
memory: "12G"
2020
image: "docker.elastic.co/ml-dev/ml-linux-build:33"
2121
env:
2222
PATH: "/usr/local/gcc133/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

.clang-tidy

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,31 @@ Checks: >
88
99
clang-diagnostic-*,
1010
-clang-diagnostic-sign-conversion,
11+
-clang-diagnostic-unused-macros,
1112
1213
google-*,
1314
-google-build-using-namespace,
1415
-google-readability-namespace-comments,
1516
-google-runtime-references,
17+
1618
misc-*,
19+
-misc-non-private-member-variables-in-classes,
20+
-misc-include-cleaner,
1721
1822
modernize-*,
1923
-modernize-use-trailing-return-type,
2024
-modernize-concat-nested-namespaces,
2125
-modernize-use-nodiscard,
22-
-modernize-replace-random-shuffle,
23-
-modernize-unary-static-assert,
24-
-modernize-use-uncaught-exception,
2526
2627
performance-*,
2728
2829
readability-*,
2930
-readability-magic-numbers,
30-
-readability-named-parameter,
3131
-readability-redundant-access-specifiers,
3232
-readability-simplify-boolean-expr,
3333
-readability-identifier-length,
3434
3535
WarningsAsErrors: false
36-
AnalyzeTemporaryDtors: false
3736
FormatStyle: file
3837
CheckOptions:
3938
- key: bugprone-assert-side-effect.AssertMacros
@@ -61,4 +60,6 @@ CheckOptions:
6160
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
6261
value: 'true'
6362
- key: readability-function-cognitive-complexity.IgnoreMacros
64-
value: 'true'
63+
value: 'true'
64+
- key: modernize-include.UseAngleBrackets
65+
value: true

cmake/variables.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111

1212
# set the C++ standard we need to enforce
13-
set (CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard to use")
13+
set (CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
1414
set (CMAKE_CXX_STANDARD_REQUIRED ON)
1515
set (CMAKE_CXX_EXTENSIONS OFF)
1616

include/api/CAnomalyJob.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
126126
struct SBackgroundPersistArgs {
127127
SBackgroundPersistArgs(core_t::TTime time,
128128
const model::CResourceMonitor::SModelSizeStats& modelSizeStats,
129-
const model::CInterimBucketCorrector& interimBucketCorrector,
129+
model::CInterimBucketCorrector interimBucketCorrector,
130130
const model::CHierarchicalResultsAggregator& aggregator,
131131
core_t::TTime latestRecordTime,
132132
core_t::TTime lastResultsTime,
@@ -146,12 +146,12 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
146146
using TBackgroundPersistArgsPtr = std::shared_ptr<SBackgroundPersistArgs>;
147147

148148
public:
149-
CAnomalyJob(const std::string& jobId,
149+
CAnomalyJob(std::string jobId,
150150
model::CLimits& limits,
151151
CAnomalyJobConfig& jobConfig,
152152
model::CAnomalyDetectorModelConfig& modelConfig,
153153
core::CJsonOutputStreamWrapper& outputBuffer,
154-
const TPersistCompleteFunc& persistCompleteFunc,
154+
TPersistCompleteFunc persistCompleteFunc,
155155
CPersistenceManager* persistenceManager,
156156
core_t::TTime maxQuantileInterval,
157157
const std::string& timeFieldName,
@@ -265,7 +265,8 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
265265

266266
//! This is the function that is called in a different thread to the
267267
//! main processing when background persistence is triggered.
268-
bool runBackgroundPersist(TBackgroundPersistArgsPtr args, core::CDataAdder& persister);
268+
bool runBackgroundPersist(const TBackgroundPersistArgsPtr& args,
269+
core::CDataAdder& persister);
269270

270271
//! This function is called from the persistence manager when foreground persistence is triggered
271272
bool runForegroundPersist(core::CDataAdder& persister);
@@ -331,9 +332,9 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
331332

332333
//! Parses the time range in a control message assuming the time range follows after a
333334
//! single character code (e.g. starts with 'i10 20').
334-
bool parseTimeRangeInControlMessage(const std::string& controlMessage,
335-
core_t::TTime& start,
336-
core_t::TTime& end);
335+
static bool parseTimeRangeInControlMessage(const std::string& controlMessage,
336+
core_t::TTime& start,
337+
core_t::TTime& end);
337338

338339
//! Update equalizers if not interim and aggregate.
339340
void updateAggregatorAndAggregate(bool isInterim, model::CHierarchicalResults& results);
@@ -375,24 +376,25 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
375376
//! Update configuration
376377
void doForecast(const std::string& controlMessage);
377378

378-
TAnomalyDetectorPtr
379+
static TAnomalyDetectorPtr
379380
makeDetector(const model::CAnomalyDetectorModelConfig& modelConfig,
380381
model::CLimits& limits,
381382
const std::string& partitionFieldValue,
382383
core_t::TTime firstTime,
383384
const model::CAnomalyDetector::TModelFactoryCPtr& modelFactory);
384385

385386
//! Populate detector keys from the anomaly job config.
386-
void populateDetectorKeys(const CAnomalyJobConfig& jobConfig, TKeyVec& keys);
387+
static void populateDetectorKeys(const CAnomalyJobConfig& jobConfig, TKeyVec& keys);
387388

388389
//! Extract the field called \p fieldName from \p dataRowFields.
389-
const std::string* fieldValue(const std::string& fieldName, const TStrStrUMap& dataRowFields);
390+
static const std::string* fieldValue(const std::string& fieldName,
391+
const TStrStrUMap& dataRowFields);
390392

391393
//! Extract the required fields from \p dataRowFields
392394
//! and add the new record to \p detector
393-
void addRecord(const TAnomalyDetectorPtr detector,
394-
core_t::TTime time,
395-
const TStrStrUMap& dataRowFields);
395+
static void addRecord(const TAnomalyDetectorPtr& detector,
396+
core_t::TTime time,
397+
const TStrStrUMap& dataRowFields);
396398

397399
//! Parses a control message requesting that model state be persisted.
398400
//! Extracts optional arguments to be used for persistence.
@@ -420,12 +422,12 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
420422
core_t::TTime time,
421423
const model::CSearchKey& key,
422424
const std::string& partitionFieldValue,
423-
model::CResourceMonitor& resourceMonitor);
425+
const model::CResourceMonitor& resourceMonitor);
424426

425427
//! Prune all the models that exceed \p buckets in age
426428
//! A value of 0 for \buckets indicates that only 'obsolete' models will
427429
//! be pruned, i.e. those which are so old as to be effectively dead.
428-
void pruneAllModels(std::size_t buckets = 0);
430+
void pruneAllModels(std::size_t buckets = 0) const;
429431

430432
private:
431433
//! The job ID
@@ -454,7 +456,7 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
454456
model::CAnomalyDetectorModelConfig& m_ModelConfig;
455457

456458
//! Keep count of how many records we've handled
457-
std::uint64_t m_NumRecordsHandled;
459+
std::uint64_t m_NumRecordsHandled = 0;
458460

459461
//! Detector keys.
460462
TKeyVec m_DetectorKeys;
@@ -463,7 +465,7 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
463465
TKeyAnomalyDetectorPtrUMap m_Detectors;
464466

465467
//! The end time of the last bucket out of latency window we've seen
466-
core_t::TTime m_LastFinalisedBucketEndTime;
468+
core_t::TTime m_LastFinalisedBucketEndTime = 0;
467469

468470
//! Optional function to be called when persistence is complete
469471
TPersistCompleteFunc m_PersistCompleteFunc;
@@ -486,10 +488,10 @@ class API_EXPORT CAnomalyJob : public CDataProcessor {
486488
core_t::TTime m_LastNormalizerPersistTime;
487489

488490
//! Latest record time seen.
489-
core_t::TTime m_LatestRecordTime;
491+
core_t::TTime m_LatestRecordTime = 0;
490492

491493
//! Last time we sent a finalised result to the API.
492-
core_t::TTime m_LastResultsTime;
494+
core_t::TTime m_LastResultsTime = 0;
493495

494496
//! When the model state was restored was it entirely successful.
495497
//! Extra information about any errors that may have occurred

0 commit comments

Comments
 (0)