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

Code before:
		"foo", "bar",
	)

	floatMetadata := Metadata{
		Metadata: metadata.Metadata{
			Type: model.MetricTypeCounter,
			Unit: "bytes",
			Help: "some help",
		},
		MetricFamilyName: "test_bytes_total",
	}

	t.Run("happy case with CT zero, reference is passed and reused", func(t *testing.T) {
		app := &appenderRecorder{}
		capp := NewCombinedAppender(app, promslog.NewNopLogger(), true, false, NewCombinedAppenderMetrics(prometheus.NewRegistry()))

		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 1, 2, 42.0, nil))

		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 3, 4, 62.0, []exemplar.Exemplar{
			{
				Labels: labels.FromStrings("tracid", "122"),
				Value:  1337,
			},
		}))

		// With appendMetadata=false, UpdateMetadata should NOT be called
		require.Len(t, app.records, 5)
		requireEqualOpAndRef(t, "AppendCTZeroSample", 0, app.records[0])
		ref := app.records[0].outRef
		require.NotZero(t, ref)
		requireEqualOpAndRef(t, "Append", ref, app.records[1])
		requireEqualOpAndRef(t, "AppendCTZeroSample", ref, app.records[2])
		requireEqualOpAndRef(t, "Append", ref, app.records[3])
		requireEqualOpAndRef(t, "AppendExemplar", ref, app.records[4])
	})

	t.Run("error on second CT ingest doesn't update the reference", func(t *testing.T) {
		app := &appenderRecorder{}
		capp := NewCombinedAppender(app, promslog.NewNopLogger(), true, false, NewCombinedAppenderMetrics(prometheus.NewRegistry()))

		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 1, 2, 42.0, nil))

		app.appendCTZeroSampleError = errors.New("test error")
		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 3, 4, 62.0, nil))

		// With appendMetadata=false, UpdateMetadata should NOT be called
		require.Len(t, app.records, 4)
		requireEqualOpAndRef(t, "AppendCTZeroSample", 0, app.records[0])
		ref := app.records[0].outRef
		require.NotZero(t, ref)
		requireEqualOpAndRef(t, "Append", ref, app.records[1])

Review comment (suggestion):
This is a bit out of context, when reading the test for the first time, I'd just leave it out.
```suggestion
```

Code after:
		model.MetricNameLabel, "test_bytes_total",
		"foo", "bar",
	)

	floatMetadata := Metadata{
		Metadata: metadata.Metadata{
			Type: model.MetricTypeCounter,
			Unit: "bytes",
			Help: "some help",
		},
		MetricFamilyName: "test_bytes_total",
	}

	t.Run("happy case with CT zero, reference is passed and reused", func(t *testing.T) {
		app := &appenderRecorder{}
		capp := NewCombinedAppender(app, promslog.NewNopLogger(), true, false, NewCombinedAppenderMetrics(prometheus.NewRegistry()))

		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 1, 2, 42.0, nil))

		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 3, 4, 62.0, []exemplar.Exemplar{
			{
				Labels: labels.FromStrings("tracid", "122"),
				Value:  1337,
			},
		}))

		require.Len(t, app.records, 5)
		requireEqualOpAndRef(t, "AppendCTZeroSample", 0, app.records[0])
		ref := app.records[0].outRef
		require.NotZero(t, ref)
		requireEqualOpAndRef(t, "Append", ref, app.records[1])
		requireEqualOpAndRef(t, "AppendCTZeroSample", ref, app.records[2])
		requireEqualOpAndRef(t, "Append", ref, app.records[3])
		requireEqualOpAndRef(t, "AppendExemplar", ref, app.records[4])
	})

	t.Run("error on second CT ingest doesn't update the reference", func(t *testing.T) {
		app := &appenderRecorder{}
		capp := NewCombinedAppender(app, promslog.NewNopLogger(), true, false, NewCombinedAppenderMetrics(prometheus.NewRegistry()))

		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 1, 2, 42.0, nil))

		app.appendCTZeroSampleError = errors.New("test error")
		require.NoError(t, capp.AppendSample(seriesLabels.Copy(), floatMetadata, 3, 4, 62.0, nil))

		require.Len(t, app.records, 4)
		requireEqualOpAndRef(t, "AppendCTZeroSample", 0, app.records[0])
		ref := app.records[0].outRef
		require.NotZero(t, ref)
		requireEqualOpAndRef(t, "Append", ref, app.records[1])
		requireEqualOpAndRef(t, "AppendCTZeroSample", ref, app.records[2])