Repository: prometheus/prometheus
File: storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw_test.go (Go)

Code before:
// limitations under the License.
// Provenance-includes-location: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/95e8f8fdc2a9dc87230406c9a3cf02be4fd68bea/pkg/translator/prometheusremotewrite/metrics_to_prw_test.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: Copyright The OpenTelemetry Authors.

package prometheusremotewrite

import (
	"context"
	"fmt"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"
	"github.com/stretchr/testify/require"
	"go.opentelemetry.io/collector/pdata/pcommon"
	"go.opentelemetry.io/collector/pdata/pmetric"
	"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"

	"github.com/prometheus/prometheus/model/labels"
	"github.com/prometheus/prometheus/prompb"
	prometheustranslator "github.com/prometheus/prometheus/storage/remote/otlptranslator/prometheus"
)

func TestFromMetrics(t *testing.T) {

	for _, keepIdentifyingResourceAttributes := range []bool{false, true} {
		t.Run(fmt.Sprintf("successful/keepIdentifyingAttributes=%v", keepIdentifyingResourceAttributes), func(t *testing.T) {
			converter := NewPrometheusConverter()
			payload := createExportRequest(5, 128, 128, 2, 0)
			var expMetadata []prompb.MetricMetadata
			resourceMetricsSlice := payload.Metrics().ResourceMetrics()
			for i := 0; i < resourceMetricsSlice.Len(); i++ {
				scopeMetricsSlice := resourceMetricsSlice.At(i).ScopeMetrics()
				for j := 0; j < scopeMetricsSlice.Len(); j++ {
					metricSlice := scopeMetricsSlice.At(j).Metrics()
					for k := 0; k < metricSlice.Len(); k++ {
						metric := metricSlice.At(k)
						promName := prometheustranslator.BuildCompliantName(metric, "", false, false)
						expMetadata = append(expMetadata, prompb.MetricMetadata{
							Type:             otelMetricTypeToPromMetricType(metric),
							MetricFamilyName: promName,
							Help:             metric.Description(),
							Unit:             metric.Unit(),
						})
					}
				}
			}

			annots, err := converter.FromMetrics(
				context.Background(),

Review comment (suggestion):
[Nit] I'd prefer if you avoid adding this blank line at the function's beginning :)
```suggestion
```

Code after:
// limitations under the License.
// Provenance-includes-location: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/95e8f8fdc2a9dc87230406c9a3cf02be4fd68bea/pkg/translator/prometheusremotewrite/metrics_to_prw_test.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: Copyright The OpenTelemetry Authors.

package prometheusremotewrite

import (
	"context"
	"fmt"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"
	"github.com/stretchr/testify/require"
	"go.opentelemetry.io/collector/pdata/pcommon"
	"go.opentelemetry.io/collector/pdata/pmetric"
	"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"

	"github.com/prometheus/prometheus/model/labels"
	"github.com/prometheus/prometheus/prompb"
	prometheustranslator "github.com/prometheus/prometheus/storage/remote/otlptranslator/prometheus"
)

func TestFromMetrics(t *testing.T) {
	for _, keepIdentifyingResourceAttributes := range []bool{false, true} {
		t.Run(fmt.Sprintf("successful/keepIdentifyingAttributes=%v", keepIdentifyingResourceAttributes), func(t *testing.T) {
			converter := NewPrometheusConverter()
			payload := createExportRequest(5, 128, 128, 2, 0)
			var expMetadata []prompb.MetricMetadata
			resourceMetricsSlice := payload.Metrics().ResourceMetrics()
			for i := 0; i < resourceMetricsSlice.Len(); i++ {
				scopeMetricsSlice := resourceMetricsSlice.At(i).ScopeMetrics()
				for j := 0; j < scopeMetricsSlice.Len(); j++ {
					metricSlice := scopeMetricsSlice.At(j).Metrics()
					for k := 0; k < metricSlice.Len(); k++ {
						metric := metricSlice.At(k)
						promName := prometheustranslator.BuildCompliantName(metric, "", false, false)
						expMetadata = append(expMetadata, prompb.MetricMetadata{
							Type:             otelMetricTypeToPromMetricType(metric),
							MetricFamilyName: promName,
							Help:             metric.Description(),
							Unit:             metric.Unit(),
						})
					}
				}
			}

			annots, err := converter.FromMetrics(
				context.Background(),
				payload.Metrics(),