metric_index.go 981 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/correctnesstests/metrics"
  4. import (
  5. "go.opentelemetry.io/collector/pdata/pmetric"
  6. )
  7. type metricReceived struct {
  8. pdm pmetric.Metrics
  9. received bool
  10. }
  11. type metricsReceivedIndex struct {
  12. m map[string]*metricReceived
  13. }
  14. func newMetricsReceivedIndex(pdms []pmetric.Metrics) *metricsReceivedIndex {
  15. mi := &metricsReceivedIndex{m: map[string]*metricReceived{}}
  16. for _, pdm := range pdms {
  17. metrics := pdm.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics()
  18. name := metrics.At(0).Name()
  19. mi.m[name] = &metricReceived{pdm: pdm}
  20. }
  21. return mi
  22. }
  23. func (mi *metricsReceivedIndex) lookup(name string) (*metricReceived, bool) {
  24. mr, ok := mi.m[name]
  25. return mr, ok
  26. }
  27. func (mi *metricsReceivedIndex) allReceived() bool {
  28. for _, m := range mi.m {
  29. if !m.received {
  30. return false
  31. }
  32. }
  33. return true
  34. }