Skip to content

Commit

Permalink
Merge Container Insights on Windows to aws-cwa-dev with cherry-picked…
Browse files Browse the repository at this point in the history
… commits (#168)

Add support for Container Insights on Windows for EKS  

* Add kubelet summary API for Windows (#142)
* CPU extractors with unit tests (#146)
* Add memory extractors for pod and node level (#147)
* Define structs for CPU and Memory stats (#149)
* Add Container level metrics for CPU and memory resources. (#150)
* Add storage metrics for container and node level (#151)
* Add network metrics (#152)
* Enable awscontainerinsights receiver to run inside Host Process container (#153)
* Add HCS shim api as alternative source for metric provider (#154)
* Add check for host process container before reading from hcshim (#156)
* Fix CPU utilization percentage for Windows nodes (#161)
* Add List of Metrics for Windows + Design (#166)
* fix fstype (#164)
  • Loading branch information
KlwntSingh authored Feb 29, 2024
1 parent e89ec77 commit c9246c3
Show file tree
Hide file tree
Showing 61 changed files with 3,216 additions and 124 deletions.
2 changes: 1 addition & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ require (
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubelet v0.28.3 // indirect
k8s.io/kubelet v0.28.4 // indirect
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect
sigs.k8s.io/controller-runtime v0.16.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -521,7 +524,7 @@ require (
github.com/nginxinc/nginx-prometheus-exporter v0.8.1-0.20201110005315-f5a5f8086c19 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.89.0 // indirect
Expand Down Expand Up @@ -558,7 +561,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.12 // 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
Expand Down Expand Up @@ -625,8 +628,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
Expand Down
22 changes: 13 additions & 9 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -496,7 +499,7 @@ require (
github.com/nginxinc/nginx-prometheus-exporter v0.8.1-0.20201110005315-f5a5f8086c19 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.92.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.89.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.89.0 // indirect
Expand Down Expand Up @@ -696,7 +699,7 @@ require (
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubelet v0.28.3 // indirect
k8s.io/kubelet v0.28.4 // indirect
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect
sigs.k8s.io/controller-runtime v0.16.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
10 changes: 7 additions & 3 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions internal/aws/containerinsight/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const (
// We assume 50 micro-seconds is the minimal gap between two collected data sample to be valid to calculate delta
MinTimeDiff = 50 * time.Microsecond

// Environment variables
RunInContainer = "RUN_IN_CONTAINER"
RunAsHostProcessContainer = "RUN_AS_HOST_PROCESS_CONTAINER"
TrueValue = "True"

// Attribute names
InstanceID = "InstanceId"
InstanceType = "InstanceType"
Expand All @@ -26,6 +31,8 @@ const (
MetricType = "Type"
SourcesKey = "Sources"
Timestamp = "Timestamp"
OperatingSystem = "OperatingSystem"
OperatingSystemWindows = "windows"

// The following constants are used for metric name construction
CPUTotal = "cpu_usage_total"
Expand Down
11 changes: 11 additions & 0 deletions internal/aws/containerinsight/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package containerinsight // import "github.com/open-telemetry/opentelemetry-coll
import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -83,6 +85,15 @@ func IsPod(mType string) bool {
return false
}

func IsWindowsHostProcessContainer() bool {
// todo: Remove this workaround func when Windows AMIs has containerd 1.7 which solves upstream bug
// https://kubernetes.io/docs/tasks/configure-pod-container/create-hostprocess-pod/#containerd-v1-6
if runtime.GOOS == OperatingSystemWindows && os.Getenv(RunInContainer) == TrueValue && os.Getenv(RunAsHostProcessContainer) == TrueValue {
return true
}
return false
}

func getPrefixByMetricType(mType string) string {
prefix := ""
instancePrefix := "instance_"
Expand Down
12 changes: 12 additions & 0 deletions internal/aws/containerinsight/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package containerinsight
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -866,3 +867,14 @@ func TestConvertToOTLPMetricsForPodContainerStatusMetrics(t *testing.T) {
md = ConvertToOTLPMetrics(fields, tags, zap.NewNop())
checkMetricsAreExpected(t, md, fields, tags, expectedUnits)
}

func TestHostProcessContainer(t *testing.T) {
os.Setenv(RunInContainer, "True")
assert.Equal(t, IsWindowsHostProcessContainer(), false)

os.Setenv(RunAsHostProcessContainer, "True")
assert.Equal(t, IsWindowsHostProcessContainer(), true)

os.Unsetenv(RunInContainer)
os.Unsetenv(RunAsHostProcessContainer)
}
3 changes: 3 additions & 0 deletions internal/aws/k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.89.0
)

require (
Expand Down Expand Up @@ -56,6 +57,8 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight => ../../aws/containerinsight

retract (
v0.76.2
v0.76.1
Expand Down
Loading

0 comments on commit c9246c3

Please sign in to comment.