You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2022/07/29 13:32:33 UTC

[nifi-minifi-cpp] 01/02: MINIFICPP-1851 Create the CollectKubernetesPodMetrics processor

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 8255a9bd8405c716135563896890f30107f51952
Author: Ferenc Gerlits <fg...@gmail.com>
AuthorDate: Fri Jul 29 10:34:31 2022 +0200

    MINIFICPP-1851 Create the CollectKubernetesPodMetrics processor
    
    This processor wraps the existing Kubernetes REST API calls for pod
    metric collection in an easy to use processor, so users don't have to
    look up the necessary endpoint (/apis/metrics.k8s.io/v1beta1/pods) for
    InvokeHTTP when they want to collect pod metrics from inside a cluster.
    
    The pods/containers for which the metrics is collected can be filtered
    using the properties of the linked KubernetesControllerService
    
    Closes #1373
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 LICENSE                                            | 209 +--------------------
 cmake/KubernetesClientC.cmake                      |   2 +-
 docker/test/integration/features/CMakeLists.txt    |   3 +-
 ...bernetes.feature => kubernetes_logging.feature} |   0
 .../features/kubernetes_metrics.feature            |  47 +++++
 .../integration/minifi/core/KubernetesProxy.py     |  50 +++--
 .../minifi/core/MinifiAsPodInKubernetesCluster.py  |   6 +-
 .../processors/CollectKubernetesPodMetrics.py      |  24 +++
 ...-one.pod.yml => hello-world-one.helper-pod.yml} |   0
 ...-two.pod.yml => hello-world-two.helper-pod.yml} |   0
 .../pods-etc/metrics-server.dependencies.yml       | 199 ++++++++++++++++++++
 .../{log-collector.pod.yml => minifi.test-pod.yml} |   2 +-
 .../pods-etc/namespace-reader.clusterrole.yml      |   2 +-
 .../kubernetes/pods-etc/pod-reader.clusterrole.yml |   2 +-
 extensions/kubernetes/ApiClient.cpp                |  53 ++++++
 extensions/kubernetes/ApiClient.h                  |  48 +++++
 extensions/kubernetes/CMakeLists.txt               |   4 +-
 extensions/kubernetes/ContainerInfo.h              |  29 +++
 extensions/kubernetes/MetricsApi.cpp               |  45 +++++
 extensions/kubernetes/MetricsApi.h                 |  29 +++
 extensions/kubernetes/MetricsFilter.cpp            |  81 ++++++++
 extensions/kubernetes/MetricsFilter.h              |  31 +++
 .../KubernetesControllerService.cpp                |  48 +----
 .../KubernetesControllerService.h                  |   8 +-
 .../processors/CollectKubernetesPodMetrics.cpp     |  92 +++++++++
 .../processors/CollectKubernetesPodMetrics.h       |  61 ++++++
 extensions/kubernetes/tests/CMakeLists.txt         |  34 ++++
 .../tests/KubernetesMetricsFilterTests.cpp         |  94 +++++++++
 libminifi/include/utils/Deleters.h                 |   4 +
 29 files changed, 931 insertions(+), 276 deletions(-)

diff --git a/LICENSE b/LICENSE
index 966d7e6dd..823ac8688 100644
--- a/LICENSE
+++ b/LICENSE
@@ -210,6 +210,8 @@ This project bundles 'RocksDB' which is available under an ALv2 license
 This project bundles 'AWS SDK for C++' which is available under an ALv2 license
 This project bundles 'C++ Client Libraries for Google Cloud Services' which is available under an ALv2 license
 This project bundles 'Abseil Common Libraries (C++)' which is available under an ALv2 license
+This product bundles 'Kubernetes Client Library for C' (kubernetes-client/c), which is available under an ALv2 license
+This project bundles a configuration file from 'Kubernetes Metrics Server' (kubernetes-sigs/metrics-server), which is available under an ALv2 license
 
 The Apache NiFi - MiNiFi C++ project contains subcomponents with separate copyright
 notices and license terms. Your use of the source code for the these
@@ -3407,213 +3409,6 @@ For these and/or other purposes and motivations, and without any expectation of
 
 --------------------------------------------------------------------------
 
-This product bundles 'kubernetes-client/c', which is available under the Apache License 2.0:
-
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "{}"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright {yyyy} {name of copyright owner}
-
-   Licensed 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.
-
---------------------------------------------------------------------------
-
 This product bundles 'prometheus-cpp' which is available under an MIT license.
 
   MIT License
diff --git a/cmake/KubernetesClientC.cmake b/cmake/KubernetesClientC.cmake
index 5e211d27f..5da6d3c5e 100644
--- a/cmake/KubernetesClientC.cmake
+++ b/cmake/KubernetesClientC.cmake
@@ -49,7 +49,7 @@ set(K8S_PC ${Bash_EXECUTABLE} -c "set -x &&\
         (${Patch_EXECUTABLE} -R -p1 -s -f --dry-run -i ${K8S_PATCH_FILE} || ${Patch_EXECUTABLE} -p1 -i ${K8S_PATCH_FILE})")
 FetchContent_Declare(kubernetes
     GIT_REPOSITORY https://github.com/kubernetes-client/c
-    GIT_TAG 9581cd9a8426a5ad7d543b146d5c5ede37cc32e0  # latest commit on master as of 2022-01-05
+    GIT_TAG f5f12a807432824963bbea380cdf4d9ba412e00e  # v0.4.0
     PATCH_COMMAND "${K8S_PC}"
 )
 
diff --git a/docker/test/integration/features/CMakeLists.txt b/docker/test/integration/features/CMakeLists.txt
index bf1b3634e..901a3d71e 100644
--- a/docker/test/integration/features/CMakeLists.txt
+++ b/docker/test/integration/features/CMakeLists.txt
@@ -44,7 +44,8 @@ if (ENABLE_LIBRDKAFKA)
 endif()
 
 if (ENABLE_KUBERNETES)
-    set(ENABLED_BEHAVE_TESTS "${ENABLED_BEHAVE_TESTS};${CMAKE_CURRENT_SOURCE_DIR}/kubernetes.feature")
+    set(ENABLED_BEHAVE_TESTS "${ENABLED_BEHAVE_TESTS};${CMAKE_CURRENT_SOURCE_DIR}/kubernetes_logging.feature")
+    set(ENABLED_BEHAVE_TESTS "${ENABLED_BEHAVE_TESTS};${CMAKE_CURRENT_SOURCE_DIR}/kubernetes_metrics.feature")
 endif()
 
 if (ENABLE_MQTT)
diff --git a/docker/test/integration/features/kubernetes.feature b/docker/test/integration/features/kubernetes_logging.feature
similarity index 100%
rename from docker/test/integration/features/kubernetes.feature
rename to docker/test/integration/features/kubernetes_logging.feature
diff --git a/docker/test/integration/features/kubernetes_metrics.feature b/docker/test/integration/features/kubernetes_metrics.feature
new file mode 100644
index 000000000..e9b849dd1
--- /dev/null
+++ b/docker/test/integration/features/kubernetes_metrics.feature
@@ -0,0 +1,47 @@
+# 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.
+
+@requires.kubernetes.cluster
+Feature: Minifi can collect metrics from Kubernetes pods
+
+  Background:
+    Given the content of "/tmp/output" is monitored
+
+  Scenario: Collect all metrics from the default namespace
+    Given a CollectKubernetesPodMetrics processor in a Kubernetes cluster
+    And the CollectKubernetesPodMetrics processor has a Kubernetes Controller Service which is a Kubernetes Controller Service
+    And a PutFile processor in the Kubernetes cluster
+    And the "Directory" property of the PutFile processor is set to "/tmp/output"
+    And the "success" relationship of the CollectKubernetesPodMetrics processor is connected to the PutFile
+    When the MiNiFi instance starts up
+    Then at least one flowfile with the content '"kind":"PodMetricsList","apiVersion":"metrics.k8s.io/v1beta1"' is placed in the monitored directory in less than 2 minutes
+
+  Scenario: Collect metrics from selected pods
+    Given a CollectKubernetesPodMetrics processor in a Kubernetes cluster
+    And the CollectKubernetesPodMetrics processor has a Kubernetes Controller Service which is a Kubernetes Controller Service with the "Pod Name Filter" property set to ".*one"
+    And a PutFile processor in the Kubernetes cluster
+    And the "Directory" property of the PutFile processor is set to "/tmp/output"
+    And the "success" relationship of the CollectKubernetesPodMetrics processor is connected to the PutFile
+    When the MiNiFi instance starts up
+    Then at least one flowfile with the content '"metadata":{"name":"hello-world-one","namespace":"default"' is placed in the monitored directory in less than 2 minutes
+
+  Scenario: Collect metrics from selected containers
+    Given a CollectKubernetesPodMetrics processor in a Kubernetes cluster
+    And the CollectKubernetesPodMetrics processor has a Kubernetes Controller Service which is a Kubernetes Controller Service with the "Container Name Filter" property set to "echo-[^o].."
+    And a PutFile processor in the Kubernetes cluster
+    And the "Directory" property of the PutFile processor is set to "/tmp/output"
+    And the "success" relationship of the CollectKubernetesPodMetrics processor is connected to the PutFile
+    When the MiNiFi instance starts up
+    Then at least one flowfile with the content '"containers":[{"name":"echo-two","usage":{"cpu":"0","memory":' is placed in the monitored directory in less than 2 minutes
diff --git a/docker/test/integration/minifi/core/KubernetesProxy.py b/docker/test/integration/minifi/core/KubernetesProxy.py
index 0af95fc81..8c35037c2 100644
--- a/docker/test/integration/minifi/core/KubernetesProxy.py
+++ b/docker/test/integration/minifi/core/KubernetesProxy.py
@@ -16,7 +16,9 @@
 
 import docker
 import glob
+import logging
 import os
+import re
 import stat
 import subprocess
 import time
@@ -37,12 +39,14 @@ class KubernetesProxy:
         self.cleanup()
 
     def cleanup(self):
-        subprocess.run([self.kind_binary_path, 'delete', 'cluster'])
+        if os.path.exists(self.kind_binary_path):
+            subprocess.run([self.kind_binary_path, 'delete', 'cluster'])
 
     def __download_kind(self):
-        if subprocess.run(['curl', '-Lo', self.kind_binary_path, 'https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64']).returncode != 0:
-            raise Exception("Could not download kind")
-        os.chmod(self.kind_binary_path, stat.S_IXUSR)
+        if not os.path.exists(self.kind_binary_path):
+            if subprocess.run(['curl', '-Lo', self.kind_binary_path, 'https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64']).returncode != 0:
+                raise Exception("Could not download kind")
+            os.chmod(self.kind_binary_path, stat.S_IXUSR)
 
     def create_config(self, volumes):
         kind_config = dedent("""\
@@ -74,22 +78,40 @@ class KubernetesProxy:
         if subprocess.run([self.kind_binary_path, 'load', 'docker-image', image_name + ':' + image_tag]).returncode != 0:
             raise Exception("Could not load the %s docker image into the kind cluster" % image_name)
 
-    def create_objects(self):
+    def create_helper_objects(self):
         self.__wait_for_default_service_account('default')
         namespaces = self.__create_objects_of_type(self.resources_directory, 'namespace')
         for namespace in namespaces:
             self.__wait_for_default_service_account(namespace)
 
-        self.__create_objects_of_type(self.resources_directory, 'pod')
+        self.__create_objects_of_type(self.resources_directory, 'dependencies')
+        self.__create_objects_of_type(self.resources_directory, 'helper-pod')
         self.__create_objects_of_type(self.resources_directory, 'clusterrole')
         self.__create_objects_of_type(self.resources_directory, 'clusterrolebinding')
 
+        self.__wait_for_pod_startup('default', 'hello-world-one')
+        self.__wait_for_pod_startup('default', 'hello-world-two')
+        self.__wait_for_pod_startup('kube-system', 'metrics-server')
+
+    def create_minifi_pod(self):
+        self.__create_objects_of_type(self.resources_directory, 'test-pod')
+        self.__wait_for_pod_startup('daemon', 'minifi')
+
     def delete_pods(self):
-        self.__delete_objects_of_type('pod')
+        self.__delete_objects_of_type('test-pod')
+        self.__delete_objects_of_type('helper-pod')
+
+    def __wait_for_pod_startup(self, namespace, pod_name):
+        for _ in range(120):
+            (code, output) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', '-n', namespace, 'get', 'pods'])
+            if code == 0 and re.search(f'{pod_name}.*Running', output.decode('utf-8')):
+                return
+            time.sleep(1)
+        raise Exception(f"The pod {namespace}:{pod_name} in the Kubernetes cluster failed to start up")
 
     def __wait_for_default_service_account(self, namespace):
         for _ in range(120):
-            (code, _) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', '-n', namespace, 'get', 'serviceaccount', 'default'])
+            (code, output) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', '-n', namespace, 'get', 'serviceaccount', 'default'])
             if code == 0:
                 return
             time.sleep(1)
@@ -102,9 +124,9 @@ class KubernetesProxy:
             file_name_in_container = os.path.join('/var/tmp', file_name)
             self.__copy_file_to_container(full_file_name, 'kind-control-plane', file_name_in_container)
 
-            (code, _) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', 'apply', '-f', file_name_in_container])
+            (code, output) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', 'apply', '-f', file_name_in_container])
             if code != 0:
-                raise Exception("Could not create kubernetes object from file '%s'" % full_file_name)
+                raise Exception("Could not create kubernetes object from file '%s': %s" % full_file_name, output.decode('utf-8'))
 
             object_name = file_name.replace(f'.{type}.yml', '')
             found_objects.append(object_name)
@@ -115,9 +137,11 @@ class KubernetesProxy:
             file_name = os.path.basename(full_file_name)
             file_name_in_container = os.path.join('/var/tmp', file_name)
 
-            (code, _) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', 'delete', '-f', file_name_in_container, '--grace-period=0', '--force'])
-            if code != 0:
-                raise Exception("Could not delete kubernetes object from file '%s'" % file_name_in_container)
+            (code, output) = self.docker_client.containers.get('kind-control-plane').exec_run(['kubectl', 'delete', '-f', file_name_in_container, '--grace-period=0', '--force'])
+            if code == 0:
+                logging.info("Created component from file '%s': %s", full_file_name, output.decode('utf-8'))
+            else:
+                raise Exception("Could not delete kubernetes object from file '%s': %s", full_file_name, output.decode('utf-8'))
 
     def __copy_file_to_container(self, host_file, container_name, container_file):
         if subprocess.run(['docker', 'cp', host_file, container_name + ':' + container_file]).returncode != 0:
diff --git a/docker/test/integration/minifi/core/MinifiAsPodInKubernetesCluster.py b/docker/test/integration/minifi/core/MinifiAsPodInKubernetesCluster.py
index e9c821367..66bc734a0 100644
--- a/docker/test/integration/minifi/core/MinifiAsPodInKubernetesCluster.py
+++ b/docker/test/integration/minifi/core/MinifiAsPodInKubernetesCluster.py
@@ -45,10 +45,10 @@ class MinifiAsPodInKubernetesCluster(MinifiContainer):
 
         logging.info('Setting up container: %s', self.name)
 
+        self.kubernetes_proxy.create_helper_objects()
         self._create_config()
-
         self.kubernetes_proxy.load_docker_image(MinifiAsPodInKubernetesCluster.MINIFI_IMAGE_NAME, MinifiAsPodInKubernetesCluster.MINIFI_IMAGE_TAG)
-        self.kubernetes_proxy.create_objects()
+        self.kubernetes_proxy.create_minifi_pod()
 
         logging.info('Finished setting up container: %s', self.name)
 
@@ -56,7 +56,7 @@ class MinifiAsPodInKubernetesCluster(MinifiContainer):
         return LogSource.FROM_GET_APP_LOG_METHOD
 
     def get_app_log(self):
-        return 'OK', self.kubernetes_proxy.get_logs('daemon', 'log-collector')
+        return 'OK', self.kubernetes_proxy.get_logs('daemon', 'minifi')
 
     def cleanup(self):
         # cleanup is done through the kubernetes cluster in the environment.py
diff --git a/docker/test/integration/minifi/processors/CollectKubernetesPodMetrics.py b/docker/test/integration/minifi/processors/CollectKubernetesPodMetrics.py
new file mode 100644
index 000000000..4da4e5066
--- /dev/null
+++ b/docker/test/integration/minifi/processors/CollectKubernetesPodMetrics.py
@@ -0,0 +1,24 @@
+# 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.
+
+
+from ..core.Processor import Processor
+
+
+class CollectKubernetesPodMetrics(Processor):
+    def __init__(self, schedule={'scheduling strategy': 'TIMER_DRIVEN', 'scheduling period': '1 second'}):
+        super(CollectKubernetesPodMetrics, self).__init__(
+            'CollectKubernetesPodMetrics',
+            schedule=schedule)
diff --git a/docker/test/integration/resources/kubernetes/pods-etc/hello-world-one.pod.yml b/docker/test/integration/resources/kubernetes/pods-etc/hello-world-one.helper-pod.yml
similarity index 100%
rename from docker/test/integration/resources/kubernetes/pods-etc/hello-world-one.pod.yml
rename to docker/test/integration/resources/kubernetes/pods-etc/hello-world-one.helper-pod.yml
diff --git a/docker/test/integration/resources/kubernetes/pods-etc/hello-world-two.pod.yml b/docker/test/integration/resources/kubernetes/pods-etc/hello-world-two.helper-pod.yml
similarity index 100%
rename from docker/test/integration/resources/kubernetes/pods-etc/hello-world-two.pod.yml
rename to docker/test/integration/resources/kubernetes/pods-etc/hello-world-two.helper-pod.yml
diff --git a/docker/test/integration/resources/kubernetes/pods-etc/metrics-server.dependencies.yml b/docker/test/integration/resources/kubernetes/pods-etc/metrics-server.dependencies.yml
new file mode 100644
index 000000000..4ad4a3f85
--- /dev/null
+++ b/docker/test/integration/resources/kubernetes/pods-etc/metrics-server.dependencies.yml
@@ -0,0 +1,199 @@
+# downloaded from https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.6.1/components.yaml
+# with a --kubelet-insecure-tls argument added because `kind` doesn't like TLS here
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: metrics-server
+  namespace: kube-system
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRole
+metadata:
+  labels:
+    k8s-app: metrics-server
+    rbac.authorization.k8s.io/aggregate-to-admin: "true"
+    rbac.authorization.k8s.io/aggregate-to-edit: "true"
+    rbac.authorization.k8s.io/aggregate-to-view: "true"
+  name: system:aggregated-metrics-reader
+rules:
+- apiGroups:
+  - metrics.k8s.io
+  resources:
+  - pods
+  - nodes
+  verbs:
+  - get
+  - list
+  - watch
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRole
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: system:metrics-server
+rules:
+- apiGroups:
+  - ""
+  resources:
+  - nodes/metrics
+  verbs:
+  - get
+- apiGroups:
+  - ""
+  resources:
+  - pods
+  - nodes
+  verbs:
+  - get
+  - list
+  - watch
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: RoleBinding
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: metrics-server-auth-reader
+  namespace: kube-system
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: Role
+  name: extension-apiserver-authentication-reader
+subjects:
+- kind: ServiceAccount
+  name: metrics-server
+  namespace: kube-system
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: metrics-server:system:auth-delegator
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: system:auth-delegator
+subjects:
+- kind: ServiceAccount
+  name: metrics-server
+  namespace: kube-system
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: system:metrics-server
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: system:metrics-server
+subjects:
+- kind: ServiceAccount
+  name: metrics-server
+  namespace: kube-system
+---
+apiVersion: v1
+kind: Service
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: metrics-server
+  namespace: kube-system
+spec:
+  ports:
+  - name: https
+    port: 443
+    protocol: TCP
+    targetPort: https
+  selector:
+    k8s-app: metrics-server
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: metrics-server
+  namespace: kube-system
+spec:
+  selector:
+    matchLabels:
+      k8s-app: metrics-server
+  strategy:
+    rollingUpdate:
+      maxUnavailable: 0
+  template:
+    metadata:
+      labels:
+        k8s-app: metrics-server
+    spec:
+      containers:
+      - args:
+        - --kubelet-insecure-tls
+        - --cert-dir=/tmp
+        - --secure-port=4443
+        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
+        - --kubelet-use-node-status-port
+        - --metric-resolution=15s
+        image: k8s.gcr.io/metrics-server/metrics-server:v0.6.1
+        imagePullPolicy: IfNotPresent
+        livenessProbe:
+          failureThreshold: 3
+          httpGet:
+            path: /livez
+            port: https
+            scheme: HTTPS
+          periodSeconds: 10
+        name: metrics-server
+        ports:
+        - containerPort: 4443
+          name: https
+          protocol: TCP
+        readinessProbe:
+          failureThreshold: 3
+          httpGet:
+            path: /readyz
+            port: https
+            scheme: HTTPS
+          initialDelaySeconds: 20
+          periodSeconds: 10
+        resources:
+          requests:
+            cpu: 100m
+            memory: 200Mi
+        securityContext:
+          allowPrivilegeEscalation: false
+          readOnlyRootFilesystem: true
+          runAsNonRoot: true
+          runAsUser: 1000
+        volumeMounts:
+        - mountPath: /tmp
+          name: tmp-dir
+      nodeSelector:
+        kubernetes.io/os: linux
+      priorityClassName: system-cluster-critical
+      serviceAccountName: metrics-server
+      volumes:
+      - emptyDir: {}
+        name: tmp-dir
+---
+apiVersion: apiregistration.k8s.io/v1
+kind: APIService
+metadata:
+  labels:
+    k8s-app: metrics-server
+  name: v1beta1.metrics.k8s.io
+spec:
+  group: metrics.k8s.io
+  groupPriorityMinimum: 100
+  insecureSkipTLSVerify: true
+  service:
+    name: metrics-server
+    namespace: kube-system
+  version: v1beta1
+  versionPriority: 100
diff --git a/docker/test/integration/resources/kubernetes/pods-etc/log-collector.pod.yml b/docker/test/integration/resources/kubernetes/pods-etc/minifi.test-pod.yml
similarity index 96%
rename from docker/test/integration/resources/kubernetes/pods-etc/log-collector.pod.yml
rename to docker/test/integration/resources/kubernetes/pods-etc/minifi.test-pod.yml
index 307a9bc87..c6f980647 100644
--- a/docker/test/integration/resources/kubernetes/pods-etc/log-collector.pod.yml
+++ b/docker/test/integration/resources/kubernetes/pods-etc/minifi.test-pod.yml
@@ -2,7 +2,7 @@ apiVersion: v1
 kind: Pod
 metadata:
   namespace: daemon
-  name: log-collector
+  name: minifi
 spec:
   securityContext:
     runAsUser: 0
diff --git a/docker/test/integration/resources/kubernetes/pods-etc/namespace-reader.clusterrole.yml b/docker/test/integration/resources/kubernetes/pods-etc/namespace-reader.clusterrole.yml
index 863439a69..9b714f46b 100644
--- a/docker/test/integration/resources/kubernetes/pods-etc/namespace-reader.clusterrole.yml
+++ b/docker/test/integration/resources/kubernetes/pods-etc/namespace-reader.clusterrole.yml
@@ -4,6 +4,6 @@ metadata:
   namespace: default
   name: namespace-reader
 rules:
-- apiGroups: [""]  # "" indicates the core API group
+- apiGroups: ["", "metrics.k8s.io"]  # "" indicates the core API group
   resources: ["namespaces"]
   verbs: ["get", "watch", "list"]
diff --git a/docker/test/integration/resources/kubernetes/pods-etc/pod-reader.clusterrole.yml b/docker/test/integration/resources/kubernetes/pods-etc/pod-reader.clusterrole.yml
index a83231487..03904d40c 100644
--- a/docker/test/integration/resources/kubernetes/pods-etc/pod-reader.clusterrole.yml
+++ b/docker/test/integration/resources/kubernetes/pods-etc/pod-reader.clusterrole.yml
@@ -4,6 +4,6 @@ metadata:
   namespace: default
   name: pod-reader
 rules:
-- apiGroups: [""]  # "" indicates the core API group
+- apiGroups: ["", "metrics.k8s.io"]  # "" indicates the core API group
   resources: ["pods"]
   verbs: ["get", "watch", "list"]
diff --git a/extensions/kubernetes/ApiClient.cpp b/extensions/kubernetes/ApiClient.cpp
new file mode 100644
index 000000000..032d57faa
--- /dev/null
+++ b/extensions/kubernetes/ApiClient.cpp
@@ -0,0 +1,53 @@
+/**
+ * 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 "ApiClient.h"
+
+extern "C" {
+#include "config/incluster_config.h"
+#include "config/kube_config.h"
+#include "include/apiClient.h"
+}
+
+#include "utils/StringUtils.h"
+
+namespace {
+
+gsl::not_null<apiClient_t*> createApiClient(char **base_path, sslConfig_t** ssl_config, list_t** api_keys) {
+  int rc = load_incluster_config(base_path, ssl_config, api_keys);
+  if (rc != 0) {
+    throw std::runtime_error(org::apache::nifi::minifi::utils::StringUtils::join_pack("load_incluster_config() failed with error code ", std::to_string(rc)));
+  }
+  const auto api_client = apiClient_create_with_base_path(*base_path, *ssl_config, *api_keys);
+  if (!api_client) {
+    throw std::runtime_error("apiClient_create_with_base_path() failed");
+  }
+  return gsl::make_not_null(api_client);
+}
+
+}  // namespace
+
+namespace org::apache::nifi::minifi::kubernetes {
+
+ApiClient::ApiClient() : api_client_(createApiClient(&base_path_, &ssl_config_, &api_keys_)) {}
+
+ApiClient::~ApiClient() noexcept {
+  apiClient_free(api_client_);
+  free_client_config(base_path_, ssl_config_, api_keys_);
+  apiClient_unsetupGlobalEnv();
+}
+
+}  // namespace org::apache::nifi::minifi::kubernetes
diff --git a/extensions/kubernetes/ApiClient.h b/extensions/kubernetes/ApiClient.h
new file mode 100644
index 000000000..5f2d7d702
--- /dev/null
+++ b/extensions/kubernetes/ApiClient.h
@@ -0,0 +1,48 @@
+/**
+ * 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 <string>
+
+#include "utils/gsl.h"
+
+struct apiClient_t;
+struct list_t;
+struct sslConfig_t;
+
+namespace org::apache::nifi::minifi::kubernetes {
+
+class ApiClient {
+ public:
+  ApiClient();
+  ~ApiClient() noexcept;
+
+  ApiClient(ApiClient&&) = delete;
+  ApiClient(const ApiClient&) = delete;
+  ApiClient& operator=(ApiClient&&) = delete;
+  ApiClient& operator=(const ApiClient&) = delete;
+
+  [[nodiscard]] gsl::not_null<apiClient_t*> getClient() const noexcept { return api_client_; }
+
+ private:
+  gsl::owner<char*> base_path_ = nullptr;
+  gsl::owner<sslConfig_t*> ssl_config_ = nullptr;
+  gsl::owner<list_t*> api_keys_ = nullptr;
+  gsl::not_null<gsl::owner<apiClient_t*>> api_client_;  // must be declared after base_path_, ssl_config_ and api_keys_
+};
+
+}  // namespace org::apache::nifi::minifi::kubernetes
diff --git a/extensions/kubernetes/CMakeLists.txt b/extensions/kubernetes/CMakeLists.txt
index 22f846f45..bd99a6be8 100644
--- a/extensions/kubernetes/CMakeLists.txt
+++ b/extensions/kubernetes/CMakeLists.txt
@@ -23,9 +23,9 @@ include(KubernetesClientC)
 
 include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt)
 
-file(GLOB SOURCES "*.cpp" "controllerservice/*.cpp")
+file(GLOB SOURCES "*.cpp" "controllerservice/*.cpp" "processors/*.cpp")
 add_library(minifi-kubernetes-extensions SHARED ${SOURCES})
 target_link_libraries(minifi-kubernetes-extensions ${LIBMINIFI} kubernetes CURL::libcurl)
 
-register_extension(minifi-kubernetes-extensions "KUBERNETES EXTENSIONS" KUBERNETES-EXTENSIONS "This enables Kubernetes support")
+register_extension(minifi-kubernetes-extensions "KUBERNETES EXTENSIONS" KUBERNETES-EXTENSIONS "This enables Kubernetes support" "extensions/kubernetes/tests")
 register_extension_linter(minifi-kubernetes-extensions-linter)
diff --git a/extensions/kubernetes/ContainerInfo.h b/extensions/kubernetes/ContainerInfo.h
new file mode 100644
index 000000000..2a742f347
--- /dev/null
+++ b/extensions/kubernetes/ContainerInfo.h
@@ -0,0 +1,29 @@
+/**
+ * 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 <string>
+
+namespace org::apache::nifi::minifi::kubernetes {
+
+struct ContainerInfo {
+  std::string name_space;
+  std::string pod_name;
+  std::string container_name;
+};
+
+}  // namespace org::apache::nifi::minifi::kubernetes
diff --git a/extensions/kubernetes/MetricsApi.cpp b/extensions/kubernetes/MetricsApi.cpp
new file mode 100644
index 000000000..f392079c9
--- /dev/null
+++ b/extensions/kubernetes/MetricsApi.cpp
@@ -0,0 +1,45 @@
+/**
+ * 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 "MetricsApi.h"
+
+#include <memory>
+
+extern "C" {
+#include "include/generic.h"
+}
+
+#include "ApiClient.h"
+#include "utils/Deleters.h"
+
+namespace {
+struct genericClient_t_deleter { void operator()(genericClient_t* ptr) const noexcept { genericClient_free(ptr); } };
+using genericClient_unique_ptr = std::unique_ptr<genericClient_t, genericClient_t_deleter>;
+}  // namespace
+
+namespace org::apache::nifi::minifi::kubernetes::metrics {
+
+nonstd::expected<std::string, std::string> podMetricsList(const kubernetes::ApiClient& api_client) {
+  genericClient_unique_ptr genericClient{genericClient_create(api_client.getClient(), "metrics.k8s.io", "v1beta1", "pods")};
+  utils::freeing_unique_ptr<char> api_response{Generic_list(genericClient.get())};
+  if (api_response) {
+    return std::string{api_response.get()};
+  } else {
+    return nonstd::make_unexpected("Could not access the Kubernetes API /apis/metrics.k8s.io/v1beta1/pods");
+  }
+}
+
+}  // namespace org::apache::nifi::minifi::kubernetes::metrics
diff --git a/extensions/kubernetes/MetricsApi.h b/extensions/kubernetes/MetricsApi.h
new file mode 100644
index 000000000..bcbfad65a
--- /dev/null
+++ b/extensions/kubernetes/MetricsApi.h
@@ -0,0 +1,29 @@
+/**
+ * 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 <string>
+
+#include "ApiClient.h"
+
+#include "utils/expected.h"
+
+namespace org::apache::nifi::minifi::kubernetes::metrics {
+
+nonstd::expected<std::string, std::string> podMetricsList(const kubernetes::ApiClient& api_client);
+
+}  // namespace org::apache::nifi::minifi::kubernetes::metrics
diff --git a/extensions/kubernetes/MetricsFilter.cpp b/extensions/kubernetes/MetricsFilter.cpp
new file mode 100644
index 000000000..343a720f7
--- /dev/null
+++ b/extensions/kubernetes/MetricsFilter.cpp
@@ -0,0 +1,81 @@
+/**
+ * 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 "MetricsFilter.h"
+
+#include "rapidjson/document.h"
+#include "rapidjson/error/en.h"
+#include "rapidjson/stringbuffer.h"
+#include "rapidjson/writer.h"
+#include "utils/StringUtils.h"
+
+namespace org::apache::nifi::minifi::kubernetes::metrics {
+
+nonstd::expected<std::string, std::string> filter(const std::string& metrics_json, const std::function<bool(const kubernetes::ContainerInfo&)>& filter_function) {
+  rapidjson::Document document;
+  rapidjson::ParseResult parse_result = document.Parse<rapidjson::kParseStopWhenDoneFlag>(metrics_json.data());
+  if (parse_result.IsError()) {
+    return nonstd::make_unexpected(utils::StringUtils::join_pack("Error parsing the metrics received from the Kubernetes API at offset ",
+        std::to_string(parse_result.Offset()), ": ", rapidjson::GetParseError_En(parse_result.Code())));
+  }
+
+  if (!document.HasMember("items") || !document["items"].IsArray()) {
+    return nonstd::make_unexpected("Unexpected JSON received from the Kubernetes API: missing list of 'items'");
+  }
+
+  rapidjson::Value& pods = document["items"];
+  for (rapidjson::Value::ValueIterator pod_it = pods.Begin(); pod_it != pods.End(); /* don't increment here, as we may remove elements */) {
+    rapidjson::Value& pod_metrics = *pod_it;
+
+    if (!pod_metrics.HasMember("metadata") || !pod_metrics["metadata"].IsObject()) { ++pod_it; continue; }
+    const rapidjson::Value& metadata = pod_metrics["metadata"];
+
+    if (!metadata.HasMember("namespace") || !metadata["namespace"].IsString()) { ++pod_it; continue; }
+    const std::string name_space = metadata["namespace"].GetString();
+
+    if (!metadata.HasMember("name") || !metadata["name"].IsString()) { ++pod_it; continue; }
+    const std::string pod_name = metadata["name"].GetString();
+
+    if (!pod_metrics.HasMember("containers") || !pod_metrics["containers"].IsArray()) { ++pod_it; continue; }
+    rapidjson::Value& containers = pod_metrics["containers"];
+
+    for (rapidjson::Value::ValueIterator container_it = containers.Begin(); container_it != containers.End(); /* don't increment here, as we may remove elements */) {
+      const rapidjson::Value& container_metrics = *container_it;
+
+      if (!container_metrics.HasMember("name") || !container_metrics["name"].IsString()) { ++container_it; continue; }
+      const std::string container_name = container_metrics["name"].GetString();
+
+      if (!filter_function(kubernetes::ContainerInfo{.name_space = name_space, .pod_name = pod_name, .container_name = container_name})) {
+        container_it = containers.Erase(container_it);
+      } else {
+        ++container_it;
+      }
+    }
+
+    if (containers.Empty()) {
+      pod_it = pods.Erase(pod_it);
+    } else {
+      ++pod_it;
+    }
+  }
+
+  rapidjson::StringBuffer buffer;
+  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+  document.Accept(writer);
+  return buffer.GetString();
+}
+
+}  // namespace org::apache::nifi::minifi::kubernetes::metrics
diff --git a/extensions/kubernetes/MetricsFilter.h b/extensions/kubernetes/MetricsFilter.h
new file mode 100644
index 000000000..3ed60131a
--- /dev/null
+++ b/extensions/kubernetes/MetricsFilter.h
@@ -0,0 +1,31 @@
+/**
+ * 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 <functional>
+#include <string>
+
+#include "ContainerInfo.h"
+#include "utils/expected.h"
+
+namespace org::apache::nifi::minifi::kubernetes::metrics {
+
+[[nodiscard]] nonstd::expected<std::string, std::string> filter(
+    const std::string& metrics_json,
+    const std::function<bool(const kubernetes::ContainerInfo&)>& filter_function);
+
+}  // namespace org::apache::nifi::minifi::kubernetes::metrics
diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp
index d022f96a5..24f3b9a4a 100644
--- a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp
+++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp
@@ -20,9 +20,6 @@
 #include <vector>
 
 extern "C" {
-#include "config/incluster_config.h"
-#include "config/kube_config.h"
-#include "include/apiClient.h"
 #include "api/CoreV1API.h"
 }
 
@@ -35,45 +32,6 @@ extern "C" {
 
 namespace org::apache::nifi::minifi::controllers {
 
-class KubernetesControllerService::APIClient {
- public:
-  APIClient();
-  ~APIClient() noexcept;
-
-  APIClient(APIClient&&) = delete;
-  APIClient(const APIClient&) = delete;
-  APIClient& operator=(APIClient&&) = delete;
-  APIClient& operator=(const APIClient&) = delete;
-
-  [[nodiscard]] gsl::not_null<apiClient_t*> getClient() const noexcept { return api_client_; }
-
- private:
-  char* base_path_ = nullptr;
-  sslConfig_t* ssl_config_ = nullptr;
-  list_t* api_keys_ = nullptr;
-  gsl::not_null<apiClient_t*> api_client_;
-};
-
-KubernetesControllerService::APIClient::APIClient()
-  : api_client_([this] {
-    int rc = load_incluster_config(&base_path_, &ssl_config_, &api_keys_);
-    if (rc != 0) {
-      throw std::runtime_error(utils::StringUtils::join_pack("load_incluster_config() failed with error code ", std::to_string(rc)));
-    }
-    const auto api_client = apiClient_create_with_base_path(base_path_, ssl_config_, api_keys_);
-    if (!api_client) {
-      throw std::runtime_error("apiClient_create_with_base_path() failed");
-    }
-    return gsl::make_not_null(api_client);
-    }()) {
-}
-
-KubernetesControllerService::APIClient::~APIClient() noexcept {
-  apiClient_free(api_client_);
-  free_client_config(base_path_, ssl_config_, api_keys_);
-  apiClient_unsetupGlobalEnv();
-}
-
 const core::Property KubernetesControllerService::NamespaceFilter{
     core::PropertyBuilder::createProperty("Namespace Filter")
         ->withDescription("Limit the output to pods in namespaces which match this regular expression")
@@ -110,7 +68,7 @@ void KubernetesControllerService::initialize() {
 
 void KubernetesControllerService::onEnable() {
   try {
-    api_client_ = std::make_unique<APIClient>();
+    api_client_ = std::make_unique<kubernetes::ApiClient>();
   } catch (const std::runtime_error& ex) {
     logger_->log_error("Could not create the API client in the Kubernetes Controller Service: %s", ex.what());
   }
@@ -199,6 +157,10 @@ std::optional<std::vector<KubernetesControllerService::AttributeMap>> Kubernetes
   return container_attribute_maps;
 }
 
+bool KubernetesControllerService::matchesRegexFilters(const kubernetes::ContainerInfo& container_info) const {
+  return matchesRegexFilters(container_info.name_space, container_info.pod_name, container_info.container_name);
+}
+
 bool KubernetesControllerService::matchesRegexFilters(const std::string& name_space, const std::string& pod_name, const std::string& container_name) const {
   static constexpr auto matchesFilter = [](const std::string& target, const std::optional<utils::Regex>& filter) {
     return !filter || utils::regexMatch(target, *filter);
diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.h b/extensions/kubernetes/controllerservice/KubernetesControllerService.h
index 252585935..ec883c309 100644
--- a/extensions/kubernetes/controllerservice/KubernetesControllerService.h
+++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.h
@@ -21,6 +21,8 @@
 #include <string_view>
 #include <vector>
 
+#include "../ApiClient.h"
+#include "../ContainerInfo.h"
 #include "controllers/AttributeProviderService.h"
 #include "core/logging/Logger.h"
 #include "core/Property.h"
@@ -53,10 +55,10 @@ class KubernetesControllerService : public AttributeProviderService {
   void onEnable() override;
   std::optional<std::vector<AttributeMap>> getAttributes() override;
   std::string_view name() const override { return "kubernetes"; }
+  const kubernetes::ApiClient* apiClient() const { return api_client_.get(); }
+  bool matchesRegexFilters(const kubernetes::ContainerInfo& container_info) const;
 
  private:
-  class APIClient;
-
   bool matchesRegexFilters(const std::string& name_space, const std::string& pod_name, const std::string& container_name) const;
 
   std::mutex initialization_mutex_;
@@ -65,7 +67,7 @@ class KubernetesControllerService : public AttributeProviderService {
   std::optional<utils::Regex> pod_name_filter_;
   std::optional<utils::Regex> container_name_filter_;
   std::shared_ptr<core::logging::Logger> logger_;
-  std::unique_ptr<APIClient> api_client_;
+  std::unique_ptr<kubernetes::ApiClient> api_client_;
 };
 
 }  // namespace org::apache::nifi::minifi::controllers
diff --git a/extensions/kubernetes/processors/CollectKubernetesPodMetrics.cpp b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.cpp
new file mode 100644
index 000000000..3f777cff1
--- /dev/null
+++ b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.cpp
@@ -0,0 +1,92 @@
+/**
+ * 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 "CollectKubernetesPodMetrics.h"
+
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/PropertyBuilder.h"
+#include "core/Resource.h"
+#include "../ContainerInfo.h"
+#include "../MetricsApi.h"
+#include "../MetricsFilter.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+const core::Property CollectKubernetesPodMetrics::KubernetesControllerService{
+    core::PropertyBuilder::createProperty("Kubernetes Controller Service")
+    ->withDescription("Controller service which provides Kubernetes functionality")
+    ->isRequired(true)
+    ->build()};
+
+const core::Relationship CollectKubernetesPodMetrics::Success("success", "All flow files produced are routed to Success.");
+
+void CollectKubernetesPodMetrics::initialize() {
+  setSupportedProperties(properties());
+  setSupportedRelationships(relationships());
+}
+
+void CollectKubernetesPodMetrics::onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>&) {
+  gsl_Expects(context);
+
+  const auto controller_service_name = context->getProperty(KubernetesControllerService);
+  if (!controller_service_name || controller_service_name->empty()) {
+    throw minifi::Exception{ExceptionType::PROCESS_SCHEDULE_EXCEPTION, utils::StringUtils::join_pack("Missing '", KubernetesControllerService.getName(), "' property")};
+  }
+
+  std::shared_ptr<core::controller::ControllerService> controller_service = context->getControllerService(*controller_service_name);
+  if (!controller_service) {
+    throw minifi::Exception{ExceptionType::PROCESS_SCHEDULE_EXCEPTION, utils::StringUtils::join_pack("Controller service '", *controller_service_name, "' not found")};
+  }
+
+  kubernetes_controller_service_ = std::dynamic_pointer_cast<minifi::controllers::KubernetesControllerService>(controller_service);
+  if (!kubernetes_controller_service_) {
+    throw minifi::Exception{ExceptionType::PROCESS_SCHEDULE_EXCEPTION, utils::StringUtils::join_pack("Controller service '", *controller_service_name, "' is not a KubernetesControllerService")};
+  }
+}
+
+void CollectKubernetesPodMetrics::onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) {
+  gsl_Expects(context && session && kubernetes_controller_service_);
+
+  const kubernetes::ApiClient* api_client = kubernetes_controller_service_->apiClient();
+  if (!api_client) {
+    throw minifi::Exception(ExceptionType::PROCESSOR_EXCEPTION, "The KubernetesControllerService is in a bad state: the API client is null");
+  }
+
+  const auto metrics = kubernetes::metrics::podMetricsList(*api_client);
+  if (!metrics) {
+    logger_->log_error("Could not get metrics from the Kubernetes API: %s", metrics.error());
+    return;
+  }
+
+  const auto metrics_filtered = kubernetes::metrics::filter(metrics.value(), [this](const kubernetes::ContainerInfo& container_info) {
+    return kubernetes_controller_service_->matchesRegexFilters(container_info);
+  });
+  if (!metrics_filtered) {
+    logger_->log_error("Error parsing or filtering the metrics received from the Kubernetes API: %s", metrics_filtered.error());
+    return;
+  }
+
+  logger_->log_debug("Metrics received from the Kubernetes API: %s", metrics_filtered.value());
+
+  const auto flow_file = session->create();
+  session->writeBuffer(flow_file, metrics_filtered.value());
+  session->transfer(flow_file, Success);
+}
+
+REGISTER_RESOURCE(CollectKubernetesPodMetrics, Processor);
+
+}  // namespace org::apache::nifi::minifi::processors
diff --git a/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h
new file mode 100644
index 000000000..b1e922033
--- /dev/null
+++ b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h
@@ -0,0 +1,61 @@
+/**
+ * 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 <string>
+
+#include "../controllerservice/KubernetesControllerService.h"
+#include "core/logging/LoggerConfiguration.h"
+#include "core/Processor.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+class CollectKubernetesPodMetrics : public core::Processor {
+ public:
+  explicit CollectKubernetesPodMetrics(const std::string& name, const utils::Identifier& uuid = {})
+      : Processor(name, uuid) {
+  }
+
+  EXTENSIONAPI static constexpr const char* Description = "A processor which collects pod metrics when MiNiFi is run inside Kubernetes.";
+
+  EXTENSIONAPI static const core::Property KubernetesControllerService;
+  static auto properties() {
+    return std::array{KubernetesControllerService};
+  }
+
+  EXTENSIONAPI static const core::Relationship Success;
+  static auto relationships() {
+    return std::array{Success};
+  }
+
+  EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
+  EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false;
+  EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_FORBIDDEN;
+  EXTENSIONAPI static constexpr bool IsSingleThreaded = true;
+  ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS
+
+  void initialize() override;
+  void onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>& session_factory) override;
+  void onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) override;
+
+ private:
+  gsl::not_null<std::shared_ptr<core::logging::Logger>> logger_ = gsl::make_not_null(core::logging::LoggerFactory<CollectKubernetesPodMetrics>::getLogger());
+  std::shared_ptr<controllers::KubernetesControllerService> kubernetes_controller_service_;
+};
+
+}  // namespace org::apache::nifi::minifi::processors
diff --git a/extensions/kubernetes/tests/CMakeLists.txt b/extensions/kubernetes/tests/CMakeLists.txt
new file mode 100644
index 000000000..7052a514e
--- /dev/null
+++ b/extensions/kubernetes/tests/CMakeLists.txt
@@ -0,0 +1,34 @@
+#
+# 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.
+#
+
+file(GLOB KUBERNETES_UNIT_TESTS  "*.cpp")
+SET(KUBERNETES_UNIT_TEST_COUNT 0)
+FOREACH(TEST_FILE ${KUBERNETES_UNIT_TESTS})
+    get_filename_component(TEST_TARGET "${TEST_FILE}" NAME_WE)
+    add_executable("${TEST_TARGET}" "${TEST_FILE}")
+    target_include_directories(${TEST_TARGET} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/libminifi")
+    target_include_directories(${TEST_TARGET} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/libminifi/test")
+    target_include_directories(${TEST_TARGET} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/kubernetes")
+    target_link_libraries(${TEST_TARGET} minifi-kubernetes-extensions)
+    target_link_libraries(${TEST_TARGET} ${CATCH_MAIN_LIB})
+    createTests("${TEST_TARGET}")
+    add_test(NAME ${TEST_TARGET} COMMAND "${TEST_TARGET}" WORKING_DIRECTORY "${TEST_DIR}")
+    MATH(EXPR KUBERNETES_UNIT_TEST_COUNT "${KUBERNETES_UNIT_TEST_COUNT}+1")
+ENDFOREACH()
+message("-- Finished building ${KUBERNETES_UNIT_TEST_COUNT} Kubernetes related test file(s)...")
diff --git a/extensions/kubernetes/tests/KubernetesMetricsFilterTests.cpp b/extensions/kubernetes/tests/KubernetesMetricsFilterTests.cpp
new file mode 100644
index 000000000..faa382613
--- /dev/null
+++ b/extensions/kubernetes/tests/KubernetesMetricsFilterTests.cpp
@@ -0,0 +1,94 @@
+/**
+ * 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 "Catch.h"
+
+#include "ContainerInfo.h"
+#include "MetricsFilter.h"
+#include "utils/StringUtils.h"
+
+namespace minifi = org::apache::nifi::minifi;
+
+namespace {
+constexpr const char* RESULT_HEADER = R"({"kind":"PodMetricsList","apiVersion":"metrics.k8s.io/v1beta1","metadata":{},"items":[)";
+
+constexpr const char* HELLO_WORLD_POD_HEADER = R"({"metadata":{"name":"hello-world","namespace":"default","creationTimestamp":"2022-07-15T14:08:36Z"},)"
+    R"("timestamp":"2022-07-15T14:08:35Z","window":"30.817s","containers":[)";
+
+constexpr const char* HELLO_WORLD_CONTAINER_ONE = R"({"name":"echo-one","usage":{"cpu":"123n","memory":"1596Ki"}})";
+
+constexpr const char* HELLO_WORLD_CONTAINER_TWO = R"({"name":"echo-two","usage":{"cpu":"456n","memory":"1560Ki"}})";
+
+constexpr const char* MINIFI_POD = R"({"metadata":{"name":"minifi","namespace":"default","creationTimestamp":"2022-07-15T14:08:36Z"},)"
+    R"("timestamp":"2022-07-15T14:08:22Z","window":"6.342s",)"
+    R"("containers":[{"name":"minifi","usage":{"cpu":"924956n","memory":"8800Ki"}}]})";
+
+constexpr const char* SYSTEM_POD = R"({"metadata":{"name":"kube-apiserver-kind-control-plane","namespace":"kube-system","creationTimestamp":"2022-07-15T14:08:36Z",)"
+    R"("labels":{"component":"kube-apiserver","tier":"control-plane"}},"timestamp":"2022-07-15T14:08:29Z","window":"18.516s",)"
+    R"("containers":[{"name":"kube-apiserver","usage":{"cpu":"83095152n","memory":"270396Ki"}}]})";
+
+const std::string API_RESULT = minifi::utils::StringUtils::join_pack(
+    RESULT_HEADER, HELLO_WORLD_POD_HEADER, HELLO_WORLD_CONTAINER_ONE, ",", HELLO_WORLD_CONTAINER_TWO, "]},", MINIFI_POD, ",", SYSTEM_POD, "]}");
+
+void testSuccessfulFiltering(const std::function<bool(const minifi::kubernetes::ContainerInfo&)>& filter, const std::string& expected_result) {
+  const auto filtered_result = minifi::kubernetes::metrics::filter(API_RESULT, filter);
+  REQUIRE(filtered_result.has_value());
+  CHECK(filtered_result.value() == expected_result);
+}
+
+const auto ALWAYS_TRUE = [](const minifi::kubernetes::ContainerInfo&) { return true; };
+}  // namespace
+
+TEST_CASE("Without filtering, we get the full result back", "[kubernetes][metrics_filter]") {
+  testSuccessfulFiltering(ALWAYS_TRUE, API_RESULT);
+}
+
+TEST_CASE("We can filter to get metrics for the default namespace only", "[kubernetes][metrics_filter]") {
+  const auto default_namespace_only = [](const minifi::kubernetes::ContainerInfo& container_info) { return container_info.name_space == "default"; };
+  const auto expected_result = minifi::utils::StringUtils::join_pack(
+      RESULT_HEADER, HELLO_WORLD_POD_HEADER, HELLO_WORLD_CONTAINER_ONE, ",", HELLO_WORLD_CONTAINER_TWO, "]},", MINIFI_POD, "]}");
+  testSuccessfulFiltering(default_namespace_only, expected_result);
+}
+
+TEST_CASE("We can filter to get metrics for a selected pod only", "[kubernetes][metrics_filter]") {
+  const auto minifi_pod_only = [](const minifi::kubernetes::ContainerInfo& container_info) { return container_info.pod_name == "minifi"; };
+  const auto expected_result = minifi::utils::StringUtils::join_pack(RESULT_HEADER, MINIFI_POD, "]}");
+  testSuccessfulFiltering(minifi_pod_only, expected_result);
+}
+
+TEST_CASE("We can filter to get metrics for a selected container only", "[kubernetes][metrics_filter]") {
+  const auto one_container_only = [](const minifi::kubernetes::ContainerInfo& container_info) { return container_info.pod_name == "hello-world" && container_info.container_name == "echo-two"; };
+  const auto expected_result = minifi::utils::StringUtils::join_pack(RESULT_HEADER, HELLO_WORLD_POD_HEADER, HELLO_WORLD_CONTAINER_TWO, "]}]}");
+  testSuccessfulFiltering(one_container_only, expected_result);
+}
+
+TEST_CASE("We can filter to get no metrics (not super useful)", "[kubernetes][metrics_filter]") {
+  const auto always_false = [](const minifi::kubernetes::ContainerInfo&) { return false; };
+  const auto expected_result = minifi::utils::StringUtils::join_pack(RESULT_HEADER, "]}");
+  testSuccessfulFiltering(always_false, expected_result);
+}
+
+TEST_CASE("An invalid JSON will return an error", "[kubernetes][metrics_filter]") {
+  const auto filtered_result = minifi::kubernetes::metrics::filter(R"({"foo":1, bar:2})", ALWAYS_TRUE);
+  REQUIRE_FALSE(filtered_result.has_value());
+  CHECK(filtered_result.error() == "Error parsing the metrics received from the Kubernetes API at offset 10: Missing a name for object member.");
+}
+
+TEST_CASE("A JSON with an unexpected structure will return an error", "[kubernetes][metrics_filter]") {
+  const auto filtered_result = minifi::kubernetes::metrics::filter(R"({"foo":1, "bar":2})", ALWAYS_TRUE);
+  REQUIRE_FALSE(filtered_result.has_value());
+  CHECK(filtered_result.error() == "Unexpected JSON received from the Kubernetes API: missing list of 'items'");
+}
diff --git a/libminifi/include/utils/Deleters.h b/libminifi/include/utils/Deleters.h
index e33c3b8e8..d1527f1d9 100644
--- a/libminifi/include/utils/Deleters.h
+++ b/libminifi/include/utils/Deleters.h
@@ -23,6 +23,7 @@
 #else
 #include <ifaddrs.h>
 #endif /* WIN32 */
+#include <memory>
 #include <utility>
 #include "utils/net/DNS.h"
 
@@ -39,6 +40,9 @@ struct FreeDeleter {
   }
 };
 
+template<typename T>
+using freeing_unique_ptr = std::unique_ptr<T, FreeDeleter>;
+
 /**
  * Allows smart pointers to store a pointer both
  * to the stack and the heap while ensuring selective