metrics_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awsecscontainermetrics
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. "go.uber.org/zap"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil"
  9. )
  10. func TestMetricData(t *testing.T) {
  11. v := uint64(1)
  12. f := 1.0
  13. memStats := make(map[string]uint64)
  14. memStats["cache"] = v
  15. mem := MemoryStats{
  16. Usage: &v,
  17. MaxUsage: &v,
  18. Limit: &v,
  19. MemoryReserved: &v,
  20. MemoryUtilized: &v,
  21. Stats: memStats,
  22. }
  23. disk := DiskStats{
  24. IoServiceBytesRecursives: []IoServiceBytesRecursive{
  25. {Op: "Read", Value: &v},
  26. {Op: "Write", Value: &v},
  27. {Op: "Total", Value: &v},
  28. },
  29. }
  30. net := make(map[string]NetworkStats)
  31. net["eth0"] = NetworkStats{
  32. RxBytes: &v,
  33. RxPackets: &v,
  34. RxErrors: &v,
  35. RxDropped: &v,
  36. TxBytes: &v,
  37. TxPackets: &v,
  38. TxErrors: &v,
  39. TxDropped: &v,
  40. }
  41. netRate := NetworkRateStats{
  42. RxBytesPerSecond: &f,
  43. TxBytesPerSecond: &f,
  44. }
  45. percpu := []*uint64{&v, &v}
  46. cpuUsage := CPUUsage{
  47. TotalUsage: &v,
  48. UsageInKernelmode: &v,
  49. UsageInUserMode: &v,
  50. PerCPUUsage: percpu,
  51. }
  52. cpuStats := CPUStats{
  53. CPUUsage: &cpuUsage,
  54. OnlineCpus: &v,
  55. SystemCPUUsage: &v,
  56. CPUUtilized: &v,
  57. CPUReserved: &v,
  58. }
  59. containerStats := ContainerStats{
  60. Name: "test",
  61. ID: "001",
  62. Memory: &mem,
  63. Disk: &disk,
  64. Network: net,
  65. NetworkRate: &netRate,
  66. CPU: &cpuStats,
  67. }
  68. tm := ecsutil.TaskMetadata{
  69. Cluster: "cluster-1",
  70. TaskARN: "arn:aws:some-value/001",
  71. Family: "task-def-family-1",
  72. Revision: "task-def-version",
  73. Containers: []ecsutil.ContainerMetadata{
  74. {ContainerName: "container-1", DockerID: "001", DockerName: "docker-container-1", Limits: ecsutil.Limits{CPU: &f, Memory: &v}},
  75. },
  76. Limits: ecsutil.Limits{CPU: &f, Memory: &v},
  77. }
  78. cstats := make(map[string]*ContainerStats)
  79. cstats["001"] = &containerStats
  80. logger := zap.NewNop()
  81. md := MetricsData(cstats, tm, logger)
  82. require.Less(t, 0, len(md))
  83. }