Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU extractors with unit tests #146

Conversation

KlwntSingh
Copy link

Description:
Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

Testing:

  1. Unit tests passed in local

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric
@KlwntSingh KlwntSingh requested a review from mxiamxia as a code owner December 27, 2023 02:35
@KlwntSingh KlwntSingh changed the base branch from main to aws-cwa-ciwindows December 27, 2023 02:36
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better import name than cExtractor?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC our linter will want the import names to be all lower case, i.e. awsmetrics

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed cExtractor to cextractor.
I saw import following similar pattern in cadvisor code where import was alias as cInfo but for now i changed it to cextractor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, I didn't realize it as following an established pattern. If there was no pattern I would say "containerextractor" is more clear and avoids non-obvious abbreviations. If there is an established pattern than cExtractor seems fine.

Approving this rev, curious what the other agents team review thinks. This can be changed in a later PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced cextractor back to cExtractor


// ConvertNodeToRaw Converts Kubelet Node stats to RawMetric.
func ConvertNodeToRaw(nodeStat *stats.NodeStats) *RawMetric {
var rawMetic *RawMetric

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any risk of null pointers when dereferencing here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed this issue by adding nil checks

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences
chadpatel
chadpatel previously approved these changes Dec 29, 2023
Copy link

@nathalapooja nathalapooja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some nit comments. Everything else looks good

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we change this file name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was extractorhelpers_test before, I was not able to import helper funcs from test file in file in k8swindows package. That's why i changed it to extractorhelpers.

MemoryStats *stats.MemoryStats
}

type MetricExtractor interface {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we implement similar to MetricExtractor interface which has method HasValue using the CPUstats?

type MetricExtractor interface {
HasValue(*cinfo.ContainerInfo) bool
GetValue(info *cinfo.ContainerInfo, mInfo CPUMemInfoProvider, containerType string) []*CAdvisorMetric
Shutdown() error
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to add this func in future PRs but i have added this func now. Thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the file need to be corrected to extractor_helpers_test.go to match cAdvisor

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually cAdvisor file is extractorhelpers, I am keeping file names without snake pattern in name to keep consistent with cAdvisor.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of the file can be corrected to extractor_helpers.go

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add s at last but i am still keeping extractorhelpers to keep consistent with cAdvisor and other pakcages where name doesn't follow snake pattern.

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
Copy link
Author

@KlwntSingh KlwntSingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed some of comments and provided explanation for other comments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was extractorhelpers_test before, I was not able to import helper funcs from test file in file in k8swindows package. That's why i changed it to extractorhelpers.

MemoryStats *stats.MemoryStats
}

type MetricExtractor interface {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to add this func in future PRs but i have added this func now. Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually cAdvisor file is extractorhelpers, I am keeping file names without snake pattern in name to keep consistent with cAdvisor.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add s at last but i am still keeping extractorhelpers to keep consistent with cAdvisor and other pakcages where name doesn't follow snake pattern.

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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced cextractor back to cExtractor

@KlwntSingh KlwntSingh merged commit 1ad51be into amazon-contributing:aws-cwa-ciwindows Dec 29, 2023
55 of 67 checks passed
KlwntSingh added a commit to KlwntSingh/opentelemetry-collector-contrib that referenced this pull request Jan 30, 2024
* Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

* Refactor code

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences

* Refactored code

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
KlwntSingh added a commit to KlwntSingh/opentelemetry-collector-contrib that referenced this pull request Feb 2, 2024
* Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

* Refactor code

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences

* Refactored code

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
KlwntSingh added a commit to KlwntSingh/opentelemetry-collector-contrib that referenced this pull request Feb 2, 2024
* Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

* Refactor code

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences

* Refactored code

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
KlwntSingh added a commit to KlwntSingh/opentelemetry-collector-contrib that referenced this pull request Feb 22, 2024
* Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

* Refactor code

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences

* Refactored code

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
KlwntSingh added a commit to KlwntSingh/opentelemetry-collector-contrib that referenced this pull request Feb 22, 2024
* Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

* Refactor code

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences

* Refactored code

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
KlwntSingh added a commit that referenced this pull request Feb 29, 2024
… 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)
KlwntSingh added a commit to KlwntSingh/opentelemetry-collector-contrib that referenced this pull request Mar 2, 2024
* Add CPU extractors from kubelet summary API

1. Make cadvisor helper func's public to be used in k8swindows extractor
2. Add CPU extractor and add utilization fields
3. Add unit test for CPU extractor.
4. Add unit test data for kubelet summary API
5. Add helper func to convert Pod and Node summary stats to RawMetric

* Refactor code

1. Changed cExtractor to cextractors
2. Add nil checks to avoid panic during pointer deferences

* Refactored code

1. Added missing HasValue func in extractors
2. Replaced cextractor with cExtractor
3. Corrected extractorhelper name with missing characters
# Conflicts:
#	receiver/awscontainerinsightreceiver/internal/cadvisor/extractors/cpu_extractor.go
#	receiver/awscontainerinsightreceiver/internal/cadvisor/extractors/diskio_extractor.go
#	receiver/awscontainerinsightreceiver/internal/cadvisor/extractors/extractor.go
#	receiver/awscontainerinsightreceiver/internal/cadvisor/extractors/mem_extractor.go
#	receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet.go
KlwntSingh added a commit that referenced this pull request Mar 7, 2024
* 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)
* Add windows build tag to fix building cw agent on Windows
* Downgrade internal/aws/containerinsight from 0.92 0.89
* Separate unit tests in util.go specific for Windows
* Fix util unit tests applicable for Windows
* Fix goporto issue
* Fix lint issue
* Fix regression in unit tests caused due to rebasing mainline
* Add unit tests for k8s Windows
* Add unit test for kubelet client on Windows
* Run DCGM scrapper only for CW agent on Linux
* Separate out node Volume unit tests for Windows
* Add changelog for Container Insights on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants