diff options
| author | danibw <[email protected]> | 2022-02-10 16:50:12 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:50:12 +0300 | 
| commit | 4b28e15652a7672062edb6804bc985eedc333257 (patch) | |
| tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp | |
| parent | e8fdd1e6c0645bf1702aaf85cc7460dbd09977cb (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/logger/rotating_file.cpp | 64 | ||||
| -rw-r--r-- | library/cpp/logger/rotating_file.h | 2 | ||||
| -rw-r--r-- | library/cpp/logger/rotating_file_ut.cpp | 68 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/atomics_array.h | 12 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/histogram_collector.h | 10 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/histogram_collector_explicit.cpp | 8 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/histogram_collector_exponential.cpp | 8 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/histogram_collector_linear.cpp | 8 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/metric.h | 4 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/metric_registry.cpp | 56 | ||||
| -rw-r--r-- | library/cpp/monlib/metrics/metric_registry.h | 4 | 
11 files changed, 122 insertions, 122 deletions
diff --git a/library/cpp/logger/rotating_file.cpp b/library/cpp/logger/rotating_file.cpp index 3391d260025..a62f48f25db 100644 --- a/library/cpp/logger/rotating_file.cpp +++ b/library/cpp/logger/rotating_file.cpp @@ -2,7 +2,7 @@  #include "file.h"  #include "record.h" -#include <util/string/builder.h>  +#include <util/string/builder.h>  #include <util/system/fstat.h>  #include <util/system/rwlock.h>  #include <util/system/fs.h> @@ -11,36 +11,36 @@  /*   * rotating file log - * if Size_ > MaxSizeBytes  - *    Path.(N-1) -> Path.N  - *    Path.(N-2) -> Path.(N-1)  - *    ...  - *    Path.1     -> Path.2  - *    Path       -> Path.1  + * if Size_ > MaxSizeBytes + *    Path.(N-1) -> Path.N + *    Path.(N-2) -> Path.(N-1) + *    ... + *    Path.1     -> Path.2 + *    Path       -> Path.1   */  class TRotatingFileLogBackend::TImpl {  public: -    inline TImpl(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount)  -        : Log_(path)  -        , Path_(path)  -        , MaxSizeBytes_(maxSizeBytes)  -        , Size_(TFileStat(Path_).Size)  -        , RotatedFilesCount_(rotatedFilesCount)  -    {  -        Y_ENSURE(RotatedFilesCount_ != 0);  -    }  -  +    inline TImpl(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount) +        : Log_(path) +        , Path_(path) +        , MaxSizeBytes_(maxSizeBytes) +        , Size_(TFileStat(Path_).Size) +        , RotatedFilesCount_(rotatedFilesCount) +    { +        Y_ENSURE(RotatedFilesCount_ != 0); +    } +      inline void WriteData(const TLogRecord& rec) {          if (static_cast<ui64>(AtomicGet(Size_)) > MaxSizeBytes_) {              TWriteGuard guard(Lock_);              if (static_cast<ui64>(AtomicGet(Size_)) > MaxSizeBytes_) { -                TString newLogPath(TStringBuilder{} << Path_ << "." << RotatedFilesCount_);  -                for (size_t fileId = RotatedFilesCount_ - 1; fileId; --fileId) {  -                    TString oldLogPath(TStringBuilder{} << Path_ << "." << fileId);  -                    NFs::Rename(oldLogPath, newLogPath);  -                    newLogPath = oldLogPath;  -                }  -                NFs::Rename(Path_, newLogPath);  +                TString newLogPath(TStringBuilder{} << Path_ << "." << RotatedFilesCount_); +                for (size_t fileId = RotatedFilesCount_ - 1; fileId; --fileId) { +                    TString oldLogPath(TStringBuilder{} << Path_ << "." << fileId); +                    NFs::Rename(oldLogPath, newLogPath); +                    newLogPath = oldLogPath; +                } +                NFs::Rename(Path_, newLogPath);                  Log_.ReopenLog();                  AtomicSet(Size_, 0);              } @@ -54,23 +54,23 @@ public:          TWriteGuard guard(Lock_);          Log_.ReopenLog(); -        AtomicSet(Size_, TFileStat(Path_).Size);  +        AtomicSet(Size_, TFileStat(Path_).Size);      }  private:      TRWMutex Lock_;      TFileLogBackend Log_; -    const TString Path_;  +    const TString Path_;      const ui64 MaxSizeBytes_;      TAtomic Size_; -    const ui32 RotatedFilesCount_;  +    const ui32 RotatedFilesCount_;  }; -TRotatingFileLogBackend::TRotatingFileLogBackend(const TString& path, const ui64 maxSizeByte, const ui32 rotatedFilesCount)  -    : Impl_(new TImpl(path, maxSizeByte, rotatedFilesCount))  -{  -}  -  +TRotatingFileLogBackend::TRotatingFileLogBackend(const TString& path, const ui64 maxSizeByte, const ui32 rotatedFilesCount) +    : Impl_(new TImpl(path, maxSizeByte, rotatedFilesCount)) +{ +} +  TRotatingFileLogBackend::~TRotatingFileLogBackend() {  } diff --git a/library/cpp/logger/rotating_file.h b/library/cpp/logger/rotating_file.h index 8f5f834fbbc..cb047f25fbd 100644 --- a/library/cpp/logger/rotating_file.h +++ b/library/cpp/logger/rotating_file.h @@ -8,7 +8,7 @@  class TRotatingFileLogBackend: public TLogBackend {  public:      TRotatingFileLogBackend(const TString& preRotatePath, const TString& postRotatePath, const ui64 maxSizeBytes); -    TRotatingFileLogBackend(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount);  +    TRotatingFileLogBackend(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount);      ~TRotatingFileLogBackend() override;      void WriteData(const TLogRecord& rec) override; diff --git a/library/cpp/logger/rotating_file_ut.cpp b/library/cpp/logger/rotating_file_ut.cpp index 6cfa41da803..84966933d96 100644 --- a/library/cpp/logger/rotating_file_ut.cpp +++ b/library/cpp/logger/rotating_file_ut.cpp @@ -8,38 +8,38 @@  #include <library/cpp/testing/unittest/registar.h>  #include <library/cpp/testing/unittest/tests_data.h> -Y_UNIT_TEST_SUITE(NewRotatingFileSuite) {  -    const TString PATH = GetWorkPath() + "/my.log";  -  -    Y_UNIT_TEST(TestFileWrite) {  -        TRotatingFileLogBackend log(PATH, 4000, 2);  -        TString data = "my data";  -        log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));  -        UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");  -    }  -  -    Y_UNIT_TEST(TestFileRotate) {  -        const ui64 maxSize = 40;  -        TRotatingFileLogBackend log(PATH, maxSize, 2);  -        TStringBuilder data;  -        for (size_t i = 0; i < 10; ++i)  -            data << "data\n";  -        log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));  -        UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");  -        data.clear();  -        data << "more data";  -        log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));  -        UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");  -        UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".1").Size > 0, "file " << PATH << ".1 has zero size");  -        UNIT_ASSERT_C(TFileStat(PATH).Size < maxSize, "size of file " << PATH << " is greater than the size limit of " << maxSize << " bytes");  -    }  -  -    Y_UNIT_TEST(TestDoubleFileRotate) {  -        const ui64 maxSize = 40;  -        TRotatingFileLogBackend log(PATH, maxSize, 2);  -        TStringBuilder data;  -        for (size_t i = 0; i < 10; ++i)  -            data << "data\n";  +Y_UNIT_TEST_SUITE(NewRotatingFileSuite) { +    const TString PATH = GetWorkPath() + "/my.log"; + +    Y_UNIT_TEST(TestFileWrite) { +        TRotatingFileLogBackend log(PATH, 4000, 2); +        TString data = "my data"; +        log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size())); +        UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size"); +    } + +    Y_UNIT_TEST(TestFileRotate) { +        const ui64 maxSize = 40; +        TRotatingFileLogBackend log(PATH, maxSize, 2); +        TStringBuilder data; +        for (size_t i = 0; i < 10; ++i) +            data << "data\n"; +        log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size())); +        UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size"); +        data.clear(); +        data << "more data"; +        log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size())); +        UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size"); +        UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".1").Size > 0, "file " << PATH << ".1 has zero size"); +        UNIT_ASSERT_C(TFileStat(PATH).Size < maxSize, "size of file " << PATH << " is greater than the size limit of " << maxSize << " bytes"); +    } + +    Y_UNIT_TEST(TestDoubleFileRotate) { +        const ui64 maxSize = 40; +        TRotatingFileLogBackend log(PATH, maxSize, 2); +        TStringBuilder data; +        for (size_t i = 0; i < 10; ++i) +            data << "data\n";          log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));          UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");          log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size())); @@ -53,5 +53,5 @@ Y_UNIT_TEST_SUITE(NewRotatingFileSuite) {          UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".1").Size > 0, "file " << PATH << ".1 has zero size");          UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".2").Size > 0, "file " << PATH << ".2 has zero size");          UNIT_ASSERT_C(TFileStat(PATH).Size < maxSize, "size of file " << PATH << " is greater than the size limit of " << maxSize << " bytes"); -    }  -}  +    } +} diff --git a/library/cpp/monlib/metrics/atomics_array.h b/library/cpp/monlib/metrics/atomics_array.h index e044f14b00f..f19aebf2915 100644 --- a/library/cpp/monlib/metrics/atomics_array.h +++ b/library/cpp/monlib/metrics/atomics_array.h @@ -31,12 +31,12 @@ namespace NMonitoring {              Values_[index].fetch_add(count, std::memory_order_relaxed);          } -        void Reset() noexcept {  -            for (size_t i = 0; i < Size_; i++) {  -                Values_[i].store(0, std::memory_order_relaxed);  -            }  -        }  -  +        void Reset() noexcept { +            for (size_t i = 0; i < Size_; i++) { +                Values_[i].store(0, std::memory_order_relaxed); +            } +        } +          TVector<ui64> Copy() const {              TVector<ui64> copy(Reserve(Size_));              for (size_t i = 0; i < Size_; i++) { diff --git a/library/cpp/monlib/metrics/histogram_collector.h b/library/cpp/monlib/metrics/histogram_collector.h index 5afbf63c8e9..9f6bbbdfb73 100644 --- a/library/cpp/monlib/metrics/histogram_collector.h +++ b/library/cpp/monlib/metrics/histogram_collector.h @@ -33,11 +33,11 @@ namespace NMonitoring {          }          /** -         * Reset collector values  -         */  -        virtual void Reset() = 0;  -  -        /**  +         * Reset collector values +         */ +        virtual void Reset() = 0; + +        /**           * @return snapshot of the state of this collector.           */          virtual IHistogramSnapshotPtr Snapshot() const = 0; diff --git a/library/cpp/monlib/metrics/histogram_collector_explicit.cpp b/library/cpp/monlib/metrics/histogram_collector_explicit.cpp index 7684468a2d5..377fc233eff 100644 --- a/library/cpp/monlib/metrics/histogram_collector_explicit.cpp +++ b/library/cpp/monlib/metrics/histogram_collector_explicit.cpp @@ -27,10 +27,10 @@ namespace NMonitoring {              Values_.Add(index, count);          } -        void Reset() override {  -            Values_.Reset();  -        }  -  +        void Reset() override { +            Values_.Reset(); +        } +          IHistogramSnapshotPtr Snapshot() const override {              auto values = Values_.Copy();              return ExplicitHistogramSnapshot(Bounds_, values); diff --git a/library/cpp/monlib/metrics/histogram_collector_exponential.cpp b/library/cpp/monlib/metrics/histogram_collector_exponential.cpp index e4dc327dffe..2f8a50a5f9d 100644 --- a/library/cpp/monlib/metrics/histogram_collector_exponential.cpp +++ b/library/cpp/monlib/metrics/histogram_collector_exponential.cpp @@ -35,10 +35,10 @@ namespace NMonitoring {              Values_.Add(index, count);          } -        void Reset() override {  -            Values_.Reset();  -        }  -  +        void Reset() override { +            Values_.Reset(); +        } +          IHistogramSnapshotPtr Snapshot() const override {              return new TExponentialHistogramSnapshot(Base_, Scale_, Values_.Copy());          } diff --git a/library/cpp/monlib/metrics/histogram_collector_linear.cpp b/library/cpp/monlib/metrics/histogram_collector_linear.cpp index 8cd6aafcb7f..f8ad86f3a48 100644 --- a/library/cpp/monlib/metrics/histogram_collector_linear.cpp +++ b/library/cpp/monlib/metrics/histogram_collector_linear.cpp @@ -36,10 +36,10 @@ namespace NMonitoring {              Values_.Add(index, count);          } -        void Reset() override {  -            Values_.Reset();  -        }  -  +        void Reset() override { +            Values_.Reset(); +        } +          IHistogramSnapshotPtr Snapshot() const override {              return new TLinearHistogramSnapshot(                      StartValue_, BucketWidth_, Values_.Copy()); diff --git a/library/cpp/monlib/metrics/metric.h b/library/cpp/monlib/metrics/metric.h index 725d4feceff..b8ce12d7533 100644 --- a/library/cpp/monlib/metrics/metric.h +++ b/library/cpp/monlib/metrics/metric.h @@ -379,8 +379,8 @@ namespace NMonitoring {          }          void Reset() override { -            Collector_->Reset();  -        }  +            Collector_->Reset(); +        }      private:          IHistogramCollectorPtr Collector_; diff --git a/library/cpp/monlib/metrics/metric_registry.cpp b/library/cpp/monlib/metrics/metric_registry.cpp index d1bb063aab4..b083163a7b2 100644 --- a/library/cpp/monlib/metrics/metric_registry.cpp +++ b/library/cpp/monlib/metrics/metric_registry.cpp @@ -124,34 +124,34 @@ namespace NMonitoring {          return Metric<THistogram, EMetricType::HIST_RATE>(std::move(labels), std::move(collector), true);      } -    void TMetricRegistry::Reset() {  -        TWriteGuard g{Lock_};  -        for (auto& [label, metric] : Metrics_) {  -            switch (metric->Type()) {  -            case EMetricType::GAUGE:  -                static_cast<TGauge*>(metric.Get())->Set(.0);  -                break;  -            case EMetricType::IGAUGE:  -                static_cast<TIntGauge*>(metric.Get())->Set(0);  -                break;  -            case EMetricType::COUNTER:  -                static_cast<TCounter*>(metric.Get())->Reset();  -                break;  -            case EMetricType::RATE:  -                static_cast<TRate*>(metric.Get())->Reset();  -                break;  -            case EMetricType::HIST:  -            case EMetricType::HIST_RATE:  -                static_cast<THistogram*>(metric.Get())->Reset();  -                break;  -            case EMetricType::UNKNOWN:  -            case EMetricType::DSUMMARY:  -            case EMetricType::LOGHIST:  -                break;  -            }  -        }  -    }  -  +    void TMetricRegistry::Reset() { +        TWriteGuard g{Lock_}; +        for (auto& [label, metric] : Metrics_) { +            switch (metric->Type()) { +            case EMetricType::GAUGE: +                static_cast<TGauge*>(metric.Get())->Set(.0); +                break; +            case EMetricType::IGAUGE: +                static_cast<TIntGauge*>(metric.Get())->Set(0); +                break; +            case EMetricType::COUNTER: +                static_cast<TCounter*>(metric.Get())->Reset(); +                break; +            case EMetricType::RATE: +                static_cast<TRate*>(metric.Get())->Reset(); +                break; +            case EMetricType::HIST: +            case EMetricType::HIST_RATE: +                static_cast<THistogram*>(metric.Get())->Reset(); +                break; +            case EMetricType::UNKNOWN: +            case EMetricType::DSUMMARY: +            case EMetricType::LOGHIST: +                break; +            } +        } +    } +      void TMetricRegistry::Clear() {          TWriteGuard g{Lock_};          Metrics_.clear(); diff --git a/library/cpp/monlib/metrics/metric_registry.h b/library/cpp/monlib/metrics/metric_registry.h index ade57cfef3f..670cf8651e1 100644 --- a/library/cpp/monlib/metrics/metric_registry.h +++ b/library/cpp/monlib/metrics/metric_registry.h @@ -82,12 +82,12 @@ namespace NMonitoring {          /**           * Set all registered metrics to zero           */ -        void Reset();  +        void Reset();          /**           * Remove all registered metrics from registry           */          void Clear(); -  +          void Accept(TInstant time, IMetricConsumer* consumer) const override;          void Append(TInstant time, IMetricConsumer* consumer) const override;  | 
