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

[receiver/awscontainerinsight] fix lint error for awscontainerinsightreceiver #12325

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion receiver/awscontainerinsightreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package awscontainerinsightreceiver

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//go:build linux
// +build linux

// nolint:errcheck,gocritic
package cadvisor // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor"

import (
Expand Down Expand Up @@ -126,7 +125,7 @@ type Decorator interface {

type Cadvisor struct {
logger *zap.Logger
nodeName string //get the value from downward API
nodeName string // get the value from downward API
createCadvisorManager createCadvisorManager
manager cadvisorManager
version string
Expand Down Expand Up @@ -216,7 +215,7 @@ func (c *Cadvisor) addECSMetrics(cadvisormetrics []*extractors.CAdvisorMetric) {
if !cpuExist && !memExist {
c.logger.Warn("Can't get mem or cpu limit")
} else {
//cgroup standard cpulimits should be cadvisor standard * 1.024
// cgroup standard cpulimits should be cadvisor standard * 1.024
metricMap[ci.MetricName(ci.TypeInstance, ci.CPUReservedCapacity)] = float64(cpuReserved) / (float64(cpuLimits.(int64)) * 1.024) * 100
metricMap[ci.MetricName(ci.TypeInstance, ci.MemReservedCapacity)] = float64(memReserved) / float64(memLimits.(int64)) * 100
}
Expand Down Expand Up @@ -262,28 +261,28 @@ func (c *Cadvisor) decorateMetrics(cadvisormetrics []*extractors.CAdvisorMetric)
tags := m.GetTags()
c.addEbsVolumeInfo(tags, ebsVolumeIdsUsedAsPV)

//add version
// add version
tags[ci.Version] = c.version

//add NodeName for node, pod and container
// 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
// 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
// add scaling group name
tags[ci.AutoScalingGroupNameKey] = c.hostInfo.GetAutoScalingGroupName()

//add ECS cluster name and container instance id
// add ECS cluster name and container instance id
if c.containerOrchestrator == ci.ECS {
if c.ecsInfo.GetClusterName() == "" {
c.logger.Warn("Can't get cluster name")
Expand Down Expand Up @@ -322,7 +321,7 @@ func (c *Cadvisor) GetMetrics() []pmetric.Metrics {
var containerinfos []*cInfo.ContainerInfo
var err error

//For EKS don't emit metrics if the cluster name is not detected
// For EKS don't emit metrics if the cluster name is not detected
if c.containerOrchestrator == ci.EKS {
clusterName := c.hostInfo.GetClusterName()
if clusterName == "" {
Expand Down Expand Up @@ -383,10 +382,10 @@ func (c *Cadvisor) initManager(createManager createCadvisorManager) error {
c.logger.Error("cadvisor manager allocate failed, ", zap.Error(err))
return err
}
cadvisormetrics.RegisterPlugin("containerd", containerd.NewPlugin())
cadvisormetrics.RegisterPlugin("crio", crio.NewPlugin())
cadvisormetrics.RegisterPlugin("docker", docker.NewPlugin())
cadvisormetrics.RegisterPlugin("systemd", systemd.NewPlugin())
_ = cadvisormetrics.RegisterPlugin("containerd", containerd.NewPlugin())
_ = cadvisormetrics.RegisterPlugin("crio", crio.NewPlugin())
_ = cadvisormetrics.RegisterPlugin("docker", docker.NewPlugin())
_ = cadvisormetrics.RegisterPlugin("systemd", systemd.NewPlugin())
c.manager = m
err = c.manager.Start()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//go:build linux
// +build linux

// nolint:gocritic
package cadvisor // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor"

import (
Expand Down Expand Up @@ -71,7 +70,7 @@ func processContainers(cInfos []*cInfo.ContainerInfo, mInfo extractors.CPUMemInf
if key, ok := podKeys[outPodKey.cgroupPath]; !ok {
podKeys[outPodKey.cgroupPath] = *outPodKey
} else {
//collect the container ids associated with a pod
// collect the container ids associated with a pod
key.containerIds = append(key.containerIds, outPodKey.containerIds...)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package extractors

import (
Expand All @@ -28,7 +27,7 @@ func TestCPUStats(t *testing.T) {
result := testutils.LoadContainerInfo(t, "./testdata/PreInfoContainer.json")
result2 := testutils.LoadContainerInfo(t, "./testdata/CurInfoContainer.json")

//test container type
// test container type
containerType := TypeContainer
extractor := NewCPUMetricExtractor(nil)

Expand All @@ -46,7 +45,7 @@ func TestCPUStats(t *testing.T) {
AssertContainsTaggedFloat(t, cMetrics[0], "container_cpu_usage_system", 10, 0)
AssertContainsTaggedFloat(t, cMetrics[0], "container_cpu_utilization", 0.5, 0)

//test node type
// test node type
containerType = TypeNode
extractor = NewCPUMetricExtractor(nil)

Expand All @@ -64,7 +63,7 @@ func TestCPUStats(t *testing.T) {
AssertContainsTaggedFloat(t, cMetrics[0], "node_cpu_utilization", 0.5, 0)
AssertContainsTaggedInt(t, cMetrics[0], "node_cpu_limit", 2000)

//test instance type
// test instance type
containerType = TypeInstance
extractor = NewCPUMetricExtractor(nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package extractors

import (
Expand All @@ -28,7 +27,7 @@ func TestDiskIOStats(t *testing.T) {

result := testutils.LoadContainerInfo(t, "./testdata/PreInfoContainer.json")
result2 := testutils.LoadContainerInfo(t, "./testdata/CurInfoContainer.json")
//for eks node-level metrics
// for eks node-level metrics
containerType := TypeNode
extractor := NewDiskIOMetricExtractor(nil)

Expand Down Expand Up @@ -62,7 +61,7 @@ func TestDiskIOStats(t *testing.T) {
AssertContainsTaggedField(t, cMetrics[0], expectedFieldsService, expectedTags)
AssertContainsTaggedField(t, cMetrics[1], expectedFieldsServiced, expectedTags)

//for ecs node-level metrics
// for ecs node-level metrics
containerType = TypeInstance
extractor = NewDiskIOMetricExtractor(nil)

Expand Down Expand Up @@ -95,7 +94,7 @@ func TestDiskIOStats(t *testing.T) {
AssertContainsTaggedField(t, cMetrics[0], expectedFieldsService, expectedTags)
AssertContainsTaggedField(t, cMetrics[1], expectedFieldsServiced, expectedTags)

//for non supported type
// for non supported type
containerType = TypeContainerDiskIO
extractor = NewDiskIOMetricExtractor(nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors"

import (
Expand Down Expand Up @@ -47,9 +46,9 @@ type MetricExtractor interface {
type CAdvisorMetric struct {
// source of the metric for debugging merge conflict
cgroupPath string
//key/value pairs that are typed and contain the metric (numerical) data
// key/value pairs that are typed and contain the metric (numerical) data
fields map[string]interface{}
//key/value string pairs that are used to identify the metrics
// key/value string pairs that are used to identify the metrics
tags map[string]string

logger *zap.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package extractors

import (
Expand All @@ -36,7 +35,7 @@ func AssertContainsTaggedFloat(
if val, ok := val.(float64); ok {
actualValue = val
if (val >= expectedValue-delta) && (val <= expectedValue+delta) {
//Found the point, return without failing
// Found the point, return without failing
return
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors"

import (
Expand All @@ -24,9 +23,7 @@ import (
ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight"
)

const (
allowList = "^tmpfs$|^/dev/|^overlay$"
)
var allowedPaths = regexp.MustCompile(`^(tmpfs|\/dev\/.*|overlay)$`)

type FileSystemMetricExtractor struct {
allowListRegexP *regexp.Regexp
Expand Down Expand Up @@ -79,12 +76,8 @@ func (f *FileSystemMetricExtractor) GetValue(info *cinfo.ContainerInfo, _ CPUMem

func NewFileSystemMetricExtractor(logger *zap.Logger) *FileSystemMetricExtractor {
fse := &FileSystemMetricExtractor{
logger: logger,
}
if p, err := regexp.Compile(allowList); err == nil {
fse.allowListRegexP = p
} else {
logger.Error("NewFileSystemMetricExtractor set regex failed", zap.Error(err))
logger: logger,
allowListRegexP: allowedPaths,
}

return fse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck,gocritic
package extractors

import (
Expand All @@ -29,7 +28,7 @@ import (

func TestFSStats(t *testing.T) {
result := testutils.LoadContainerInfo(t, "./testdata/CurInfoContainer.json")
//container type
// container type
containerType := TypeContainer
extractor := NewFileSystemMetricExtractor(nil)

Expand All @@ -51,7 +50,7 @@ func TestFSStats(t *testing.T) {
}
AssertContainsTaggedField(t, cMetrics[0], expectedFields, expectedTags)

//pod type
// pod type
containerType = TypePod
extractor = NewFileSystemMetricExtractor(nil)

Expand All @@ -61,7 +60,7 @@ func TestFSStats(t *testing.T) {

assert.Equal(t, len(cMetrics), 0)

//node type for eks
// node type for eks

result2 := testutils.LoadContainerInfo(t, "./testdata/CurInfoNode.json")
containerType = TypeNode
Expand Down Expand Up @@ -133,7 +132,7 @@ func TestFSStatsWithAllowList(t *testing.T) {

var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.Encode(result)
assert.NoError(t, enc.Encode(result))
containerType := TypeContainer
extractor := NewFileSystemMetricExtractor(nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package extractors // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/extractors"

import (
Expand Down Expand Up @@ -65,7 +64,7 @@ func (n *NetMetricExtractor) GetValue(info *cinfo.ContainerInfo, _ CPUMemInfoPro
mType := getNetMetricType(containerType, n.logger)
netIfceMetric := make(map[string]interface{})

infoName := info.Name + containerType + cur.Name //used to identify the network interface
infoName := info.Name + containerType + cur.Name // used to identify the network interface
multiplier := float64(time.Second)
assignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetRxBytes, infoName, float64(cur.RxBytes), curStats.Timestamp, multiplier)
assignRateValueToField(&n.rateCalculator, netIfceMetric, ci.NetRxPackets, infoName, float64(cur.RxPackets), curStats.Timestamp, multiplier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package testutils // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor/testutils"

import (
Expand Down Expand Up @@ -40,7 +39,7 @@ func LoadContainerInfo(t *testing.T, file string) []*cinfo.ContainerInfo {

var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.Encode(result)
assert.NoError(t, enc.Encode(result))
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package ecsinfo // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/ecsInfo"

import (
Expand Down Expand Up @@ -54,7 +53,7 @@ type cgroupScannerProvider interface {
getCPUReserved() int64
getMemReserved() int64

//use for test
// use for test
getCPUReservedInTask(taskID string, clusterName string) int64
getMEMReservedInTask(taskID string, clusterName string, containers []ECSContainer) int64
}
Expand Down Expand Up @@ -164,7 +163,7 @@ func (c *cgroupScanner) getMEMReservedInTask(taskID string, clusterName string,
for _, container := range containers {
containerPath := filepath.Join(memPath, container.DockerID)

//soft limit first
// soft limit first
if softLimit, err := readInt64(containerPath, "memory.soft_limit_in_bytes"); err == nil && softLimit != kernelMagicCodeNotSet {
sum += softLimit
continue
Expand Down Expand Up @@ -280,11 +279,12 @@ func getTaskCgroupPathFromARN(arn string) (string, error) {
}

result = strings.Split(result[5], "/")
if len(result) == 2 {
switch len(result) {
case 2:
return result[1], nil
} else if len(result) == 3 {
case 3:
return result[2], nil
} else {
default:
return "", fmt.Errorf("invalid ecs task arn: %q", arn)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package ecsinfo // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/ecsInfo"

import (
Expand Down Expand Up @@ -63,7 +62,7 @@ func newECSInstanceInfo(ctx context.Context, ecsAgentEndpointProvider hostIPProv
}

shouldRefresh := func() bool {
//stop the refresh once we get instance ID and cluster name successfully
// stop the refresh once we get instance ID and cluster name successfully
return cii.GetClusterName() == "" || cii.GetContainerInstanceID() == ""
}

Expand Down Expand Up @@ -98,7 +97,7 @@ func (cii *containerInstanceInfo) refresh(ctx context.Context) {
cii.containerInstanceID = instanceID
defer cii.Unlock()

//notify cgroups that the clustername and instanceID is ready
// notify cgroups that the clustername and instanceID is ready
if cii.clusterName != "" && cii.containerInstanceID != "" && !isClosed(cii.readyC) {
close(cii.readyC)
}
Expand Down
Loading