You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/08/10 11:02:32 UTC

[GitHub] [nifi-minifi-cpp] lordgamez commented on a diff in pull request #1367: MINIFICPP-1822 - Add alert capability

lordgamez commented on code in PR #1367:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1367#discussion_r942309625


##########
libminifi/include/utils/TestUtils.h:
##########
@@ -62,14 +63,45 @@ Identifier generateUUID() {
 
 class ManualClock : public timeutils::Clock {
  public:
-  [[nodiscard]] std::chrono::milliseconds timeSinceEpoch() const override { return time_; }
-  void advance(std::chrono::milliseconds elapsed_time) { time_ += elapsed_time; }
+  [[nodiscard]] std::chrono::milliseconds timeSinceEpoch() const override {
+    std::lock_guard lock(mtx_);
+    return time_;
+  }
+  void advance(std::chrono::milliseconds elapsed_time) {
+    std::lock_guard lock(mtx_);
+    time_ += elapsed_time;
+    for (auto* cv : cvs_) {
+      cv->notify_all();
+    }
+  }
+  std::chrono::milliseconds wait_until(std::condition_variable& cv, std::unique_lock<std::mutex>& lck, std::chrono::milliseconds time, const std::function<bool()>& pred) override {
+    std::chrono::milliseconds now;
+    {
+      std::unique_lock lock(mtx_);
+      now = time_;
+      cvs_.insert(&cv);
+    }
+    if (now < time) {
+      cv.wait_for(lck, time - now, [&] {
+        now = timeSinceEpoch();
+        return now >= time || pred();
+      });
+    }
+    {
+      std::unique_lock lock(mtx_);
+      cvs_.erase(&cv);
+    }
+    return now;
+  }
 
  private:
+  mutable std::mutex mtx_;
+  std::unordered_set<std::condition_variable*> cvs_;
   std::chrono::milliseconds time_{0};
 };
 
 
+

Review Comment:
   nitpick: I would remove one newline instead of adding one :)



##########
libminifi/include/core/logging/alert/AlertSink.h:
##########
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <deque>
+#include <mutex>
+#include <unordered_set>
+#include <regex>
+#include <utility>
+#include <string>
+#include <memory>
+
+#include "core/controller/ControllerServiceProvider.h"
+#include "core/logging/LoggerProperties.h"
+#include "utils/ThreadPool.h"
+#include "utils/StagingQueue.h"
+#include "properties/Configure.h"
+#include "spdlog/sinks/base_sink.h"
+
+namespace org::apache::nifi::minifi::controllers {
+class SSLContextService;
+}  // namespace org::apache::nifi::minifi::controllers
+
+namespace org::apache::nifi::minifi::core::logging {
+
+class AlertSink : public spdlog::sinks::base_sink<std::mutex> {
+  struct Config {
+    std::string url;
+    std::optional<std::string> ssl_service_name;
+    int batch_size;
+    std::chrono::milliseconds flush_period;
+    std::chrono::milliseconds rate_limit;
+    int buffer_limit;
+    std::regex filter;
+    spdlog::level::level_enum level;
+  };
+
+  struct Services {
+    std::shared_ptr<controllers::SSLContextService> ssl_service;
+    std::shared_ptr<AgentIdentificationProvider> agent_id;
+  };
+
+  struct LogBuffer {
+    size_t size_{0};
+    std::deque<std::pair<std::string, size_t>> data_;
+
+    static LogBuffer allocate(size_t size);
+    LogBuffer commit();
+    [[nodiscard]]
+    size_t size() const;
+  };
+
+  class LiveLogSet {
+    using Hash = size_t;
+    std::chrono::milliseconds lifetime_{};
+    std::unordered_set<Hash> hashes_to_ignore_;
+    std::deque<std::pair<std::chrono::milliseconds, Hash>> timestamped_hashes_;
+   public:

Review Comment:
   nitpick: Prefer the order of public members before privates ones according to the [cpp guideline](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rl-order)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org