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

Add cluster-level metrics to container insight receiver #3683

Merged
merged 4 commits into from
Jun 8, 2021
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
4 changes: 2 additions & 2 deletions internal/aws/k8s/k8sclient/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ func (c *K8sClient) Shutdown() {
c.Ep = nil
}
if c.Pod != nil && !reflect.ValueOf(c.Pod).IsNil() {
c.Pod.shutdown()
c.Pod.Shutdown()
c.Pod = nil
}
if c.Node != nil && !reflect.ValueOf(c.Node).IsNil() {
c.Node.shutdown()
c.Node.Shutdown()
c.Node = nil
}
if c.Job != nil && !reflect.ValueOf(c.Job).IsNil() {
Expand Down
7 changes: 3 additions & 4 deletions internal/aws/k8s/k8sclient/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ type NodeClient interface {
ClusterFailedNodeCount() int
// Get the number of nodes for current cluster
ClusterNodeCount() int

// shutdown is only used internally by clientset to stop the NodeClient
shutdown()
// Shutdown stops the NodeClient
Shutdown()
}

type nodeClientOption func(*nodeClient)
Expand Down Expand Up @@ -143,7 +142,7 @@ func newNodeClient(clientSet kubernetes.Interface, logger *zap.Logger, options .
return c
}

func (c *nodeClient) shutdown() {
func (c *nodeClient) Shutdown() {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion internal/aws/k8s/k8sclient/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func TestNodeClient(t *testing.T) {

assert.Equal(t, clusterNodeCount, expectedClusterNodeCount)
assert.Equal(t, clusterFailedNodeCount, expectedClusterFailedNodeCount)
client.shutdown()
client.Shutdown()
assert.True(t, client.stopped)
}

Expand Down
7 changes: 3 additions & 4 deletions internal/aws/k8s/k8sclient/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import (
type PodClient interface {
// Get the mapping between the namespace and the number of belonging pods
NamespaceToRunningPodNum() map[string]int

// shutdown is only used internally by clientset to stop the PodClient
shutdown()
// Shutdown stops the PodClient
Shutdown()
}

type podClientOption func(*podClient)
Expand Down Expand Up @@ -107,7 +106,7 @@ func newPodClient(clientSet kubernetes.Interface, logger *zap.Logger, options ..
return c
}

func (c *podClient) shutdown() {
func (c *podClient) Shutdown() {
c.mu.Lock()
defer c.mu.Unlock()
close(c.stopChan)
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/k8s/k8sclient/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestPodClient_NamespaceToRunningPodNum(t *testing.T) {
resultMap := client.NamespaceToRunningPodNum()
log.Printf("NamespaceToRunningPodNum (len=%v): %v", len(resultMap), awsutil.Prettify(resultMap))
assert.True(t, reflect.DeepEqual(resultMap, expectedMap))
client.shutdown()
client.Shutdown()
assert.True(t, client.stopped)
}

Expand Down
14 changes: 1 addition & 13 deletions receiver/awscontainerinsightreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/cadvisor"
hostInfo "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/host"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/k8sapiserver"
)

// Factory for awscontainerinsightreceiver
Expand Down Expand Up @@ -68,12 +63,5 @@ func createMetricsReceiver(

rCfg := baseCfg.(*Config)
logger := params.Logger
hostInfo, err := hostInfo.NewInfo(rCfg.CollectionInterval, logger)
// TODO: I will need to change the code here to let cadvisor and k8sapiserver return err as well
if err != nil {
logger.Warn("failed to initialize hostInfo", zap.Error(err))
}
cadvisor := cadvisor.New(rCfg.ContainerOrchestrator, hostInfo, logger)
k8sapiserver := k8sapiserver.New(hostInfo, logger)
return New(logger, rCfg, consumer, cadvisor, k8sapiserver)
return New(logger, rCfg, consumer)
}
10 changes: 10 additions & 0 deletions receiver/awscontainerinsightreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ go 1.16
require (
github.com/aws/aws-sdk-go v1.38.55
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s v0.0.0-00010101000000-000000000000
github.com/shirou/gopsutil v3.21.5+incompatible
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/collector v0.27.1-0.20210608105628-44a4ae746c3c
go.uber.org/zap v1.17.0
k8s.io/api v0.21.0
k8s.io/apimachinery v0.21.0
k8s.io/client-go v0.21.0
k8s.io/klog v1.0.0
)

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

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s => ./../../internal/aws/k8s
27 changes: 27 additions & 0 deletions receiver/awscontainerinsightreceiver/go.sum

Large diffs are not rendered by default.

Loading