metric_test.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package tests
  4. // This file contains Test functions which initiate the tests. The tests can be either
  5. // coded in this file or use scenarios from perf_scenarios.go.
  6. import (
  7. "path/filepath"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. "go.opentelemetry.io/collector/component"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datareceivers"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datasenders"
  14. "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
  15. )
  16. func TestMetric10kDPS(t *testing.T) {
  17. tests := []struct {
  18. name string
  19. sender testbed.DataSender
  20. receiver testbed.DataReceiver
  21. resourceSpec testbed.ResourceSpec
  22. skipMessage string
  23. }{
  24. {
  25. name: "Carbon",
  26. sender: datasenders.NewCarbonDataSender(testbed.GetAvailablePort(t)),
  27. receiver: datareceivers.NewCarbonDataReceiver(testbed.GetAvailablePort(t)),
  28. resourceSpec: testbed.ResourceSpec{
  29. ExpectedMaxCPU: 237,
  30. ExpectedMaxRAM: 100,
  31. },
  32. skipMessage: "Flaky test, https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9729",
  33. },
  34. {
  35. name: "OpenCensus",
  36. sender: datasenders.NewOCMetricDataSender(testbed.DefaultHost, testbed.GetAvailablePort(t)),
  37. receiver: datareceivers.NewOCDataReceiver(testbed.GetAvailablePort(t)),
  38. resourceSpec: testbed.ResourceSpec{
  39. ExpectedMaxCPU: 85,
  40. ExpectedMaxRAM: 100,
  41. },
  42. },
  43. {
  44. name: "OTLP",
  45. sender: testbed.NewOTLPMetricDataSender(testbed.DefaultHost, testbed.GetAvailablePort(t)),
  46. receiver: testbed.NewOTLPDataReceiver(testbed.GetAvailablePort(t)),
  47. resourceSpec: testbed.ResourceSpec{
  48. ExpectedMaxCPU: 60,
  49. ExpectedMaxRAM: 105,
  50. },
  51. },
  52. {
  53. name: "OTLP-HTTP",
  54. sender: testbed.NewOTLPHTTPMetricDataSender(testbed.DefaultHost, testbed.GetAvailablePort(t)),
  55. receiver: testbed.NewOTLPHTTPDataReceiver(testbed.GetAvailablePort(t)),
  56. resourceSpec: testbed.ResourceSpec{
  57. ExpectedMaxCPU: 60,
  58. ExpectedMaxRAM: 100,
  59. },
  60. },
  61. {
  62. name: "SignalFx",
  63. sender: datasenders.NewSFxMetricDataSender(testbed.GetAvailablePort(t)),
  64. receiver: datareceivers.NewSFxMetricsDataReceiver(testbed.GetAvailablePort(t)),
  65. resourceSpec: testbed.ResourceSpec{
  66. ExpectedMaxCPU: 120,
  67. ExpectedMaxRAM: 98,
  68. },
  69. },
  70. }
  71. for _, test := range tests {
  72. t.Run(test.name, func(t *testing.T) {
  73. if test.skipMessage != "" {
  74. t.Skip(test.skipMessage)
  75. }
  76. Scenario10kItemsPerSecond(
  77. t,
  78. test.sender,
  79. test.receiver,
  80. test.resourceSpec,
  81. performanceResultsSummary,
  82. nil,
  83. nil,
  84. )
  85. })
  86. }
  87. }
  88. func TestMetricsFromFile(t *testing.T) {
  89. // This test demonstrates usage of NewFileDataProvider to generate load using
  90. // previously recorded data.
  91. resultDir, err := filepath.Abs(filepath.Join("results", t.Name()))
  92. require.NoError(t, err)
  93. dataProvider, err := testbed.NewFileDataProvider("testdata/k8s-metrics.yaml", component.DataTypeMetrics)
  94. assert.NoError(t, err)
  95. options := testbed.LoadOptions{
  96. DataItemsPerSecond: 1_000,
  97. Parallel: 1,
  98. // ItemsPerBatch is based on the data from the file.
  99. ItemsPerBatch: dataProvider.ItemsPerBatch,
  100. }
  101. agentProc := testbed.NewChildProcessCollector()
  102. sender := testbed.NewOTLPMetricDataSender(testbed.DefaultHost, testbed.GetAvailablePort(t))
  103. receiver := testbed.NewOTLPDataReceiver(testbed.GetAvailablePort(t))
  104. configStr := createConfigYaml(t, sender, receiver, resultDir, nil, nil)
  105. configCleanup, err := agentProc.PrepareConfig(configStr)
  106. require.NoError(t, err)
  107. defer configCleanup()
  108. tc := testbed.NewTestCase(
  109. t,
  110. dataProvider,
  111. sender,
  112. receiver,
  113. agentProc,
  114. &testbed.PerfTestValidator{},
  115. performanceResultsSummary,
  116. testbed.WithResourceLimits(testbed.ResourceSpec{ExpectedMaxCPU: 120, ExpectedMaxRAM: 110}),
  117. )
  118. defer tc.Stop()
  119. tc.StartBackend()
  120. tc.StartAgent()
  121. tc.StartLoad(options)
  122. tc.Sleep(tc.Duration)
  123. tc.StopLoad()
  124. tc.WaitFor(func() bool { return tc.LoadGenerator.DataItemsSent() > 0 }, "load generator started")
  125. tc.WaitFor(func() bool { return tc.LoadGenerator.DataItemsSent() == tc.MockBackend.DataItemsReceived() },
  126. "all data items received")
  127. tc.StopAgent()
  128. tc.ValidateData()
  129. }