Skip to content

Commit d68c7c6

Browse files
committed
test: validate kubelet datastream hits
1 parent 5e6ad52 commit d68c7c6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

testing/integration/otel_helm_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

23+
"github.com/elastic/elastic-agent-libs/testing/estools"
2324
"github.com/elastic/elastic-agent/pkg/testing/define"
2425
)
2526

@@ -184,6 +185,9 @@ func TestOtelKubeStackHelmEDOTImage(t *testing.T) {
184185
// - Two Gateway pods to collect, aggregate and forward
185186
// telemetry.
186187
k8sStepCheckRunningPods("app.kubernetes.io/managed-by=opentelemetry-operator", 4, "otc-container"),
188+
// validate kubeletstats metrics are being
189+
// pushed
190+
k8sStepCheckDatastreamsHits(info, "metrics", "kubeletstatsreceiver.otel", "default"),
187191
},
188192
},
189193
{
@@ -277,3 +281,24 @@ func k8sStepCheckRunningPods(podLabelSelector string, expectedPodNumber int, con
277281
}, 5*time.Minute, 10*time.Second, fmt.Sprintf("at least %d agent containers should be checked", expectedPodNumber))
278282
}
279283
}
284+
285+
// k8sStepCheckDatastreams checks the corresponding Elasticsearch datastreams
286+
// are created and documents being written
287+
func k8sStepCheckDatastreamsHits(info *define.Info, dsType, dataset, namespace string) k8sTestStep {
288+
datastream := fmt.Sprintf("%s-%s-%s", dsType, dataset, namespace)
289+
return func(t *testing.T, ctx context.Context, kCtx k8sContext, namespace string) {
290+
var initDocumentHits estools.Hits
291+
require.Eventually(t, func() bool {
292+
docs, err := estools.GetLogsForDatastream(ctx, info.ESClient, dsType, dataset, namespace)
293+
require.NoError(t, err, "failed to get %s datastream documents", datastream)
294+
initDocumentHits = docs.Hits
295+
return docs.Hits.Total.Value > 0
296+
}, 5*time.Minute, 10*time.Second, fmt.Sprintf("at least one document should be available for %s datastream", datastream))
297+
298+
require.Eventually(t, func() bool {
299+
docs, err := estools.GetLogsForDatastream(ctx, info.ESClient, dsType, dataset, namespace)
300+
require.NoError(t, err, "failed to get %s datastream documents", datastream)
301+
return docs.Hits.Total.Value > initDocumentHits.Total.Value
302+
}, 5*time.Minute, 10*time.Second, fmt.Sprintf("no new documents for %s datastream", datastream))
303+
}
304+
}

0 commit comments

Comments
 (0)