This is an automated email from the ASF dual-hosted git repository. szaszm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 4ac2979905e29016bc14f733c066240e4f223681 Author: Martin Zink <[email protected]> AuthorDate: Wed Apr 20 17:58:47 2022 +0200 MINIFICPP-1536 Remove deprecated ProcessMetrics and SystemMetrics ProcessMetrics and SystemMetrics are superseded by AgentInformation and DeviceInfoNode. These deprecated classes are not platform independent and they provide no additional information that AgentInformation and DeviceInfoNode doesnt already provide. They are also not used in any C2 implementation as far as I could tell. Closes #1302 Signed-off-by: Marton Szasz <[email protected]> --- .../include/core/state/nodes/ProcessMetrics.h | 105 ------------------ libminifi/include/core/state/nodes/SystemMetrics.h | 118 --------------------- libminifi/src/core/state/nodes/ProcessMetrics.cpp | 36 ------- libminifi/src/core/state/nodes/SystemMetrics.cpp | 36 ------- libminifi/test/unit/C2MetricsTests.cpp | 33 +----- 5 files changed, 2 insertions(+), 326 deletions(-) diff --git a/libminifi/include/core/state/nodes/ProcessMetrics.h b/libminifi/include/core/state/nodes/ProcessMetrics.h deleted file mode 100644 index 769230dc7..000000000 --- a/libminifi/include/core/state/nodes/ProcessMetrics.h +++ /dev/null @@ -1,105 +0,0 @@ -/** - * - * 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. - */ -#ifndef LIBMINIFI_INCLUDE_CORE_STATE_NODES_PROCESSMETRICS_H_ -#define LIBMINIFI_INCLUDE_CORE_STATE_NODES_PROCESSMETRICS_H_ - -#include <map> -#include <sstream> -#include <string> -#include <vector> - -#ifndef WIN32 -#include <sys/resource.h> - -#endif - -#include "../nodes/DeviceInformation.h" -#include "../nodes/MetricsBase.h" -#include "Connection.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace state { -namespace response { - -/** - * Justification and Purpose: Provides Connection queue metrics. Provides critical information to the - * C2 server. - * - */ -class ProcessMetrics : public ResponseNode { - public: - ProcessMetrics(const std::string &name, const utils::Identifier &uuid) - : ResponseNode(name, uuid) { - } - - ProcessMetrics(const std::string &name) // NOLINT - : ResponseNode(name) { - } - - ProcessMetrics() = default; - - virtual std::string getName() const { - return "ProcessMetrics"; - } - - std::vector<SerializedResponseNode> serialize() { - std::vector<SerializedResponseNode> serialized; - -#ifndef WIN32 - struct rusage my_usage; - getrusage(RUSAGE_SELF, &my_usage); - - SerializedResponseNode memory; - memory.name = "MemoryMetrics"; - - SerializedResponseNode maxrss; - maxrss.name = "maxrss"; - - maxrss.value = (uint64_t)my_usage.ru_maxrss; - - memory.children.push_back(maxrss); - serialized.push_back(memory); - - SerializedResponseNode cpu; - cpu.name = "CpuMetrics"; - SerializedResponseNode ics; - ics.name = "involcs"; - - ics.value = (uint64_t)my_usage.ru_nivcsw; - - cpu.children.push_back(ics); - serialized.push_back(cpu); - -#endif - return serialized; - } - - protected: -}; - -} // namespace response -} // namespace state -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_STATE_NODES_PROCESSMETRICS_H_ diff --git a/libminifi/include/core/state/nodes/SystemMetrics.h b/libminifi/include/core/state/nodes/SystemMetrics.h deleted file mode 100644 index 4c05d7bd0..000000000 --- a/libminifi/include/core/state/nodes/SystemMetrics.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * - * 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. - */ -#ifndef LIBMINIFI_INCLUDE_CORE_STATE_NODES_SYSTEMMETRICS_H_ -#define LIBMINIFI_INCLUDE_CORE_STATE_NODES_SYSTEMMETRICS_H_ - -#include <map> -#include <sstream> -#include <string> -#include <vector> - -#ifndef _WIN32 -#include <sys/utsname.h> - -#endif -#include "../nodes/DeviceInformation.h" -#include "../nodes/MetricsBase.h" -#include "Connection.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace state { -namespace response { - -/** - * Justification and Purpose: Provides system information, including critical device information. - * - */ -class SystemInformation : public DeviceInformation { - public: - SystemInformation(const std::string& name, const utils::Identifier& uuid) - : DeviceInformation(name, uuid) { - } - - SystemInformation(const std::string &name) // NOLINT - : DeviceInformation(name) { - } - - SystemInformation() - : DeviceInformation("systeminfo") { - } - - virtual std::string getName() const { - return "systeminfo"; - } - - std::vector<SerializedResponseNode> serialize() { - std::vector<SerializedResponseNode> serialized; - SerializedResponseNode identifier; - identifier.name = "identifier"; - identifier.value = "identifier"; -#ifndef WIN32 - SerializedResponseNode systemInfo; - systemInfo.name = "systemInfo"; - - SerializedResponseNode vcores; - vcores.name = "vCores"; - size_t ncpus = std::thread::hardware_concurrency(); - - vcores.value = (uint32_t)ncpus; - - systemInfo.children.push_back(vcores); - - SerializedResponseNode mem; - mem.name = "physicalMem"; -#if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) - size_t mema = (size_t) sysconf(_SC_PHYS_PAGES) * (size_t) sysconf(_SC_PAGESIZE); -#endif - mem.value = (uint32_t)mema; - - systemInfo.children.push_back(mem); - - SerializedResponseNode arch; - arch.name = "machinearch"; - - utsname buf; - - if (uname(&buf) == -1) { - arch.value = "unknown"; - } else { - arch.value = std::string(buf.machine); - } - - systemInfo.children.push_back(arch); - serialized.push_back(systemInfo); -#endif - serialized.push_back(identifier); - - return serialized; - } - - protected: -}; - -} // namespace response -} // namespace state -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_STATE_NODES_SYSTEMMETRICS_H_ diff --git a/libminifi/src/core/state/nodes/ProcessMetrics.cpp b/libminifi/src/core/state/nodes/ProcessMetrics.cpp deleted file mode 100644 index 84a9440b6..000000000 --- a/libminifi/src/core/state/nodes/ProcessMetrics.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * 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/nodes/ProcessMetrics.h" -#include "core/Resource.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace state { -namespace response { - -REGISTER_RESOURCE(ProcessMetrics, "Node part of an AST that defines the Processor information and metrics subtree"); - -} // namespace response -} // namespace state -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org diff --git a/libminifi/src/core/state/nodes/SystemMetrics.cpp b/libminifi/src/core/state/nodes/SystemMetrics.cpp deleted file mode 100644 index a683b4421..000000000 --- a/libminifi/src/core/state/nodes/SystemMetrics.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * 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/nodes/SystemMetrics.h" -#include "core/Resource.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace state { -namespace response { - -REGISTER_RESOURCE(SystemInformation, "Node part of an AST that defines the System information and metrics subtree"); - -} // namespace response -} // namespace state -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org diff --git a/libminifi/test/unit/C2MetricsTests.cpp b/libminifi/test/unit/C2MetricsTests.cpp index 5333706e8..7ea9af005 100644 --- a/libminifi/test/unit/C2MetricsTests.cpp +++ b/libminifi/test/unit/C2MetricsTests.cpp @@ -17,50 +17,21 @@ */ #include <memory> -#include "../../include/core/state/nodes/ProcessMetrics.h" #include "../../include/core/state/nodes/QueueMetrics.h" #include "../../include/core/state/nodes/RepositoryMetrics.h" -#include "../../include/core/state/nodes/SystemMetrics.h" #include "../TestBase.h" #include "../Catch.h" -#include "io/ClientSocket.h" #include "core/Processor.h" #include "core/ClassLoader.h" -#include "core/yaml/YamlConfiguration.h" #include "repository/VolatileContentRepository.h" #include "ProvenanceTestHelper.h" -TEST_CASE("TestProcessMetrics", "[c2m1]") { - minifi::state::response::ProcessMetrics metrics; - - REQUIRE("ProcessMetrics" == metrics.getName()); -#ifndef WIN32 - REQUIRE(2 == metrics.serialize().size()); - - REQUIRE("MemoryMetrics" == metrics.serialize().at(0).name); - REQUIRE("CpuMetrics" == metrics.serialize().at(1).name); -#endif -} - -TEST_CASE("TestSystemMetrics", "[c2m5]") { - minifi::state::response::SystemInformation metrics; - - REQUIRE("systeminfo" == metrics.getName()); - -#ifndef WIN32 - REQUIRE(2 == metrics.serialize().size()); - - REQUIRE("systemInfo" == metrics.serialize().at(0).name); - REQUIRE("identifier" == metrics.serialize().at(1).name); -#endif -} - TEST_CASE("QueueMetricsTestNoConnections", "[c2m2]") { minifi::state::response::QueueMetrics metrics; REQUIRE("QueueMetrics" == metrics.getName()); - REQUIRE(0 == metrics.serialize().size()); + REQUIRE(metrics.serialize().empty()); } TEST_CASE("QueueMetricsTestConnections", "[c2m3]") { @@ -116,7 +87,7 @@ TEST_CASE("RepositorymetricsNoRepo", "[c2m4]") { REQUIRE("RepositoryMetrics" == metrics.getName()); - REQUIRE(0 == metrics.serialize().size()); + REQUIRE(metrics.serialize().empty()); } TEST_CASE("RepositorymetricsHaveRepo", "[c2m4]") {
