metric_functions_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package redisreceiver
  4. import (
  5. "reflect"
  6. "runtime"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. "go.opentelemetry.io/collector/pdata/pcommon"
  11. "go.opentelemetry.io/collector/receiver/receivertest"
  12. "go.uber.org/zap"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver/internal/metadata"
  14. )
  15. func TestDataPointRecorders(t *testing.T) {
  16. logger, _ := zap.NewDevelopment()
  17. settings := receivertest.NewNopCreateSettings()
  18. settings.Logger = logger
  19. rs := &redisScraper{
  20. redisSvc: newRedisSvc(newFakeClient()),
  21. settings: settings.TelemetrySettings,
  22. mb: metadata.NewMetricsBuilder(Config{}.MetricsBuilderConfig, settings),
  23. }
  24. metricByRecorder := map[string]string{}
  25. for metric, recorder := range rs.dataPointRecorders() {
  26. switch recorder.(type) {
  27. case func(pcommon.Timestamp, int64), func(pcommon.Timestamp, float64):
  28. recorderName := runtime.FuncForPC(reflect.ValueOf(recorder).Pointer()).Name()
  29. require.NotContains(t, metricByRecorder, recorderName, "share the same recorder")
  30. metricByRecorder[recorderName] = metric
  31. default:
  32. assert.Failf(t, "invalid-recorder", "Metric %q has invalid recorder type", metric)
  33. }
  34. }
  35. }