Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoravong committed Sep 3, 2024
1 parent 58f8df1 commit 7284250
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 43 deletions.
14 changes: 14 additions & 0 deletions functional_tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ package functional_tests

import (
"context"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"os"
"path/filepath"
"runtime"
"testing"
"time"
Expand Down Expand Up @@ -66,3 +70,13 @@ func waitForMetrics(t *testing.T, entriesNum int, mc *consumertest.MetricsSink)
"failed to receive %d entries, received %d metrics in %d minutes", entriesNum,
len(mc.AllMetrics()), timeoutMinutes)
}

func writeNewExpectedTraceResult(t *testing.T, file string, trace *ptrace.Traces) {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteTraces(t, filepath.Join("results", filepath.Base(file)), *trace))
}

func writeNewExpectedMetricResult(t *testing.T, file string, metric *pmetric.Metrics) {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", filepath.Base(file)), *metric))
}
49 changes: 18 additions & 31 deletions functional_tests/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,6 @@ func testNodeJSTraces(t *testing.T) {
maskScopeVersion(*selectedTrace)
maskScopeVersion(expectedTraces)

// Will update expected results before test validations
if os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
err = golden.WriteTraces(t, expectedTracesFile, *selectedTrace)
}

err = ptracetest.CompareTraces(expectedTraces, *selectedTrace,
ptracetest.IgnoreResourceAttributeValue("container.id"),
ptracetest.IgnoreResourceAttributeValue("host.arch"),
Expand Down Expand Up @@ -616,6 +611,9 @@ func testNodeJSTraces(t *testing.T) {
ptracetest.IgnoreResourceSpansOrder(),
ptracetest.IgnoreScopeSpansOrder(),
)
if err != nil {
writeNewExpectedMetricsResult(t, expectedTracesFile, *selectedTrace)
}
require.NoError(t, err)
}

Expand Down Expand Up @@ -648,11 +646,6 @@ func testJavaTraces(t *testing.T) {
maskScopeVersion(*selectedTrace)
maskScopeVersion(expectedTraces)

// Will update expected results before test validations
if os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
err = golden.WriteTraces(t, expectedTracesFile, *selectedTrace)
}

err = ptracetest.CompareTraces(expectedTraces, *selectedTrace,
ptracetest.IgnoreResourceAttributeValue("os.description"),
ptracetest.IgnoreResourceAttributeValue("process.pid"),
Expand Down Expand Up @@ -682,6 +675,9 @@ func testJavaTraces(t *testing.T) {
ptracetest.IgnoreResourceSpansOrder(),
ptracetest.IgnoreScopeSpansOrder(),
)
if err != nil {
writeNewExpectedMetricsResult(t, expectedTracesFile, *selectedTrace)
}
require.NoError(t, err)
}

Expand Down Expand Up @@ -717,11 +713,6 @@ func testDotNetTraces(t *testing.T) {
maskSpanParentID(*selectedTrace)
maskSpanParentID(expectedTraces)

// Will update expected results before test validations
if os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
err = golden.WriteTraces(t, expectedTracesFile, *selectedTrace)
}

err = ptracetest.CompareTraces(expectedTraces, *selectedTrace,
ptracetest.IgnoreResourceAttributeValue("os.description"),
ptracetest.IgnoreResourceAttributeValue("process.pid"),
Expand Down Expand Up @@ -749,6 +740,9 @@ func testDotNetTraces(t *testing.T) {
ptracetest.IgnoreResourceSpansOrder(),
ptracetest.IgnoreScopeSpansOrder(),
)
if err != nil {
writeNewExpectedMetricsResult(t, expectedTracesFile, *selectedTrace)
}
require.NoError(t, err)
}

Expand Down Expand Up @@ -833,11 +827,6 @@ func testK8sClusterReceiverMetrics(t *testing.T) {

metricNames := []string{"k8s.node.condition_ready", "k8s.namespace.phase", "k8s.pod.phase", "k8s.replicaset.desired", "k8s.replicaset.available", "k8s.daemonset.ready_nodes", "k8s.daemonset.misscheduled_nodes", "k8s.daemonset.desired_scheduled_nodes", "k8s.daemonset.current_scheduled_nodes", "k8s.container.ready", "k8s.container.memory_request", "k8s.container.memory_limit", "k8s.container.cpu_request", "k8s.container.cpu_limit", "k8s.deployment.desired", "k8s.deployment.available", "k8s.container.restarts", "k8s.container.cpu_request", "k8s.container.memory_request", "k8s.container.memory_limit"}

// Will update expected results before test validations
if os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
err = golden.WriteMetrics(t, expectedMetricsFile, *selected)
}

err = pmetrictest.CompareMetrics(expectedMetrics, *selected,
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
Expand Down Expand Up @@ -874,6 +863,9 @@ func testK8sClusterReceiverMetrics(t *testing.T) {
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints("k8s.container.ready", "k8s.container.restarts"),
)
if err != nil {
writeNewExpectedTracesResult(t, expectedMetricsFile, *selectedMetric)
}
require.NoError(t, err)
}

Expand Down Expand Up @@ -1123,7 +1115,8 @@ func testAgentMetrics(t *testing.T) {
)
assert.NoError(t, err)

expectedInternalMetrics, err := golden.ReadMetrics(filepath.Join(testDir, expectedValuesDir, "expected_internal_metrics.yaml"))
expectedInternalMetricsFile := filepath.Join(testDir, expectedValuesDir, "expected_internal_metrics.yaml")
expectedInternalMetrics, err := golden.ReadMetrics(expectedInternalMetricsFile)
require.NoError(t, err)

replaceWithStar := func(string) string { return "*" }
Expand All @@ -1135,11 +1128,6 @@ func testAgentMetrics(t *testing.T) {
}
require.NotNil(t, selectedInternalMetrics)

// Will update expected results before test validations
if os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
err = golden.WriteMetrics(t, expectedInternalMetricsFile, *selectedInternalMetrics)
}

err = pmetrictest.CompareMetrics(expectedInternalMetrics, *selectedInternalMetrics,
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
Expand Down Expand Up @@ -1181,6 +1169,9 @@ func testAgentMetrics(t *testing.T) {
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
)
if err != nil {
writeNewExpectedTracesResult(t, expectedMetricsFile, *selectedMetric)
}
assert.NoError(t, err)

expectedKubeletStatsMetricsFile := filepath.Join(testDir, expectedValuesDir, "expected_kubeletstats_metrics.yaml")
Expand All @@ -1193,11 +1184,6 @@ func testAgentMetrics(t *testing.T) {
}
require.NotNil(t, selectedKubeletstatsMetrics)

// Will update expected results before test validations
if os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" {
err = golden.WriteMetrics(t, expectedKubeletStatsMetricsFile, *selectedKubeletstatsMetrics)
}

err = pmetrictest.CompareMetrics(expectedKubeletStatsMetrics, *selectedKubeletstatsMetrics,
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
Expand Down Expand Up @@ -1238,6 +1224,7 @@ func testAgentMetrics(t *testing.T) {
pmetrictest.IgnoreMetricDataPointsOrder(),
)
if err != nil {
writeNewExpectedTracesResult(t, expectedMetricsFile, *selectedMetric)
t.Skipf("we have trouble identifying exact payloads right now: %v", err)
} else {
assert.NoError(t, err)
Expand Down
18 changes: 6 additions & 12 deletions functional_tests/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ func testHistogramMetrics(t *testing.T) {
)
assert.NoError(t, err)
if err != nil {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", "coredns_metrics.yaml"), *corednsMetrics))
writeNewExpectedMetricsResult(t, expectedCoreDNSMetrics, *selectedTrace)
}

err = pmetrictest.CompareMetrics(expectedKubeSchedulerMetrics, *schedulerMetrics,
Expand Down Expand Up @@ -288,8 +287,7 @@ func testHistogramMetrics(t *testing.T) {
)
assert.NoError(t, err)
if err != nil {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", "scheduler_metrics.yaml"), *schedulerMetrics))
writeNewExpectedMetricsResult(t, expectedKubeSchedulerMetrics, *selectedTrace)
}

err = pmetrictest.CompareMetrics(expectedKubeProxyMetrics, *kubeProxyMetrics,
Expand Down Expand Up @@ -317,8 +315,7 @@ func testHistogramMetrics(t *testing.T) {
)
assert.NoError(t, err)
if err != nil {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", "proxy_metrics.yaml"), *kubeProxyMetrics))
writeNewExpectedMetricsResult(t, expectedKubeProxyMetrics, *selectedTrace)
}

err = pmetrictest.CompareMetrics(expectedApiMetrics, *apiMetrics,
Expand All @@ -338,8 +335,7 @@ func testHistogramMetrics(t *testing.T) {
)
assert.NoError(t, err)
if err != nil {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", "api_metrics.yaml"), *apiMetrics))
writeNewExpectedMetricsResult(t, expectedApiMetrics, *selectedTrace)
}

err = pmetrictest.CompareMetrics(expectedControllerManagerMetrics, *controllerManagerMetrics,
Expand Down Expand Up @@ -367,8 +363,7 @@ func testHistogramMetrics(t *testing.T) {
)
assert.NoError(t, err)
if err != nil {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", "controller_manager_metrics.yaml"), *controllerManagerMetrics))
writeNewExpectedMetricsResult(t, expectedControllerManagerMetrics, *selectedTrace)
}

err = pmetrictest.CompareMetrics(expectedEtcdMetrics, *etcdMetrics,
Expand Down Expand Up @@ -398,7 +393,6 @@ func testHistogramMetrics(t *testing.T) {
)
assert.NoError(t, err)
if err != nil {
require.NoError(t, os.MkdirAll("results", 0755))
require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", "etcd_metrics.yaml"), *etcdMetrics))
writeNewExpectedMetricsResult(t, expectedEtcdMetrics, *selectedTrace)
}
}

0 comments on commit 7284250

Please sign in to comment.