-
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 storage metrics for container and node level (amazon-contributing…
…#151) * 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 * Address chad's and pooja's comments * Refactor: Address review comments * Refactor: remove extra add source func
- Loading branch information
1 parent
fa622c9
commit 52bd7cc
Showing
10 changed files
with
303 additions
and
11 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
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
72 changes: 72 additions & 0 deletions
72
receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/fs_extractor.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,72 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors" | ||
|
||
import ( | ||
ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight" | ||
awsmetrics "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics" | ||
cExtractor "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
type FileSystemMetricExtractor struct { | ||
logger *zap.Logger | ||
rateCalculator awsmetrics.MetricCalculator | ||
} | ||
|
||
func (f *FileSystemMetricExtractor) HasValue(rawMetric RawMetric) bool { | ||
if !rawMetric.Time.IsZero() { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (f *FileSystemMetricExtractor) GetValue(rawMetric RawMetric, _ cExtractor.CPUMemInfoProvider, containerType string) []*cExtractor.CAdvisorMetric { | ||
if containerType == ci.TypePod { | ||
return nil | ||
} | ||
|
||
containerType = getFSMetricType(containerType, f.logger) | ||
metrics := make([]*cExtractor.CAdvisorMetric, 0, len(rawMetric.FileSystemStats)) | ||
|
||
for _, v := range rawMetric.FileSystemStats { | ||
metric := cExtractor.NewCadvisorMetric(containerType, f.logger) | ||
|
||
metric.AddField(ci.MetricName(containerType, ci.FSUsage), v.UsedBytes) | ||
metric.AddField(ci.MetricName(containerType, ci.FSCapacity), v.CapacityBytes) | ||
metric.AddField(ci.MetricName(containerType, ci.FSAvailable), v.AvailableBytes) | ||
|
||
if v.CapacityBytes != 0 { | ||
metric.AddField(ci.MetricName(containerType, ci.FSUtilization), float64(v.UsedBytes)/float64(v.CapacityBytes)*100) | ||
} | ||
|
||
metrics = append(metrics, metric) | ||
} | ||
return metrics | ||
} | ||
|
||
func (f *FileSystemMetricExtractor) Shutdown() error { | ||
return f.rateCalculator.Shutdown() | ||
} | ||
|
||
func NewFileSystemMetricExtractor(logger *zap.Logger) *FileSystemMetricExtractor { | ||
return &FileSystemMetricExtractor{ | ||
logger: logger, | ||
rateCalculator: cExtractor.NewFloat64RateCalculator(), | ||
} | ||
} | ||
|
||
func getFSMetricType(containerType string, logger *zap.Logger) string { | ||
metricType := "" | ||
switch containerType { | ||
case ci.TypeNode: | ||
metricType = ci.TypeNodeFS | ||
case ci.TypeContainer: | ||
metricType = ci.TypeContainerFS | ||
default: | ||
logger.Warn("fs_extractor: fs metric extractor is parsing unexpected containerType", zap.String("containerType", containerType)) | ||
} | ||
return metricType | ||
} |
83 changes: 83 additions & 0 deletions
83
receiver/awscontainerinsightreceiver/internal/k8swindows/extractors/fs_extractor_test.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,83 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package extractors | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"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/testutils" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFSStats(t *testing.T) { | ||
result := testutils.LoadKubeletSummary(t, "./testdata/PreSingleKubeletSummary.json") | ||
|
||
nodeRawMetric := ConvertNodeToRaw(result.Node) | ||
|
||
// node type | ||
containerType := containerinsight.TypeNode | ||
extractor := NewFileSystemMetricExtractor(nil) | ||
|
||
var cMetrics []*cExtractor.CAdvisorMetric | ||
if extractor.HasValue(nodeRawMetric) { | ||
cMetrics = extractor.GetValue(nodeRawMetric, nil, containerType) | ||
} | ||
fmt.Println(len(cMetrics)) | ||
expectedFields := map[string]any{ | ||
"node_filesystem_usage": uint64(34667089920), | ||
"node_filesystem_capacity": uint64(85897244672), | ||
"node_filesystem_available": uint64(51230154752), | ||
"node_filesystem_utilization": float64(40.358791544917224), | ||
} | ||
expectedTags := map[string]string{ | ||
"Type": "NodeFS", | ||
} | ||
cExtractor.AssertContainsTaggedField(t, cMetrics[0], expectedFields, expectedTags) | ||
|
||
// pod type | ||
containerType = containerinsight.TypePod | ||
extractor = NewFileSystemMetricExtractor(nil) | ||
podRawMetric := ConvertPodToRaw(result.Pods[0]) | ||
|
||
if extractor.HasValue(podRawMetric) { | ||
cMetrics = extractor.GetValue(podRawMetric, nil, containerType) | ||
} | ||
|
||
assert.Equal(t, len(cMetrics), 0) | ||
|
||
// container type for eks | ||
containerType = containerinsight.TypeContainer | ||
extractor = NewFileSystemMetricExtractor(nil) | ||
containerRawMetric := ConvertContainerToRaw(result.Pods[0].Containers[0], result.Pods[0]) | ||
|
||
if extractor.HasValue(containerRawMetric) { | ||
cMetrics = extractor.GetValue(containerRawMetric, nil, containerType) | ||
} | ||
|
||
expectedFields = map[string]any{ | ||
"container_filesystem_available": uint64(51230154752), | ||
"container_filesystem_capacity": uint64(85897244672), | ||
"container_filesystem_usage": uint64(339738624), | ||
"container_filesystem_utilization": float64(0.3955174875484043), | ||
} | ||
expectedTags = map[string]string{ | ||
"Type": "ContainerFS", | ||
} | ||
cExtractor.AssertContainsTaggedField(t, cMetrics[0], expectedFields, expectedTags) | ||
|
||
expectedFields = map[string]any{ | ||
"container_filesystem_available": uint64(51230154752), | ||
"container_filesystem_capacity": uint64(85897244672), | ||
"container_filesystem_usage": uint64(919463), | ||
"container_filesystem_utilization": float64(0.0010704219949207732), | ||
} | ||
expectedTags = map[string]string{ | ||
"Type": "ContainerFS", | ||
} | ||
cExtractor.AssertContainsTaggedField(t, cMetrics[1], expectedFields, expectedTags) | ||
} |
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
Oops, something went wrong.