szaszm commented on a change in pull request #955:
URL: https://github.com/apache/nifi-minifi-cpp/pull/955#discussion_r558340027



##########
File path: libminifi/src/core/logging/LoggerConfiguration.cpp
##########
@@ -85,6 +108,7 @@ LoggerConfiguration::LoggerConfiguration()
 void LoggerConfiguration::initialize(const std::shared_ptr<LoggerProperties> 
&logger_properties) {
   std::lock_guard<std::mutex> lock(mutex);
   root_namespace_ = initialize_namespaces(logger_properties);
+  initializeCompression(lock, logger_properties);

Review comment:
       I think this should be configurable. It may not be feasible to use 
memory to store logs in low memory environments or when lightweight operation 
is desired.

##########
File path: libminifi/include/io/BufferStream.h
##########
@@ -42,6 +42,14 @@ class BufferStream : public BaseStream {
     write(reinterpret_cast<const uint8_t*>(data.c_str()), data.length());
   }
 
+  /*
+   * prepares the stream to accept and additional byte_count bytes
+   * @param byte_count number of bytes we expect to write
+   */
+  void reserve(size_t byte_count) {

Review comment:
       I would name this `extend` or similar to avoid confusion with STL 
`reserve` that takes the new capacity, not the difference.

##########
File path: libminifi/include/core/logging/internal/LogBuffer.h
##########
@@ -0,0 +1,62 @@
+/**
+ *
+ * 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 <memory>
+#include <utility>
+
+#include "io/BufferStream.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace logging {
+namespace internal {
+
+class LogBuffer {
+ public:
+  LogBuffer() = default;
+  explicit LogBuffer(std::unique_ptr<io::BufferStream> buffer): 
buffer_{std::move(buffer)} {}
+
+  static LogBuffer allocate(size_t max_size) {
+    LogBuffer instance{utils::make_unique<io::BufferStream>()};
+    instance.buffer_->reserve(max_size * 3 / 2);

Review comment:
       why is this multiplication?

##########
File path: libminifi/test/unit/LoggerTests.cpp
##########
@@ -107,3 +110,71 @@ TEST_CASE("Test ShortenNames", "[ttl6]") {
   LogTestController::getInstance(props)->reset();
   LogTestController::getInstance().reset();
 }
+
+using namespace minifi::io;
+
+std::string decompress(const std::shared_ptr<InputStream>& input) {
+  auto output = utils::make_unique<BufferStream>();
+  auto decompressor = 
std::make_shared<ZlibDecompressStream>(gsl::make_not_null(output.get()));
+  minifi::internal::pipe(input, decompressor);
+  decompressor->close();
+  return std::string{reinterpret_cast<const char*>(output->getBuffer()), 
output->size()};
+}
+
+TEST_CASE("Test Compression", "[ttl7]") {
+  auto& log_config = logging::LoggerConfiguration::getConfiguration();
+  auto properties = std::make_shared<logging::LoggerProperties>();
+  std::string className;
+  SECTION("Using root logger") {
+    className = "CompressionTestClassUsingRoot";
+    // by default the root logger is OFF
+    properties->set("logger.root", "INFO");
+  }
+  SECTION("Inherit compression sink") {
+    className = "CompressionTestClassInheriting";
+    properties->set("appender.null", "null");
+    properties->set("logger." + className, "INFO,null");
+  }
+  log_config.initialize(properties);
+  auto logger = log_config.getLogger(className);
+  logger->log_error("Hi there");
+  std::shared_ptr<InputStream> 
compressed_log{logging::LoggerConfiguration::getCompressedLog(true)};
+  REQUIRE(compressed_log);
+  auto logs = decompress(compressed_log);
+  REQUIRE(logs.find("Hi there") != std::string::npos);

Review comment:
       Shouldn't this be equal or `StringUtils::endsWith`?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to