Skip to content

[awscontainerinsightreceiver] Enable usage of user defined collection interval in awscontainerinsightreceiver #319

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

Open
wants to merge 1 commit into
base: aws-cwa-dev
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions receiver/awscontainerinsightreceiver/internal/efa/efaSysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import (
)

const (
defaultCollectionInterval = 20 * time.Second
// acirDefaultCollectionInterval is the hardcoded collection interval that is set in
// the awsContainerInsightReceiver when collection interval is not specified in the agent configuration.
awsContainerInsightsDefaultCollectionInterval = 60 * time.Second
efaDefaultCollectionInterval = 20 * time.Second
)

const (
Expand Down Expand Up @@ -106,11 +109,14 @@ type efaCounters struct {
txBytes uint64 // hw_counters/tx_bytes
}

func NewEfaSyfsScraper(logger *zap.Logger, decorator stores.Decorator, podResourcesStore podResourcesStore, hostInfo hostInfoProvider) *Scraper {
func NewEfaSyfsScraper(logger *zap.Logger, decorator stores.Decorator, podResourcesStore podResourcesStore, hostInfo hostInfoProvider, collectionInterval time.Duration) *Scraper {
ctx, cancel := context.WithCancel(context.Background())
podResourcesStore.AddResourceName(efaK8sResourceName)
if collectionInterval == awsContainerInsightsDefaultCollectionInterval {
collectionInterval = efaDefaultCollectionInterval
}
e := &Scraper{
collectionInterval: defaultCollectionInterval,
collectionInterval: collectionInterval,
cancel: cancel,
sysFsReader: defaultSysFsReader(logger),
deltaCalculator: metrics.NewMetricCalculator(calculateDelta),
Expand Down
16 changes: 10 additions & 6 deletions receiver/awscontainerinsightreceiver/internal/efa/efaSysfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver/internal/stores"
)

const (
dummyCollectionInterval = 60 * time.Second
)

type mockSysfsReader struct {
scrapeCounts map[string]uint64
}
Expand Down Expand Up @@ -250,7 +254,7 @@ var efa1PodContainerMetrics = []expectation{
var efa1Metrics = []expectation{efa1NodeMetric, efa1PodContainerMetrics[0], efa1PodContainerMetrics[1]}

func TestGetMetrics(t *testing.T) {
s := NewEfaSyfsScraper(zap.NewNop(), mockDecorator{}, mockPodResourcesStore{}, mockHost)
s := NewEfaSyfsScraper(zap.NewNop(), mockDecorator{}, mockPodResourcesStore{}, mockHost, dummyCollectionInterval)
s.sysFsReader = newMockSysfsReader()

var expectedMetrics []expectation
Expand All @@ -269,7 +273,7 @@ func TestGetMetrics(t *testing.T) {
}

func TestGetMetricsBeforeSuccessfulScrape(t *testing.T) {
s := NewEfaSyfsScraper(zap.NewNop(), mockDecorator{}, mockPodResourcesStore{}, mockHost)
s := NewEfaSyfsScraper(zap.NewNop(), mockDecorator{}, mockPodResourcesStore{}, mockHost, dummyCollectionInterval)

result := s.GetMetrics()
assert.Empty(t, result)
Expand All @@ -296,7 +300,7 @@ func (p mockPodResourcesStoreMissingOneDevice) GetContainerInfo(deviceID string,
}

func TestGetMetricsMissingDeviceFromPodResources(t *testing.T) {
s := NewEfaSyfsScraper(zap.NewNop(), mockDecorator{}, mockPodResourcesStoreMissingOneDevice{}, mockHost)
s := NewEfaSyfsScraper(zap.NewNop(), mockDecorator{}, mockPodResourcesStoreMissingOneDevice{}, mockHost, dummyCollectionInterval)
s.sysFsReader = newMockSysfsReader()

assert.NoError(t, s.scrape())
Expand Down Expand Up @@ -394,7 +398,7 @@ func findTimestamp(t *testing.T, attrs pcommon.Map) (string, time.Time) {
}

func TestScrape(t *testing.T) {
s := NewEfaSyfsScraper(zap.NewNop(), nil, mockPodResourcesStore{}, mockHost)
s := NewEfaSyfsScraper(zap.NewNop(), nil, mockPodResourcesStore{}, mockHost, dummyCollectionInterval)
s.sysFsReader = newMockSysfsReader()

s.hostInfo = mockHost
Expand Down Expand Up @@ -515,7 +519,7 @@ func (r mockSysfsReaderError4) GetMACAddressFromDeviceName(_ efaDeviceName) (str

func TestScrapeErrors(t *testing.T) {
for _, reader := range []sysFsReader{mockSysfsReaderError1{}, mockSysfsReaderError2{}, mockSysfsReaderError3{}, mockSysfsReaderError4{}} {
s := NewEfaSyfsScraper(zap.NewNop(), nil, mockPodResourcesStore{}, mockHost)
s := NewEfaSyfsScraper(zap.NewNop(), nil, mockPodResourcesStore{}, mockHost, dummyCollectionInterval)

s.sysFsReader = reader

Expand Down Expand Up @@ -547,7 +551,7 @@ func (r mockSysfsReaderNoEfaData) GetMACAddressFromDeviceName(_ efaDeviceName) (
}

func TestScrapeNoEfaData(t *testing.T) {
s := NewEfaSyfsScraper(zap.NewNop(), nil, mockPodResourcesStore{}, mockHost)
s := NewEfaSyfsScraper(zap.NewNop(), nil, mockPodResourcesStore{}, mockHost, dummyCollectionInterval)

s.sysFsReader = mockSysfsReaderNoEfaData{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

const (
caFile = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt"
collectionInterval = 60 * time.Second
jobName = "containerInsightsDCGMExporterScraper"
scraperMetricsPath = "/metrics"
scraperK8sServiceSelector = "k8s-app=dcgm-exporter-service"
Expand All @@ -30,7 +29,7 @@ type hostInfoProvider interface {
GetInstanceType() string
}

func GetScraperConfig(hostInfoProvider hostInfoProvider) *config.ScrapeConfig {
func GetScraperConfig(hostInfoProvider hostInfoProvider, collectionInterval time.Duration) *config.ScrapeConfig {
return &config.ScrapeConfig{
HTTPClientConfig: configutil.HTTPClientConfig{
TLSConfig: configutil.TLSConfig{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"strings"
"testing"
"time"

configutil "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -36,9 +37,10 @@ DCGM_FI_DEV_GPU_UTIL{gpu="0",UUID="uuid",device="nvidia0",modelName="NVIDIA A10G
`

const (
dummyInstanceID = "i-0000000000"
dummyClusterName = "cluster-name"
dummyInstanceType = "instance-type"
dummyInstanceID = "i-0000000000"
dummyClusterName = "cluster-name"
dummyInstanceType = "instance-type"
dummyCollectionInterval = 60 * time.Second
)

type mockHostInfoProvider struct{}
Expand Down Expand Up @@ -148,7 +150,7 @@ func TestNewDcgmScraperEndToEnd(t *testing.T) {
Consumer: mConsumer,
Host: componenttest.NewNopHost(),
HostInfoProvider: mockHostInfoProvider{},
ScraperConfigs: GetScraperConfig(mockHostInfoProvider{}),
ScraperConfigs: GetScraperConfig(mockHostInfoProvider{}, dummyCollectionInterval),
Logger: settings.Logger,
})
assert.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
)

const (
caFile = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"

Check failure on line 29 in receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, receiver-0)

File is not properly formatted (gci)

Check failure on line 29 in receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, receiver-0)

File is not properly formatted (gci)
collectionInterval = 60 * time.Second
// needs to start with "containerInsightsKubeAPIServerScraper" for histogram deltas in the emf exporter
jobName = "containerInsightsKubeAPIServerScraper"
serviceAccountTokenDefaultPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" // #nosec
Expand Down Expand Up @@ -73,6 +72,7 @@
Host component.Host
ClusterNameProvider clusterNameProvider
LeaderElection *LeaderElection
CollectionInterval time.Duration
}

func NewPrometheusScraper(opts PrometheusScraperOpts) (*PrometheusScraper, error) {
Expand Down Expand Up @@ -106,8 +106,8 @@
CredentialsFile: serviceAccountTokenDefaultPath,
},
},
ScrapeInterval: model.Duration(collectionInterval),
ScrapeTimeout: model.Duration(collectionInterval),
ScrapeInterval: model.Duration(opts.CollectionInterval),
ScrapeTimeout: model.Duration(opts.CollectionInterval),
ScrapeProtocols: config.DefaultScrapeProtocols,
ScrapeFallbackProtocol: config.PrometheusText0_0_4,
JobName: fmt.Sprintf("%s/%s", jobName, opts.Endpoint),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"testing"
"time"

configutil "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
Expand All @@ -26,6 +27,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver"
)

const (
dummyCollectionInterval = 60 * time.Second
)

const renameMetric = `
# HELP http_go_threads Number of OS threads created
# TYPE http_go_threads gauge
Expand Down Expand Up @@ -102,6 +107,7 @@ func TestNewPrometheusScraperBadInputs(t *testing.T) {
Host: componenttest.NewNopHost(),
ClusterNameProvider: mockClusterNameProvider{},
LeaderElection: nil,
CollectionInterval: dummyCollectionInterval,
},
{
Ctx: context.TODO(),
Expand All @@ -111,6 +117,7 @@ func TestNewPrometheusScraperBadInputs(t *testing.T) {
Host: componenttest.NewNopHost(),
ClusterNameProvider: mockClusterNameProvider{},
LeaderElection: &leaderElection,
CollectionInterval: dummyCollectionInterval,
},
{
Ctx: context.TODO(),
Expand All @@ -120,6 +127,7 @@ func TestNewPrometheusScraperBadInputs(t *testing.T) {
Host: nil,
ClusterNameProvider: mockClusterNameProvider{},
LeaderElection: &leaderElection,
CollectionInterval: dummyCollectionInterval,
},
{
Ctx: context.TODO(),
Expand All @@ -129,6 +137,7 @@ func TestNewPrometheusScraperBadInputs(t *testing.T) {
Host: componenttest.NewNopHost(),
ClusterNameProvider: nil,
LeaderElection: &leaderElection,
CollectionInterval: dummyCollectionInterval,
},
}

Expand Down Expand Up @@ -169,6 +178,7 @@ func TestNewPrometheusScraperEndToEnd(t *testing.T) {
Host: componenttest.NewNopHost(),
ClusterNameProvider: mockClusterNameProvider{},
LeaderElection: &leaderElection,
CollectionInterval: dummyCollectionInterval,
})
assert.NoError(t, err)
assert.Equal(t, mockClusterNameProvider{}, scraper.clusterNameProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (

const (
caFile = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt"
collectionInterval = 60 * time.Second
jobName = "containerInsightsNeuronMonitorScraper"
scraperMetricsPath = "/metrics"
scraperK8sServiceSelector = "k8s-app=neuron-monitor-service"
)

func GetNeuronScrapeConfig(hostinfo prometheusscraper.HostInfoProvider) *config.ScrapeConfig {
func GetNeuronScrapeConfig(hostinfo prometheusscraper.HostInfoProvider, collectionInterval time.Duration) *config.ScrapeConfig {
return &config.ScrapeConfig{
ScrapeProtocols: config.DefaultScrapeProtocols,
HTTPClientConfig: configutil.HTTPClientConfig{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
Expand All @@ -15,10 +16,11 @@ import (
)

const (
dummyClusterName = "cluster-name"
dummyHostName = "i-000000000"
dummyNodeName = "dummy-nodeName"
dummyInstanceType = "instance-type"
dummyClusterName = "cluster-name"
dummyHostName = "i-000000000"
dummyNodeName = "dummy-nodeName"
dummyInstanceType = "instance-type"
dummyCollectionInterval = 60 * time.Second
)

type mockHostInfoProvider struct{}
Expand Down Expand Up @@ -132,7 +134,7 @@ func TestNewNeuronScraperEndToEnd(t *testing.T) {
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
Consumer: consumer,
Host: componenttest.NewNopHost(),
ScraperConfigs: GetNeuronScrapeConfig(mockHostInfoProvider{}),
ScraperConfigs: GetNeuronScrapeConfig(mockHostInfoProvider{}, dummyCollectionInterval),
HostInfoProvider: mockHostInfoProvider{},
}

Expand Down Expand Up @@ -246,7 +248,7 @@ func TestNewNeuronScraperWithUltraServersEndToEnd(t *testing.T) {
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
Consumer: consumer,
Host: componenttest.NewNopHost(),
ScraperConfigs: GetNeuronScrapeConfig(mockHostInfoProvider{}),
ScraperConfigs: GetNeuronScrapeConfig(mockHostInfoProvider{}, dummyCollectionInterval),
HostInfoProvider: mockHostInfoProvider{},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

const (
collectionInterval = 60 * time.Second
jobName = "containerInsightsNVMeExporterScraper"
scraperMetricsPath = "/metrics"
scraperK8sServiceSelector = "app=ebs-csi-node"
Expand All @@ -29,7 +28,7 @@ type hostInfoProvider interface {
GetInstanceType() string
}

func GetScraperConfig(hostInfoProvider hostInfoProvider) *config.ScrapeConfig {
func GetScraperConfig(hostInfoProvider hostInfoProvider, collectionInterval time.Duration) *config.ScrapeConfig {
return &config.ScrapeConfig{
ScrapeInterval: model.Duration(collectionInterval),
ScrapeTimeout: model.Duration(collectionInterval),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"strings"
"testing"
"time"

configutil "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -36,10 +37,11 @@ aws_ebs_csi_read_seconds_total{instance_id="i-0131bee5395cc4317",volume_id="vol-
`

const (
dummyInstanceID = "i-0000000000"
dummyClusterName = "cluster-name"
dummyInstanceType = "instance-type"
dummyNodeName = "hostname"
dummyInstanceID = "i-0000000000"
dummyClusterName = "cluster-name"
dummyInstanceType = "instance-type"
dummyNodeName = "hostname"
dummyCollectionInterval = 60 * time.Second
)

type mockHostInfoProvider struct{}
Expand Down Expand Up @@ -141,7 +143,7 @@ func TestNewNVMEScraperEndToEnd(t *testing.T) {
Consumer: mConsumer,
Host: componenttest.NewNopHost(),
HostInfoProvider: mockHostInfoProvider{},
ScraperConfigs: GetScraperConfig(mockHostInfoProvider{}),
ScraperConfigs: GetScraperConfig(mockHostInfoProvider{}, dummyCollectionInterval),
Logger: settings.Logger,
})
assert.NoError(t, err)
Expand Down
Loading
Loading