From 6cd1657d6c6112dcefe8289286af38f7c8a7e434 Mon Sep 17 00:00:00 2001 From: Kulwant Singh Date: Tue, 30 Jan 2024 16:57:36 +0000 Subject: [PATCH] Add HCS shim api as alternative source for metric provider (#154) * Add storage metrics for container and node level 1. Add storage extractors for container and node level 2. Add metric source for Windows metric collection 3. Refactor metric source for cadvisor 4. Add os label for windows # Conflicts: # internal/aws/containerinsight/const.go # receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractor.go # receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractorhelpers.go # receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/fs_extractor.go # receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows.go # receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go # receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go # receiver/awscontainerinsightreceiver/internal/stores/utils.go # receiver/awscontainerinsightreceiver/internal/stores/utils_test.go * Add hcsshim API as source 1. Added hcshim API as alternative to kubelet for networking stats 2. Added unit tests for hcsshim provider 3. Add new fields to network extractor * Fix e2e test for docker build 1. Ran `go mod tidy` inside cmd/otelcontribcol --- cmd/otelcontribcol/go.mod | 11 +- cmd/otelcontribcol/go.sum | 22 +- go.mod | 3 + go.sum | 6 +- receiver/awscontainerinsightreceiver/go.mod | 17 +- receiver/awscontainerinsightreceiver/go.sum | 32 +-- .../k8swindows/extractors/cpu_extractor.go | 2 + .../k8swindows/extractors/extractor.go | 40 +++- .../k8swindows/extractors/extractorhelpers.go | 33 +++ .../k8swindows/extractors/net_extractor.go | 11 + .../extractors/net_extractor_test.go | 126 ++++++++++- .../internal/k8swindows/hcsshim/client.go | 54 +++++ .../internal/k8swindows/hcsshim/hcsshim.go | 213 ++++++++++++++++++ .../k8swindows/hcsshim/hcsshim_test.go | 147 ++++++++++++ .../internal/k8swindows/k8swindows.go | 18 ++ .../internal/k8swindows/kubelet/client.go | 12 + .../internal/k8swindows/kubelet/kubelet.go | 8 +- .../k8swindows/kubelet/kubelet_test.go | 7 +- 18 files changed, 713 insertions(+), 49 deletions(-) create mode 100644 receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/client.go create mode 100644 receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go create mode 100644 receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go diff --git a/cmd/otelcontribcol/go.mod b/cmd/otelcontribcol/go.mod index d637ef45a609..ca1782aee29c 100644 --- a/cmd/otelcontribcol/go.mod +++ b/cmd/otelcontribcol/go.mod @@ -285,6 +285,7 @@ require ( github.com/IBM/sarama v1.42.1 // indirect github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/Microsoft/hcsshim v0.11.4 // indirect github.com/ReneKroon/ttlcache/v2 v2.11.0 // indirect github.com/SAP/go-hdb v1.6.2 // indirect github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2 // indirect @@ -339,8 +340,10 @@ require ( github.com/cloudfoundry-incubator/uaago v0.0.0-20190307164349-8136b7bbe76e // indirect github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect + github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/cgroups/v3 v3.0.2 // indirect github.com/containerd/console v1.0.3 // indirect + github.com/containerd/containerd v1.7.7 // indirect github.com/containerd/ttrpc v1.2.2 // indirect github.com/coreos/go-oidc v2.2.1+incompatible // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect @@ -394,7 +397,7 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/gocql/gocql v1.3.2 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect - github.com/godbus/dbus/v5 v5.0.6 // indirect + github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -557,7 +560,7 @@ require ( github.com/opencontainers/image-spec v1.1.0-rc5 // indirect github.com/opencontainers/runc v1.1.9 // indirect github.com/opencontainers/runtime-spec v1.1.0-rc.3 // indirect - github.com/opencontainers/selinux v1.10.0 // indirect + github.com/opencontainers/selinux v1.11.0 // indirect github.com/openshift/api v3.9.0+incompatible // indirect github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect @@ -624,8 +627,8 @@ require ( github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect github.com/vincent-petithory/dataurl v1.0.0 // indirect - github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 // indirect - github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect + github.com/vishvananda/netlink v1.2.1-beta.2 // indirect + github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect github.com/vmware/go-vmware-nsxt v0.0.0-20220328155605-f49a14c1ef5f // indirect github.com/vmware/govmomi v0.33.1 // indirect github.com/vultr/govultr/v2 v2.17.2 // indirect diff --git a/cmd/otelcontribcol/go.sum b/cmd/otelcontribcol/go.sum index 882b99e2999a..8ed02d654c58 100644 --- a/cmd/otelcontribcol/go.sum +++ b/cmd/otelcontribcol/go.sum @@ -224,7 +224,8 @@ github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jB github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/Microsoft/hcsshim v0.11.1 h1:hJ3s7GbWlGK4YVV92sO88BQSyF4ZLVy7/awqOlPxFbA= +github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= +github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/Netflix/go-env v0.0.0-20220526054621-78278af1949d h1:wvStE9wLpws31NiWUx+38wny1msZ/tm+eL5xmm4Y7So= github.com/Netflix/go-env v0.0.0-20220526054621-78278af1949d/go.mod h1:9XMFaCeRyW7fC9XJOWQ+NdAv8VLG7ys7l3x4ozEGLUQ= @@ -454,11 +455,14 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= +github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= github.com/containerd/cgroups/v3 v3.0.2 h1:f5WFqIVSgo5IZmtTT3qVBo6TzI1ON6sycSBKkymb9L0= github.com/containerd/cgroups/v3 v3.0.2/go.mod h1:JUgITrzdFqp42uI2ryGA+ge0ap/nxzYgkGmIcetmErE= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/containerd/containerd v1.7.7 h1:QOC2K4A42RQpcrZyptP6z9EJZnlHfHJUfZrAAHe15q4= +github.com/containerd/containerd v1.7.7/go.mod h1:3c4XZv6VeT9qgf9GMTxNTMFxGJrGpI2vz1yk4ye+YY8= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/ttrpc v1.2.2 h1:9vqZr0pxwOF5koz6N0N3kJ0zDHokrcPxIR/ZR2YFtOs= github.com/containerd/ttrpc v1.2.2/go.mod h1:sIT6l32Ph/H9cvnJsfXM5drIVzTr5A2flTf1G5tYZak= @@ -657,8 +661,8 @@ github.com/gocql/gocql v1.3.2/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJr github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro= -github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= @@ -1225,8 +1229,8 @@ github.com/opencontainers/runc v1.1.9 h1:XR0VIHTGce5eWPkaPesqTBrhW2yAcaraWfsEalN github.com/opencontainers/runc v1.1.9/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= github.com/opencontainers/runtime-spec v1.1.0-rc.3 h1:l04uafi6kxByhbxev7OWiuUv0LZxEsYUfDWZ6bztAuU= github.com/opencontainers/runtime-spec v1.1.0-rc.3/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU= -github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI= +github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU= +github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec= github.com/openshift/api v0.0.0-20180801171038-322a19404e37 h1:05irGU4HK4IauGGDbsk+ZHrm1wOzMLYjMlfaiqMrBYc= github.com/openshift/api v0.0.0-20180801171038-322a19404e37/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY= github.com/openshift/api v0.0.0-20210521075222-e273a339932a/go.mod h1:izBmoXbUu3z5kUa4FjZhvekTsyzIWiOoaIgJiZBBMQs= @@ -1484,10 +1488,11 @@ github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVK github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI= github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U= -github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 h1:cPXZWzzG0NllBLdjWoD1nDfaqu98YMv+OneaKc8sPOA= -github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= -github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae h1:4hwBBUfQCFe3Cym0ZtKyq7L16eZUtYKs+BaHDN6mAns= +github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs= +github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA= +github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U= github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc= github.com/vmware/go-vmware-nsxt v0.0.0-20220328155605-f49a14c1ef5f h1:NbC9yOr5At92seXK+kOr2TzU3mIWzcJOVzZasGSuwoU= @@ -1877,7 +1882,6 @@ golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/go.mod b/go.mod index a127906eef40..c360ba1ae0ff 100644 --- a/go.mod +++ b/go.mod @@ -259,6 +259,7 @@ require ( github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/Microsoft/hcsshim v0.11.4 // indirect github.com/ReneKroon/ttlcache/v2 v2.11.0 // indirect github.com/SAP/go-hdb v1.6.2 // indirect github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2 // indirect @@ -313,8 +314,10 @@ require ( github.com/cloudfoundry-incubator/uaago v0.0.0-20190307164349-8136b7bbe76e // indirect github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect + github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/cgroups/v3 v3.0.2 // indirect github.com/containerd/console v1.0.3 // indirect + github.com/containerd/containerd v1.7.7 // indirect github.com/containerd/ttrpc v1.2.2 // indirect github.com/coreos/go-oidc v2.2.1+incompatible // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect diff --git a/go.sum b/go.sum index e86f13330a0d..1c7e64bc2975 100644 --- a/go.sum +++ b/go.sum @@ -229,7 +229,8 @@ github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYr github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/Microsoft/hcsshim v0.11.1 h1:hJ3s7GbWlGK4YVV92sO88BQSyF4ZLVy7/awqOlPxFbA= +github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= +github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/Netflix/go-env v0.0.0-20220526054621-78278af1949d h1:wvStE9wLpws31NiWUx+38wny1msZ/tm+eL5xmm4Y7So= github.com/Netflix/go-env v0.0.0-20220526054621-78278af1949d/go.mod h1:9XMFaCeRyW7fC9XJOWQ+NdAv8VLG7ys7l3x4ozEGLUQ= @@ -459,11 +460,14 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= +github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= github.com/containerd/cgroups/v3 v3.0.2 h1:f5WFqIVSgo5IZmtTT3qVBo6TzI1ON6sycSBKkymb9L0= github.com/containerd/cgroups/v3 v3.0.2/go.mod h1:JUgITrzdFqp42uI2ryGA+ge0ap/nxzYgkGmIcetmErE= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/containerd/containerd v1.7.7 h1:QOC2K4A42RQpcrZyptP6z9EJZnlHfHJUfZrAAHe15q4= +github.com/containerd/containerd v1.7.7/go.mod h1:3c4XZv6VeT9qgf9GMTxNTMFxGJrGpI2vz1yk4ye+YY8= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/ttrpc v1.2.2 h1:9vqZr0pxwOF5koz6N0N3kJ0zDHokrcPxIR/ZR2YFtOs= github.com/containerd/ttrpc v1.2.2/go.mod h1:sIT6l32Ph/H9cvnJsfXM5drIVzTr5A2flTf1G5tYZak= diff --git a/receiver/awscontainerinsightreceiver/go.mod b/receiver/awscontainerinsightreceiver/go.mod index f1b75b124c2f..cd8dfb78f2b6 100644 --- a/receiver/awscontainerinsightreceiver/go.mod +++ b/receiver/awscontainerinsightreceiver/go.mod @@ -3,12 +3,13 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscon go 1.20 require ( + github.com/Microsoft/hcsshim v0.11.4 github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws v0.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go v1.47.10 github.com/go-kit/log v0.2.1 github.com/google/cadvisor v0.48.1 github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0 - github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0 + github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.89.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics v0.89.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.89.0 @@ -32,6 +33,7 @@ require ( k8s.io/client-go v0.28.3 k8s.io/klog v1.0.0 k8s.io/kubelet v0.28.3 + ) require ( @@ -51,9 +53,11 @@ require ( github.com/blang/semver/v4 v4.0.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/checkpoint-restore/go-criu/v5 v5.3.0 // indirect - github.com/cilium/ebpf v0.7.0 // indirect + github.com/cilium/ebpf v0.9.1 // indirect github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect + github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/console v1.0.3 // indirect + github.com/containerd/containerd v1.6.23 // indirect github.com/containerd/ttrpc v1.2.2 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect @@ -71,7 +75,6 @@ require ( github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/fatih/color v1.15.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/frankban/quicktest v1.14.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/go-logr/logr v1.3.0 // indirect @@ -149,10 +152,10 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.89.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.89.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.0.2 // indirect + github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect github.com/opencontainers/runc v1.1.9 // indirect github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 // indirect - github.com/opencontainers/selinux v1.10.0 // indirect + github.com/opencontainers/selinux v1.10.1 // indirect github.com/openshift/api v3.9.0+incompatible // indirect github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // indirect github.com/ovh/go-ovh v1.4.3 // indirect @@ -174,8 +177,8 @@ require ( github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect - github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 // indirect - github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect + github.com/vishvananda/netlink v1.2.1-beta.2 // indirect + github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect github.com/vultr/govultr/v2 v2.17.2 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.opencensus.io v0.24.0 // indirect diff --git a/receiver/awscontainerinsightreceiver/go.sum b/receiver/awscontainerinsightreceiver/go.sum index 9c713f254065..0261b640f043 100644 --- a/receiver/awscontainerinsightreceiver/go.sum +++ b/receiver/awscontainerinsightreceiver/go.sum @@ -66,6 +66,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= +github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= @@ -103,16 +105,20 @@ github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAc github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/cilium/ebpf v0.7.0 h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k= -github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA= +github.com/cilium/ebpf v0.9.1 h1:64sn2K3UKw8NbP/blsixRpF3nXuyhz/VjRlRzvlBRu4= +github.com/cilium/ebpf v0.9.1/go.mod h1:+OhNOIXx/Fnu1IE8bJz2dzOA+VSfyTfdNUVdlQnxUFY= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= +github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= +github.com/containerd/containerd v1.6.23 h1:KYJd6UJhKHzwMhiD70iTtSmU+k4565ac22GOTI3AuTA= +github.com/containerd/containerd v1.6.23/go.mod h1:UrQOiyzrLi3n4aezYJbQH6Il+YzTvnHFbEuO3yfDrM4= github.com/containerd/ttrpc v1.2.2 h1:9vqZr0pxwOF5koz6N0N3kJ0zDHokrcPxIR/ZR2YFtOs= github.com/containerd/ttrpc v1.2.2/go.mod h1:sIT6l32Ph/H9cvnJsfXM5drIVzTr5A2flTf1G5tYZak= github.com/containerd/typeurl v1.0.2 h1:Chlt8zIieDbzQFzXzAeBEF92KhExuE4p9p92/QmY7aY= @@ -165,9 +171,7 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss= -github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= @@ -416,7 +420,6 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= @@ -506,14 +509,14 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= -github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8= +github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= github.com/opencontainers/runc v1.1.9 h1:XR0VIHTGce5eWPkaPesqTBrhW2yAcaraWfsEalNwQLM= github.com/opencontainers/runc v1.1.9/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 h1:R5M2qXZiK/mWPMT4VldCOiSL9HIAMuxQZWdG0CSM5+4= github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU= -github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI= +github.com/opencontainers/selinux v1.10.1 h1:09LIPVRP3uuZGQvgR+SgMSNBd1Eb3vlRbGqQpoHsF8w= +github.com/opencontainers/selinux v1.10.1/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI= github.com/openshift/api v0.0.0-20180801171038-322a19404e37 h1:05irGU4HK4IauGGDbsk+ZHrm1wOzMLYjMlfaiqMrBYc= github.com/openshift/api v0.0.0-20180801171038-322a19404e37/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY= github.com/openshift/api v0.0.0-20210521075222-e273a339932a/go.mod h1:izBmoXbUu3z5kUa4FjZhvekTsyzIWiOoaIgJiZBBMQs= @@ -572,7 +575,6 @@ github.com/prometheus/prometheus v0.48.0 h1:yrBloImGQ7je4h8M10ujGh4R6oxYQJQKlMuE github.com/prometheus/prometheus v0.48.0/go.mod h1:SRw624aMAxTfryAcP8rOjg4S/sHHaetx2lyJJ2nM83g= github.com/prometheus/statsd_exporter v0.22.7 h1:7Pji/i2GuhK6Lu7DHrtTkFmNBCudCPT1pX2CziuyQR0= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo= github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= @@ -629,10 +631,11 @@ github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0h github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 h1:cPXZWzzG0NllBLdjWoD1nDfaqu98YMv+OneaKc8sPOA= -github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= -github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae h1:4hwBBUfQCFe3Cym0ZtKyq7L16eZUtYKs+BaHDN6mAns= +github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs= +github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA= +github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vultr/govultr/v2 v2.17.2 h1:gej/rwr91Puc/tgh+j33p/BLR16UrIPnSr+AIwYWZQs= github.com/vultr/govultr/v2 v2.17.2/go.mod h1:ZFOKGWmgjytfyjeyAdhQlSWwTjh2ig+X49cAp50dzXI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -882,7 +885,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1085,7 +1087,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= +gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/cpu_extractor.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/cpu_extractor.go index 85d11c4338d2..09b00c540b5f 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/cpu_extractor.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/cpu_extractor.go @@ -32,6 +32,8 @@ func (c *CPUMetricExtractor) GetValue(rawMetric RawMetric, mInfo cExtractor.CPUM multiplier := float64(decimalToMillicores) identifier := rawMetric.Id cExtractor.AssignRateValueToField(&c.rateCalculator, metric.GetFields(), ci.MetricName(containerType, ci.CPUTotal), identifier, float64(rawMetric.CPUStats.UsageCoreNanoSeconds), rawMetric.Time, multiplier) + cExtractor.AssignRateValueToField(&c.rateCalculator, metric.GetFields(), ci.MetricName(containerType, ci.CPUUser), identifier, float64(rawMetric.CPUStats.UserCPUUsage), rawMetric.Time, multiplier) + cExtractor.AssignRateValueToField(&c.rateCalculator, metric.GetFields(), ci.MetricName(containerType, ci.CPUSystem), identifier, float64(rawMetric.CPUStats.SystemCPUUsage), rawMetric.Time, multiplier) numCores := mInfo.GetNumCores() if metric.GetField(ci.MetricName(containerType, ci.CPUTotal)) != nil && numCores != 0 { diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractor.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractor.go index 8512892d9702..a1b2fe3583de 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractor.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractor.go @@ -4,6 +4,8 @@ import ( "time" cExtractor "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors" + + "github.com/Microsoft/hcsshim" ) // CPUStat for Pod, Container and Node. @@ -11,6 +13,8 @@ type CPUStat struct { Time time.Time UsageNanoCores uint64 UsageCoreNanoSeconds uint64 + UserCPUUsage uint64 + SystemCPUUsage uint64 } // MemoryStat for Pod, Container and Node @@ -24,6 +28,7 @@ type MemoryStat struct { MajorPageFaults uint64 } +// FileSystemStat for Container and Node. type FileSystemStat struct { Time time.Time AvailableBytes uint64 @@ -31,13 +36,36 @@ type FileSystemStat struct { UsedBytes uint64 } +// NetworkStat for Pod and Node. type NetworkStat struct { - Time time.Time - Name string - RxBytes uint64 - RxErrors uint64 - TxBytes uint64 - TxErrors uint64 + Time time.Time + Name string + RxBytes uint64 + RxErrors uint64 + TxBytes uint64 + TxErrors uint64 + DroppedIncoming uint64 + DroppedOutgoing uint64 +} + +// HCSNetworkStat Network Stat from HCS. +type HCSNetworkStat struct { + Name string + BytesReceived uint64 + BytesSent uint64 + DroppedPacketsIncoming uint64 + DroppedPacketsOutgoing uint64 +} + +// HCSStat Stats from HCS. +type HCSStat struct { + Time time.Time + Id string + Name string + + CPU *hcsshim.ProcessorStats + + Network *[]HCSNetworkStat } // RawMetric Represent Container, Pod, Node Metric Extractors. diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractorhelpers.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractorhelpers.go index 8047a1b35310..f4c50ef437a2 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractorhelpers.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/extractorhelpers.go @@ -18,6 +18,7 @@ func convertCPUStats(kubeletCPUStat stats.CPUStats) CPUStat { if kubeletCPUStat.UsageNanoCores != nil { cpuStat.UsageNanoCores = *kubeletCPUStat.UsageNanoCores } + return cpuStat } @@ -96,6 +97,21 @@ func convertNetworkStats(kubeletNetworkStat stats.NetworkStats, kubeletIntfStat return networkstat } +// convertHCSNetworkStats Convert HCS network system stats to Raw network stats +func convertHCSNetworkStats(stat HCSStat, networkStat HCSNetworkStat) NetworkStat { + var networkstat NetworkStat + + networkstat.Time = stat.Time + + networkstat.Name = networkStat.Name + networkstat.TxBytes = networkStat.BytesSent + networkstat.RxBytes = networkStat.BytesReceived + networkstat.DroppedIncoming = networkStat.DroppedPacketsIncoming + networkstat.DroppedOutgoing = networkStat.DroppedPacketsOutgoing + + return networkstat +} + // ConvertPodToRaw Converts Kubelet Pod stats to RawMetric. func ConvertPodToRaw(podStat stats.PodStats) RawMetric { var rawMetic RawMetric @@ -188,3 +204,20 @@ func ConvertNodeToRaw(nodeStat stats.NodeStats) RawMetric { return rawMetic } + +// ConvertHCSContainerToRaw Converts HCS Container stats to RawMetric. +func ConvertHCSContainerToRaw(containerStat HCSStat) RawMetric { + var rawMetic RawMetric + + rawMetic.Id = containerStat.Id + rawMetic.Name = containerStat.Name + rawMetic.Time = containerStat.Time + + if containerStat.Network != nil { + for _, val := range *containerStat.Network { + rawMetic.NetworkStats = append(rawMetic.NetworkStats, convertHCSNetworkStats(containerStat, val)) + } + } + + return rawMetic +} diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor.go index 4fe48580a50f..30ec0fa94c30 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor.go @@ -35,6 +35,7 @@ func (n *NetMetricExtractor) GetValue(rawMetric RawMetric, mInfo cExtractor.CPUM netIfceMetrics := make([]map[string]any, len(rawMetric.NetworkStats)) for i, intf := range rawMetric.NetworkStats { + mType := getNetMetricType(containerType, n.logger) netIfceMetric := make(map[string]any) identifier := rawMetric.Id + containerType + intf.Name @@ -44,12 +45,22 @@ func (n *NetMetricExtractor) GetValue(rawMetric RawMetric, mInfo cExtractor.CPUM cExtractor.AssignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetRxErrors, identifier, float64(intf.RxErrors), rawMetric.Time, multiplier) cExtractor.AssignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetTxBytes, identifier, float64(intf.TxBytes), rawMetric.Time, multiplier) cExtractor.AssignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetTxErrors, identifier, float64(intf.TxErrors), rawMetric.Time, multiplier) + cExtractor.AssignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetRxDropped, identifier, float64(intf.DroppedIncoming), rawMetric.Time, multiplier) + cExtractor.AssignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetTxDropped, identifier, float64(intf.DroppedOutgoing), rawMetric.Time, multiplier) if netIfceMetric[ci.NetRxBytes] != nil && netIfceMetric[ci.NetTxBytes] != nil { netIfceMetric[ci.NetTotalBytes] = netIfceMetric[ci.NetRxBytes].(float64) + netIfceMetric[ci.NetTxBytes].(float64) } netIfceMetrics[i] = netIfceMetric + + metric := cExtractor.NewCadvisorMetric(mType, n.logger) + metric.AddTag(ci.NetIfce, intf.Name) + for k, v := range netIfceMetric { + metric.AddField(ci.MetricName(mType, k), v) + } + + metrics = append(metrics, metric) } aggregatedFields := ci.SumFields(netIfceMetrics) diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor_test.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor_test.go index 0d9298b89926..2ad55976c3f5 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor_test.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/net_extractor_test.go @@ -33,22 +33,128 @@ func TestNetStats(t *testing.T) { } expectedFields := []map[string]any{ + { + "node_interface_network_rx_bytes": float64(3474.633333333333), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(5477.549999999999), + "node_interface_network_tx_bytes": float64(2002.9166666666665), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(2293.733333333333), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(4781.45), + "node_interface_network_tx_bytes": float64(2487.7166666666667), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(0), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(0), + "node_interface_network_tx_bytes": float64(0), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(0), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(0), + "node_interface_network_tx_bytes": float64(0), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(0), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(0), + "node_interface_network_tx_bytes": float64(0), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(0), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(0), + "node_interface_network_tx_bytes": float64(0), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(0), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(0), + "node_interface_network_tx_bytes": float64(0), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, + { + "node_interface_network_rx_bytes": float64(0), + "node_interface_network_rx_dropped": float64(0), + "node_interface_network_rx_errors": float64(0), + "node_interface_network_total_bytes": float64(0), + "node_interface_network_tx_bytes": float64(0), + "node_interface_network_tx_dropped": float64(0), + "node_interface_network_tx_errors": float64(0), + }, { "node_network_rx_bytes": float64(5768.366666666667), + "node_network_rx_dropped": float64(0), "node_network_rx_errors": float64(0), "node_network_total_bytes": float64(10259), "node_network_tx_bytes": float64(4490.633333333333), + "node_network_tx_dropped": float64(0), "node_network_tx_errors": float64(0), }, } expectedTags := []map[string]string{ + { + "Type": "NodeNet", + "interface": "Amazon Elastic Network Adapter", + }, + { + "Type": "NodeNet", + "interface": "Hyper-V Virtual Ethernet Adapter", + }, + { + "Type": "NodeNet", + "interface": "Teredo Tunneling Pseudo-Interface", + }, + { + "Type": "NodeNet", + "interface": "AWS PV Network Device", + }, + { + "Type": "NodeNet", + "interface": "Microsoft IP-HTTPS Platform Interface", + }, + { + "Type": "NodeNet", + "interface": "Hyper-V Virtual Switch Extension Adapter", + }, + { + "Type": "NodeNet", + "interface": "Microsoft Kernel Debug Network Adapter", + }, + { + "Type": "NodeNet", + "interface": "6to4 Adapter", + }, { "Type": "Node", }, } - assert.Equal(t, len(cMetrics), 1) + assert.Equal(t, len(cMetrics), 9) for i := range expectedFields { cExtractor.AssertContainsTaggedField(t, cMetrics[i], expectedFields[i], expectedTags[i]) } @@ -69,22 +175,38 @@ func TestNetStats(t *testing.T) { } expectedFields = []map[string]any{ + { + "pod_interface_network_rx_bytes": float64(1735.9333333333334), + "pod_interface_network_rx_dropped": float64(0), + "pod_interface_network_rx_errors": float64(0), + "pod_interface_network_total_bytes": float64(1903.75), + "pod_interface_network_tx_bytes": float64(167.81666666666666), + "pod_interface_network_tx_dropped": float64(0), + "pod_interface_network_tx_errors": float64(0), + }, + { "pod_network_rx_bytes": float64(1735.9333333333334), + "pod_network_rx_dropped": float64(0), "pod_network_rx_errors": float64(0), "pod_network_total_bytes": float64(1903.75), "pod_network_tx_bytes": float64(167.81666666666666), + "pod_network_tx_dropped": float64(0), "pod_network_tx_errors": float64(0), }, } expectedTags = []map[string]string{ + { + "Type": "PodNet", + "interface": "cid-ccecfbf3-5ecf-4d93-9229-3f2f0df1b6b5", + }, { "Type": "Pod", }, } - assert.Equal(t, len(cMetrics), 1) + assert.Equal(t, len(cMetrics), 2) for i := range expectedFields { cExtractor.AssertContainsTaggedField(t, cMetrics[i], expectedFields[i], expectedTags[i]) } diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/client.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/client.go new file mode 100644 index 000000000000..ec7baf990562 --- /dev/null +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/client.go @@ -0,0 +1,54 @@ +package hcsshim + +import ( + "fmt" + + "github.com/Microsoft/hcsshim" + "go.uber.org/zap" +) + +type HCSClient interface { + GetContainerStats(containerId string) (hcsshim.Statistics, error) + GetEndpointList() ([]hcsshim.HNSEndpoint, error) + GetEndpointStat(endpointId string) (hcsshim.HNSEndpointStats, error) +} +type hCSClient struct { + logger *zap.Logger +} + +func (hc *hCSClient) GetContainerStats(containerId string) (hcsshim.Statistics, error) { + container, err := hcsshim.OpenContainer(containerId) + if err != nil { + hc.logger.Error("failed to open container using HCS shim APIs, ", zap.Error(err)) + return hcsshim.Statistics{}, err + } + defer container.Close() + cps, err := container.Statistics() + if err != nil { + hc.logger.Error("failed to get container stats from HCS shim APIs, ", zap.Error(err)) + return hcsshim.Statistics{}, err + } + + return cps, nil +} + +func (hc *hCSClient) GetEndpointList() ([]hcsshim.HNSEndpoint, error) { + endpointList, err := hcsshim.HNSListEndpointRequest() + if err != nil { + hc.logger.Error("failed to list endpoints using HNS APIs, ", zap.Error(err)) + return []hcsshim.HNSEndpoint{}, err + } + return endpointList, nil +} + +func (hc *hCSClient) GetEndpointStat(endpointId string) (hcsshim.HNSEndpointStats, error) { + endpointStat, err := hcsshim.GetHNSEndpointStats(endpointId) + if err != nil { + hc.logger.Error("failed to get HNS endpoint stats, ", zap.Error(err)) + return hcsshim.HNSEndpointStats{}, err + } + if endpointStat != nil { + return *endpointStat, nil + } + return hcsshim.HNSEndpointStats{}, fmt.Errorf("no stats for endpoint") +} diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go new file mode 100644 index 000000000000..ba951c2c92b7 --- /dev/null +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go @@ -0,0 +1,213 @@ +//go:build windows +// +build windows + +package hcsshim // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8s_windox2" + +import ( + "fmt" + "strconv" + "strings" + + ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight" + cExtractor "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet" + + "go.uber.org/zap" + "golang.org/x/exp/slices" +) + +type PodKey struct { + PodId, PodName, PodNamespace string + Containers []ContainerInfo +} + +type ContainerInfo struct { + Name, Id string +} + +type EndpointInfo struct { + Id, Name string +} + +type HCSStatsProvider struct { + logger *zap.Logger + hostInfo cExtractor.CPUMemInfoProvider + hcsClient HCSClient + kubeletProvider kubelet.KubeletProvider + metricExtractors []extractors.MetricExtractor + containerToEndpoint map[string]EndpointInfo +} + +func createHCSClient(logger *zap.Logger) HCSClient { + return &hCSClient{logger: logger} +} + +// Options decorates SummaryProvider struct. +type Options func(provider *HCSStatsProvider) + +func NewHnSProvider(logger *zap.Logger, info cExtractor.CPUMemInfoProvider, mextractor []extractors.MetricExtractor, opts ...Options) (*HCSStatsProvider, error) { + hp := &HCSStatsProvider{ + logger: logger, + hostInfo: info, + kubeletProvider: kubelet.CreateDefaultKubeletProvider(logger), + hcsClient: createHCSClient(logger), + metricExtractors: mextractor, + } + + for _, opt := range opts { + opt(hp) + } + + return hp, nil +} + +func (hp *HCSStatsProvider) GetMetrics() ([]*cExtractor.CAdvisorMetric, error) { + containerToEndpointMap, err := hp.getContainerToEndpointMap() + if err != nil { + hp.logger.Error("failed to create container to endpoint map using HCS shim APIs, ", zap.Error(err)) + return nil, err + } + hp.containerToEndpoint = containerToEndpointMap + return hp.getPodMetrics() +} + +func (hp *HCSStatsProvider) getContainerMetrics(containerId string) (extractors.HCSStat, error) { + hp.logger.Debug("Getting Container stats using Microsoft HCS shim APIs") + + cps, err := hp.hcsClient.GetContainerStats(containerId) + if err != nil { + hp.logger.Error("failed to get container stats from HCS shim client, ", zap.Error(err)) + return extractors.HCSStat{}, err + } + + if _, ok := hp.containerToEndpoint[containerId]; !ok { + hp.logger.Warn("HNS endpoint not found ", zap.String("container", containerId)) + return extractors.HCSStat{}, nil + } + + endpoint := hp.containerToEndpoint[containerId] + enpointStat, err := hp.hcsClient.GetEndpointStat(endpoint.Id) + if err != nil { + hp.logger.Error("failed to get HNS endpoint stats, ", zap.Error(err)) + return extractors.HCSStat{}, err + } + var hnsNetworks []extractors.HCSNetworkStat + + hnsNetworks = append(hnsNetworks, extractors.HCSNetworkStat{ + Name: endpoint.Name, + BytesReceived: enpointStat.BytesReceived, + BytesSent: enpointStat.BytesSent, + DroppedPacketsOutgoing: enpointStat.DroppedPacketsOutgoing, + DroppedPacketsIncoming: enpointStat.DroppedPacketsIncoming, + }) + + stat := extractors.HCSStat{Time: cps.Timestamp, CPU: &cps.Processor, Network: &hnsNetworks} + hp.logger.Debug("Returning Container stats using Microsoft HCS shim APIs") + return stat, nil +} + +func (hp *HCSStatsProvider) getPodMetrics() ([]*cExtractor.CAdvisorMetric, error) { + hp.logger.Debug("Getting pod stats using Microsoft HCS shim APIs") + podToContainerMap, err := hp.getPodToContainerMap() + if err != nil { + hp.logger.Error("failed to create pod to container map using kubelet APIs, ", zap.Error(err)) + return nil, err + } + + var metrics []*cExtractor.CAdvisorMetric + var endpointMetricsCollected []string + + for _, pod := range podToContainerMap { + var metricsPerPod []*cExtractor.CAdvisorMetric + tags := map[string]string{} + + tags[ci.PodIDKey] = pod.PodId + tags[ci.K8sPodNameKey] = pod.PodName + tags[ci.K8sNamespace] = pod.PodNamespace + + for _, container := range pod.Containers { + if _, ok := hp.containerToEndpoint[container.Id]; !ok { + hp.logger.Debug("Skipping as endpoint don't exist for container") + continue + } + endpoint := hp.containerToEndpoint[container.Id] + if slices.Contains(endpointMetricsCollected, endpoint.Id) { + hp.logger.Debug("Skipping as metric already collected for HNS Endpoint") + continue + } + + containerStats, err := hp.getContainerMetrics(container.Id) + if err != nil { + hp.logger.Warn("failed to get container metrics using HCS shim APIs, ", zap.Error(err)) + continue + } + + rawMetric := extractors.ConvertHCSContainerToRaw(containerStats) + tags[ci.Timestamp] = strconv.FormatInt(rawMetric.Time.UnixNano(), 10) + + for _, extractor := range hp.metricExtractors { + if extractor.HasValue(rawMetric) { + metricsPerPod = append(metricsPerPod, extractor.GetValue(rawMetric, hp.hostInfo, ci.TypePod)...) + } + } + endpointMetricsCollected = append(endpointMetricsCollected, hp.containerToEndpoint[container.Id].Id) + } + for _, metric := range metricsPerPod { + metric.AddTags(tags) + } + metrics = append(metrics, metricsPerPod...) + } + + return metrics, nil +} + +func (hp *HCSStatsProvider) getPodToContainerMap() (map[string]PodKey, error) { + containerNameToIdMapping := make(map[string]PodKey) + podList, err := hp.kubeletProvider.GetPods() + if err != nil { + hp.logger.Error("failed to get pod list from kubelet provider, ", zap.Error(err)) + return nil, err + } + for _, pod := range podList { + podId := fmt.Sprintf("%s", pod.UID) + podKey := PodKey{ + PodId: podId, + PodName: pod.Name, + PodNamespace: pod.Namespace, + } + if _, ok := containerNameToIdMapping[podId]; !ok { + containerNameToIdMapping[podId] = podKey + } + + for _, container := range pod.Status.ContainerStatuses { + if strings.Contains(container.ContainerID, "containerd") { + cinfo := ContainerInfo{ + Id: strings.Split(container.ContainerID, "containerd://")[1], + Name: container.Name, + } + podKey.Containers = append(podKey.Containers, cinfo) + } + } + containerNameToIdMapping[podId] = podKey + } + + return containerNameToIdMapping, nil +} + +func (hp *HCSStatsProvider) getContainerToEndpointMap() (map[string]EndpointInfo, error) { + var containerToEndpointMap = make(map[string]EndpointInfo) + endpointList, err := hp.hcsClient.GetEndpointList() + if err != nil { + hp.logger.Error("failed to get endpoints list from HCS shim client, ", zap.Error(err)) + return containerToEndpointMap, err + } + + for _, endpoint := range endpointList { + for _, container := range endpoint.SharedContainers { + containerToEndpointMap[container] = EndpointInfo{Id: endpoint.Id, Name: endpoint.Name} + } + } + + return containerToEndpointMap, nil +} diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go new file mode 100644 index 000000000000..39e52a359785 --- /dev/null +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go @@ -0,0 +1,147 @@ +package hcsshim + +import ( + "testing" + "time" + + ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight" + cTestUtils "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/testutils" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/testutils" + + "github.com/Microsoft/hcsshim" + "github.com/stretchr/testify/assert" + "go.uber.org/zap" + "go.uber.org/zap/zaptest" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" +) + +// MockKubeletProvider Mock provider implements KubeletProvider interface. +type MockHCSClient struct { + logger *zap.Logger + t *testing.T +} + +// MockKubeletProvider Mock provider implements KubeletProvider interface. +type MockKubeletProvider struct { + logger *zap.Logger + t *testing.T +} + +func (m *MockHCSClient) GetContainerStats(containerId string) (hcsshim.Statistics, error) { + return hcsshim.Statistics{ + Timestamp: time.Now(), + }, nil +} + +func (m *MockHCSClient) GetEndpointList() ([]hcsshim.HNSEndpoint, error) { + return []hcsshim.HNSEndpoint{{ + Id: "endpointId123456c6asdfasdf4354545", + Name: "cid-adfklq3qr43lj523l4daf", + SharedContainers: []string{"1234123412341afasdfa12342343134", "kaljsflasdjf1234123412341afasdfa12342343134"}, + }}, nil +} + +func (m *MockHCSClient) GetEndpointStat(endpointId string) (hcsshim.HNSEndpointStats, error) { + return hcsshim.HNSEndpointStats{ + BytesReceived: 44340, + BytesSent: 3432, + DroppedPacketsIncoming: 43, + DroppedPacketsOutgoing: 1, + EndpointID: "endpointId123456c6asdfasdf4354545", + }, nil +} + +func (m *MockKubeletProvider) GetSummary() (*stats.Summary, error) { + return testutils.LoadKubeletSummary(m.t, "./../extractors/testdata/CurSingleKubeletSummary.json"), nil +} + +func (m *MockKubeletProvider) GetPods() ([]corev1.Pod, error) { + mockPods := []corev1.Pod{} + + mockPods = append(mockPods, corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + UID: "podidq3erqwezdfa3q34q34dfdf", + Name: "mockPod", + Namespace: "default", + }, + Status: corev1.PodStatus{ContainerStatuses: []corev1.ContainerStatus{{ + Name: "mockContainername", + ContainerID: "containerd://1234123412341afasdfa12342343134", + }}}}) + return mockPods, nil +} + +func createKubeletDecoratorWithMockKubeletProvider(t *testing.T, logger *zap.Logger) Options { + return func(provider *HCSStatsProvider) { + provider.kubeletProvider = &MockKubeletProvider{t: t, logger: logger} + } +} + +func createHCSDecoratorWithMockHCSClient(t *testing.T, logger *zap.Logger) Options { + return func(provider *HCSStatsProvider) { + provider.hcsClient = &MockHCSClient{t: t, logger: logger} + } +} + +func mockInfoProvider() cTestUtils.MockHostInfo { + hostInfo := cTestUtils.MockHostInfo{ClusterName: "cluster"} + return hostInfo +} + +func mockMetricExtractors(t *testing.T) []extractors.MetricExtractor { + metricsExtractors := []extractors.MetricExtractor{} + metricsExtractors = append(metricsExtractors, extractors.NewNetMetricExtractor(zaptest.NewLogger(t))) + return metricsExtractors +} + +func TestGetContainerToEndpointMap(t *testing.T) { + hsp, err := NewHnSProvider(zaptest.NewLogger(t), mockInfoProvider(), mockMetricExtractors(t), createKubeletDecoratorWithMockKubeletProvider(t, zaptest.NewLogger(t)), createHCSDecoratorWithMockHCSClient(t, zaptest.NewLogger(t))) + assert.NoError(t, err) + + containerEndpointMap, err := hsp.getContainerToEndpointMap() + + assert.NoError(t, err) + + assert.Len(t, containerEndpointMap, 2) + assert.Contains(t, containerEndpointMap, "1234123412341afasdfa12342343134") + assert.Contains(t, containerEndpointMap, "kaljsflasdjf1234123412341afasdfa12342343134") +} + +func TestGetPodToContainerMap(t *testing.T) { + hsp, err := NewHnSProvider(zaptest.NewLogger(t), mockInfoProvider(), mockMetricExtractors(t), createKubeletDecoratorWithMockKubeletProvider(t, zaptest.NewLogger(t)), createHCSDecoratorWithMockHCSClient(t, zaptest.NewLogger(t))) + assert.NoError(t, err) + + podContainerMap, err := hsp.getPodToContainerMap() + + assert.NoError(t, err) + + assert.Len(t, podContainerMap, 1) + assert.Contains(t, podContainerMap, "podidq3erqwezdfa3q34q34dfdf") + assert.Len(t, podContainerMap["podidq3erqwezdfa3q34q34dfdf"].Containers, 1) + assert.Equal(t, podContainerMap["podidq3erqwezdfa3q34q34dfdf"].Containers[0].Id, "1234123412341afasdfa12342343134") +} + +func TestGetPodMetrics(t *testing.T) { + hsp, err := NewHnSProvider(zaptest.NewLogger(t), mockInfoProvider(), mockMetricExtractors(t), createKubeletDecoratorWithMockKubeletProvider(t, zaptest.NewLogger(t)), createHCSDecoratorWithMockHCSClient(t, zaptest.NewLogger(t))) + assert.NoError(t, err) + + containerToEndpointMap, err := hsp.getContainerToEndpointMap() + assert.NoError(t, err) + hsp.containerToEndpoint = containerToEndpointMap + + metrics, err := hsp.getPodMetrics() + assert.NoError(t, err) + + assert.Equal(t, len(metrics), 1) + podMetric := metrics[0] + assert.Equal(t, podMetric.GetMetricType(), ci.TypePodNet) + assert.NotNil(t, podMetric.GetTag(ci.PodIDKey)) + assert.NotNil(t, podMetric.GetTag(ci.K8sPodNameKey)) + assert.NotNil(t, podMetric.GetTag(ci.K8sNamespace)) + assert.NotNil(t, podMetric.GetTag(ci.Timestamp)) + assert.NotNil(t, podMetric.GetTag(ci.SourcesKey)) + assert.NotNil(t, podMetric.GetTag(ci.NetIfce)) +} diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows.go index 5f21f83b5e76..8b12c1635ac9 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows.go @@ -15,6 +15,7 @@ import ( cExtractor "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/host" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim" kubeletsummaryprovider "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/stores" @@ -28,6 +29,7 @@ type K8sWindows struct { nodeName string `toml:"node_name"` k8sDecorator stores.K8sDecorator kubeletSummaryProvider *kubeletsummaryprovider.SummaryProvider + hcsshimStatsProvider *hcsshim.HCSStatsProvider hostInfo host.Info version string } @@ -52,11 +54,19 @@ func New(logger *zap.Logger, decorator *stores.K8sDecorator, hostInfo host.Info) return nil, err } + hnsMetricsExtractors := append([]extractors.MetricExtractor{}, extractors.NewNetMetricExtractor(logger)) + hsp, err := hcsshim.NewHnSProvider(logger, &hostInfo, hnsMetricsExtractors) + if err != nil { + logger.Error("failed to initialize HCSShim SummaryProvider, ", zap.Error(err)) + return nil, err + } + return &K8sWindows{ logger: logger, nodeName: nodeName, k8sDecorator: *decorator, kubeletSummaryProvider: ksp, + hcsshimStatsProvider: hsp, hostInfo: hostInfo, version: "0", }, nil @@ -71,6 +81,14 @@ func (k *K8sWindows) GetMetrics() []pmetric.Metrics { k.logger.Error("failed to get metrics from kubelet SummaryProvider, ", zap.Error(err)) return result } + + hcsmetrics, err := k.hcsshimStatsProvider.GetMetrics() + if err != nil { + k.logger.Error("failed to get metrics from HCSShim StatsProvider, ", zap.Error(err)) + return result + } + + metrics = append(metrics, hcsmetrics...) metrics = cExtractor.MergeMetrics(metrics) metrics = k.decorateMetrics(metrics) for _, ciMetric := range metrics { diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/client.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/client.go index b9c5a5d9d6e6..d470b2f7175b 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/client.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/client.go @@ -5,13 +5,16 @@ package kubelet import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil" + "go.uber.org/zap" + corev1 "k8s.io/api/core/v1" stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" ) // KubeletProvider Represents interface to kubelet. type KubeletProvider interface { GetSummary() (*stats.Summary, error) + GetPods() ([]corev1.Pod, error) } type kubeletProvider struct { @@ -50,3 +53,12 @@ func (kp *kubeletProvider) GetSummary() (*stats.Summary, error) { } return summary, nil } + +func (kp *kubeletProvider) GetPods() ([]corev1.Pod, error) { + kclient, err := kp.getClient() + if err != nil { + kp.logger.Error("failed to get kubelet client, ", zap.Error(err)) + return nil, err + } + return kclient.ListPods() +} diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go index ce7eaac08bc0..a4a8497c55e5 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go @@ -14,7 +14,6 @@ import ( ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight" cExtractor "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows/extractors" - "go.uber.org/zap" stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" ) @@ -27,7 +26,7 @@ type SummaryProvider struct { metricExtractors []extractors.MetricExtractor } -func createDefaultKubeletProvider(logger *zap.Logger) KubeletProvider { +func CreateDefaultKubeletProvider(logger *zap.Logger) KubeletProvider { return &kubeletProvider{logger: logger, hostIP: os.Getenv("HOST_IP"), hostPort: ci.KubeSecurePort} } @@ -38,13 +37,14 @@ func New(logger *zap.Logger, info cExtractor.CPUMemInfoProvider, mextractor []ex sp := &SummaryProvider{ logger: logger, hostInfo: info, - kubeletProvider: createDefaultKubeletProvider(logger), + kubeletProvider: CreateDefaultKubeletProvider(logger), metricExtractors: mextractor, } for _, opt := range opts { opt(sp) } + return sp, nil } @@ -99,6 +99,7 @@ func (sp *SummaryProvider) getContainerMetrics(pod stats.PodStats) ([]*cExtracto metric.AddTags(tags) } } + return metrics, nil } @@ -158,6 +159,5 @@ func (sp *SummaryProvider) getNodeMetrics(summary *stats.Summary) ([]*cExtractor metrics = append(metrics, extractor.GetValue(rawMetric, sp.hostInfo, ci.TypeNode)...) } } - return metrics, nil } diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go index c2e2791c2802..3d3a08b2fa10 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go @@ -7,7 +7,6 @@ package kubelet import ( - stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" "testing" ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight" @@ -17,6 +16,8 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/zap" + corev1 "k8s.io/api/core/v1" + stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" ) // MockKubeletProvider Mock provider implements KubeletProvider interface. @@ -29,6 +30,10 @@ func (m *MockKubeletProvider) GetSummary() (*stats.Summary, error) { return testutils.LoadKubeletSummary(m.t, "./../extractors/testdata/CurSingleKubeletSummary.json"), nil } +func (m *MockKubeletProvider) GetPods() ([]corev1.Pod, error) { + return []corev1.Pod{}, nil +} + func createKubeletDecoratorWithMockKubeletProvider(t *testing.T, logger *zap.Logger) Options { return func(provider *SummaryProvider) { provider.kubeletProvider = &MockKubeletProvider{t: t, logger: logger}