adamdebreceni commented on code in PR #1532: URL: https://github.com/apache/nifi-minifi-cpp/pull/1532#discussion_r1221392697
########## libminifi/src/core/state/LogMetricsPublisher.cpp: ########## @@ -0,0 +1,129 @@ +/** + * + * 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. + */ +#include "core/state/LogMetricsPublisher.h" + +#include "core/Resource.h" +#include "properties/Configuration.h" +#include "core/TypedValues.h" + +namespace org::apache::nifi::minifi::state { + +LogMetricsPublisher::~LogMetricsPublisher() { + if (metrics_logger_thread_) { + metrics_logger_thread_->stopAndJoin(); + } +} + +void LogMetricsPublisher::initialize(const std::shared_ptr<Configure>& configuration, const std::shared_ptr<state::response::ResponseNodeLoader>& response_node_loader) { + state::MetricsPublisher::initialize(configuration, response_node_loader); + readLoggingInterval(); + readLogLevel(); +} + +void LogMetricsPublisher::logMetrics() { + do { + response::SerializedResponseNode parent_node; + parent_node.name = "LogMetrics"; + { + std::lock_guard<std::mutex> lock(response_nodes_mutex_); + for (const auto& response_node : response_nodes_) { + response::SerializedResponseNode metric_response_node; + metric_response_node.name = response_node->getName(); + for (const auto& serialized_node : response_node->serialize()) { + metric_response_node.children.push_back(serialized_node); + } + parent_node.children.push_back(metric_response_node); + } + } + utils::LogUtils::logWithLevel(logger_, log_level_, parent_node.to_pretty_string().c_str()); + } while (!utils::StoppableThread::waitForStopRequest(logging_interval_)); +} + +void LogMetricsPublisher::readLoggingInterval() { + gsl_Expects(configuration_); + if (auto logging_interval_str = configuration_->get(Configure::nifi_metrics_publisher_log_metrics_logging_interval)) { + if (auto logging_interval = minifi::core::TimePeriodValue::fromString(logging_interval_str.value())) { + logging_interval_ = logging_interval->getMilliseconds(); + logger_->log_info("Metric logging interval is set to %lld milliseconds", logging_interval_.count()); + return; + } else { + logger_->log_error("Configured logging interval '%s' is invalid!", logging_interval_str.value()); + } + } + + throw Exception(GENERAL_EXCEPTION, "Metrics logging interval not configured for log metrics publisher!"); +} + +void LogMetricsPublisher::readLogLevel() { + gsl_Expects(configuration_); + if (auto log_level_str = configuration_->get(Configure::nifi_metrics_publisher_log_metrics_log_level)) { + auto full_caps_log_level_str = utils::StringUtils::toUpper(*log_level_str); + log_level_ = utils::LogUtils::LogLevelOption::parse(full_caps_log_level_str.c_str(), utils::LogUtils::LogLevelOption::LOGGING_INFO); Review Comment: `parse` has a defaulted third argument controlling case sensitivity -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
