-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Add e2e for receiver/kubeletstats (#26676)
**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.--> Adds an E2E test for kubeletstats receiver Updates existing e2e k8s tests to bootstrap kind cluster with valid kubelet certificates. This will make k8s clusters used in the e2e test more inline with the security practices used by real clusters and improve testing with the kubeletstats receiver which connects to kubelet server. **Link to tracking Issue:** [26319](#26319) **Testing:** <Describe what testing was performed and which tests were added.> **Documentation:** <Describe the documentation added.>
- Loading branch information
Showing
12 changed files
with
1,563 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
kubeadmConfigPatches: | ||
- | | ||
kind: KubeletConfiguration | ||
serverTLSBootstrap: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build e2e | ||
// +build e2e | ||
|
||
package kubeletstatsreceiver | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/receiver/otlpreceiver" | ||
"go.opentelemetry.io/collector/receiver/receivertest" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/tools/clientcmd" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/golden" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" | ||
) | ||
|
||
const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing" | ||
|
||
func TestE2E(t *testing.T) { | ||
var expected pmetric.Metrics | ||
expectedFile := filepath.Join("testdata", "e2e", "expected.yaml") | ||
expected, err := golden.ReadMetrics(expectedFile) | ||
require.NoError(t, err) | ||
kubeConfig, err := clientcmd.BuildConfigFromFlags("", testKubeConfig) | ||
require.NoError(t, err) | ||
dynamicClient, err := dynamic.NewForConfig(kubeConfig) | ||
require.NoError(t, err) | ||
|
||
testID := uuid.NewString()[:8] | ||
collectorObjs := k8stest.CreateCollectorObjects(t, dynamicClient, testID) | ||
|
||
defer func() { | ||
for _, obj := range append(collectorObjs) { | ||
require.NoErrorf(t, k8stest.DeleteObject(dynamicClient, obj), "failed to delete object %s", obj.GetName()) | ||
} | ||
}() | ||
|
||
metricsConsumer := new(consumertest.MetricsSink) | ||
wantEntries := 10 // Minimal number of metrics to wait for. | ||
waitForData(t, wantEntries, metricsConsumer) | ||
|
||
require.NoError(t, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1], | ||
pmetrictest.IgnoreTimestamp(), | ||
pmetrictest.IgnoreStartTimestamp(), | ||
pmetrictest.IgnoreScopeVersion(), | ||
pmetrictest.IgnoreResourceMetricsOrder(), | ||
pmetrictest.IgnoreMetricsOrder(), | ||
pmetrictest.IgnoreScopeMetricsOrder(), | ||
pmetrictest.IgnoreMetricDataPointsOrder(), | ||
pmetrictest.IgnoreMetricValues(), | ||
), | ||
) | ||
} | ||
|
||
func waitForData(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { | ||
f := otlpreceiver.NewFactory() | ||
cfg := f.CreateDefaultConfig().(*otlpreceiver.Config) | ||
|
||
rcvr, err := f.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, mc) | ||
require.NoError(t, rcvr.Start(context.Background(), componenttest.NewNopHost())) | ||
require.NoError(t, err, "failed creating metrics receiver") | ||
defer func() { | ||
assert.NoError(t, rcvr.Shutdown(context.Background())) | ||
}() | ||
|
||
timeoutMinutes := 3 | ||
require.Eventuallyf(t, func() bool { | ||
return len(mc.AllMetrics()) > entriesNum | ||
}, time.Duration(timeoutMinutes)*time.Minute, 1*time.Second, | ||
"failed to receive %d entries, received %d metrics in %d minutes", entriesNum, | ||
len(mc.AllMetrics()), timeoutMinutes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.