translator_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awsecscontainermetrics
  4. import (
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/pdata/pcommon"
  10. "go.opentelemetry.io/collector/pdata/pmetric"
  11. conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
  12. )
  13. func TestConvertToOTMetrics(t *testing.T) {
  14. timestamp := pcommon.NewTimestampFromTime(time.Now())
  15. m := ECSMetrics{}
  16. m.MemoryUsage = 100
  17. m.MemoryMaxUsage = 100
  18. m.MemoryUtilized = 100
  19. m.MemoryReserved = 100
  20. m.CPUTotalUsage = 100
  21. resource := pcommon.NewResource()
  22. md := convertToOTLPMetrics("container.", m, resource, timestamp)
  23. require.EqualValues(t, 26, md.ResourceMetrics().At(0).ScopeMetrics().Len())
  24. assert.EqualValues(t, conventions.SchemaURL, md.ResourceMetrics().At(0).SchemaUrl())
  25. }
  26. func TestIntGauge(t *testing.T) {
  27. intValue := int64(100)
  28. timestamp := pcommon.NewTimestampFromTime(time.Now())
  29. ilm := pmetric.NewScopeMetrics()
  30. appendIntGauge("cpu_utilized", "Count", intValue, timestamp, ilm)
  31. require.NotNil(t, ilm)
  32. }
  33. func TestDoubleGauge(t *testing.T) {
  34. timestamp := pcommon.NewTimestampFromTime(time.Now())
  35. floatValue := 100.01
  36. ilm := pmetric.NewScopeMetrics()
  37. appendDoubleGauge("cpu_utilized", "Count", floatValue, timestamp, ilm)
  38. require.NotNil(t, ilm)
  39. }
  40. func TestIntSum(t *testing.T) {
  41. timestamp := pcommon.NewTimestampFromTime(time.Now())
  42. intValue := int64(100)
  43. ilm := pmetric.NewScopeMetrics()
  44. appendIntSum("cpu_utilized", "Count", intValue, timestamp, ilm)
  45. require.NotNil(t, ilm)
  46. }
  47. func TestConvertStoppedContainerDataToOTMetrics(t *testing.T) {
  48. timestamp := pcommon.NewTimestampFromTime(time.Now())
  49. resource := pcommon.NewResource()
  50. duration := 1200000000.32132
  51. md := convertStoppedContainerDataToOTMetrics("container.", resource, timestamp, duration)
  52. require.EqualValues(t, 1, md.ResourceMetrics().At(0).ScopeMetrics().Len())
  53. }