Skip to content

Commit

Permalink
[chore][receiver/kubeletstats] Introduce retry on test that rely on s…
Browse files Browse the repository at this point in the history
…hared Informer sync (#33685)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->

This PR introduces a "retry" check on the test that relies on the shared
node informer. This retry will ensure that the first valid scrape will
be after the informer has been "triggered" to handle the node's
addition.

**Link to tracking Issue:** <Issue number if applicable> Related to
#33681.

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>

---------

Signed-off-by: ChrsMark <[email protected]>
Co-authored-by: Tyler Helmuth <[email protected]>
  • Loading branch information
ChrsMark and TylerHelmuth authored Jul 1, 2024
1 parent 0e9dde7 commit a4706ac
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions receiver/kubeletstatsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"os"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
Expand Down Expand Up @@ -134,9 +136,14 @@ func TestScraperWithNodeUtilization(t *testing.T) {
require.NoError(t, err)
}

md, err := r.Scrape(context.Background())
require.NoError(t, err)
require.Equal(t, numContainers+numPods, md.DataPointCount())
var md pmetric.Metrics
require.Eventually(t, func() bool {
md, err = r.Scrape(context.Background())
require.NoError(t, err)
return numContainers+numPods == md.DataPointCount()
}, 10*time.Second, 100*time.Millisecond,
"metrics not collected")

expectedFile := filepath.Join("testdata", "scraper", "test_scraper_cpu_util_nodelimit_expected.yaml")

// Uncomment to regenerate '*_expected.yaml' files
Expand Down

0 comments on commit a4706ac

Please sign in to comment.