-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubelet summary API for Windows (amazon-contributing#142)
* Add pod level metric collection for Windows This PR defines code structure for metric provider which works on Windows. ### Changelog 1. Changed receiver.go in awscontainerinsights to run for Windows with metric provider. 2. Added summary API in kubeletclient 3. Add kubeletProvider to return metrics at different levels i.e. pod, contianer, node. 4. Updated hostInfo providers to run for Windows. 5. Updated ebsVolume Info provider to run for Windows. ## Todos: 1. Define correct ebsVolume Info provider for Windows 2. Change logic around k8s leader election to run for Windows
- Loading branch information
1 parent
c00ca1f
commit 4edef80
Showing
23 changed files
with
361 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
receiver/awscontainerinsightreceiver/internal/host/utilconst_windows.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !linux | ||
// +build !linux | ||
|
||
package host // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/host" | ||
|
||
// These variables are invalid for Windows | ||
const ( | ||
rootfs = "" | ||
hostProc = rootfs + "" | ||
hostMounts = hostProc + "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
receiver/awscontainerinsightreceiver/internal/host/utilsconst.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package host // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/host" | ||
|
||
const ( | ||
rootfs = "/rootfs" // the root directory "/" is mounted as "/rootfs" in container | ||
hostProc = rootfs + "/proc" // "/rootfs/proc" in container refers to the host proc directory "/proc" | ||
hostMounts = hostProc + "/mounts" // "/rootfs/proc/mounts" in container refers to "/proc/mounts" in the host | ||
) |
111 changes: 111 additions & 0 deletions
111
receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build windows | ||
// +build windows | ||
|
||
package k8swindows // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
|
||
ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight" | ||
"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/stores" | ||
|
||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type K8sWindows struct { | ||
cancel context.CancelFunc | ||
logger *zap.Logger | ||
nodeName string `toml:"node_name"` | ||
k8sDecorator stores.K8sDecorator | ||
summaryProvider *kubeletSummaryProvider | ||
hostInfo host.Info | ||
} | ||
|
||
func New(logger *zap.Logger, decorator *stores.K8sDecorator, hostInfo host.Info) (*K8sWindows, error) { | ||
nodeName := os.Getenv("HOST_NAME") | ||
if nodeName == "" { | ||
return nil, errors.New("missing environment variable HOST_NAME. Please check your deployment YAML config") | ||
} | ||
k8sSummaryProvider, err := new(logger, hostInfo) | ||
if err != nil { | ||
logger.Error("failed to initialize kubelet summary provider, ", zap.Error(err)) | ||
return nil, err | ||
} | ||
return &K8sWindows{ | ||
logger: logger, | ||
nodeName: nodeName, | ||
k8sDecorator: *decorator, | ||
summaryProvider: k8sSummaryProvider, | ||
hostInfo: hostInfo, | ||
}, nil | ||
} | ||
|
||
func (k *K8sWindows) GetMetrics() []pmetric.Metrics { | ||
k.logger.Debug("D! called K8sWindows GetMetrics") | ||
var result []pmetric.Metrics | ||
|
||
metrics, err := k.summaryProvider.getMetrics() | ||
if err != nil { | ||
k.logger.Error("error getting metrics from kubelet summary provider, ", zap.Error(err)) | ||
return result | ||
} | ||
metrics = k.decorateMetrics(metrics) | ||
for _, k8sSummaryMetric := range metrics { | ||
md := ci.ConvertToOTLPMetrics(k8sSummaryMetric.GetFields(), k8sSummaryMetric.GetTags(), k.logger) | ||
result = append(result, md) | ||
} | ||
|
||
return result | ||
} | ||
|
||
func (c *K8sWindows) decorateMetrics(cadvisormetrics []*extractors.CAdvisorMetric) []*extractors.CAdvisorMetric { | ||
//ebsVolumeIdsUsedAsPV := c.hostInfo.ExtractEbsIDsUsedByKubernetes() | ||
var result []*extractors.CAdvisorMetric | ||
for _, m := range cadvisormetrics { | ||
tags := m.GetTags() | ||
//c.addEbsVolumeInfo(tags, ebsVolumeIdsUsedAsPV) | ||
|
||
// add version | ||
//tags[ci.Version] = c.version | ||
|
||
// add nodeName for node, pod and container | ||
metricType := tags[ci.MetricType] | ||
if c.nodeName != "" && (ci.IsNode(metricType) || ci.IsInstance(metricType) || | ||
ci.IsPod(metricType) || ci.IsContainer(metricType)) { | ||
tags[ci.NodeNameKey] = c.nodeName | ||
} | ||
|
||
// add instance id and type | ||
if instanceID := c.hostInfo.GetInstanceID(); instanceID != "" { | ||
tags[ci.InstanceID] = instanceID | ||
} | ||
if instanceType := c.hostInfo.GetInstanceType(); instanceType != "" { | ||
tags[ci.InstanceType] = instanceType | ||
} | ||
|
||
// add scaling group name | ||
tags[ci.AutoScalingGroupNameKey] = c.hostInfo.GetAutoScalingGroupName() | ||
|
||
// add tags for EKS | ||
tags[ci.ClusterNameKey] = c.hostInfo.GetClusterName() | ||
|
||
out := c.k8sDecorator.Decorate(m) | ||
if out != nil { | ||
result = append(result, out) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
func (k *K8sWindows) Shutdown() error { | ||
k.logger.Debug("D! called K8sWindows Shutdown") | ||
return nil | ||
} |
32 changes: 32 additions & 0 deletions
32
receiver/awscontainerinsightreceiver/internal/k8swindows/k8swindows_nowindows.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package k8swindows // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8swindows" | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/host" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/stores" | ||
|
||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type K8sWindows struct { | ||
} | ||
|
||
// New is a dummy function to construct a dummy K8sWindows struct for linux | ||
func New(_ *zap.Logger, _ *stores.K8sDecorator, _ host.Info) (*K8sWindows, error) { | ||
return &K8sWindows{}, nil | ||
} | ||
|
||
// GetMetrics is a dummy function to always returns empty metrics for linux | ||
func (k *K8sWindows) GetMetrics() []pmetric.Metrics { | ||
return []pmetric.Metrics{} | ||
} | ||
|
||
func (k *K8sWindows) Shutdown() error { | ||
return nil | ||
} |
Oops, something went wrong.