ronantakizawa/codereview-bench huggingface dataset:
Repository: prometheus/prometheus
File: discovery/kubernetes/endpoints.go (Go)

Code before:
			epAddCount.Inc()
			e.enqueue(o)
		},
		UpdateFunc: func(_, o any) {
			epUpdateCount.Inc()
			e.enqueue(o)
		},
		DeleteFunc: func(o any) {
			epDeleteCount.Inc()
			e.enqueue(o)
		},
	})
	if err != nil {
		l.Error("Error adding endpoints event handler.", "err", err)
	}

	serviceUpdate := func(o any) {
		svc, err := convertToService(o)
		if err != nil {
			e.logger.Error("converting to Service object failed", "err", err)
			return
		}

		obj, exists, err := e.endpointsStore.GetByKey(namespacedName(svc.Namespace, svc.Name))
		if exists && err == nil {
			e.enqueue(obj.(*apiv1.Endpoints)) //nolint:staticcheck // We are still supporting the endpoints API
		}

		if err != nil {
			e.logger.Error("retrieving endpoints failed", "err", err)
		}
	}
	_, err = e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
		// TODO(fabxc): potentially remove add and delete event handlers. Those should
		// be triggered via the endpoint handlers already.
		AddFunc: func(o any) {
			svcAddCount.Inc()
			serviceUpdate(o)
		},
		UpdateFunc: func(_, o any) {
			svcUpdateCount.Inc()
			serviceUpdate(o)
		},
		DeleteFunc: func(o any) {
			svcDeleteCount.Inc()
			serviceUpdate(o)
		},
	})
	if err != nil {
		l.Error("Error adding services event handler.", "err", err)
	}

Review comment (suggestion):
it's better to have an exception for this exact deprecation globally in https://github.com/prometheus/prometheus/blob/7416f33df5789a6423f46c36390d62e41a6a317d/.golangci.yml#L47, with a comment in there.
to avoid such comments everywhere

Code after:
		AddFunc: func(o any) {
			epAddCount.Inc()
			e.enqueue(o)
		},
		UpdateFunc: func(_, o any) {
			epUpdateCount.Inc()
			e.enqueue(o)
		},
		DeleteFunc: func(o any) {
			epDeleteCount.Inc()
			e.enqueue(o)
		},
	})
	if err != nil {
		l.Error("Error adding endpoints event handler.", "err", err)
	}

	serviceUpdate := func(o any) {
		svc, err := convertToService(o)
		if err != nil {
			e.logger.Error("converting to Service object failed", "err", err)
			return
		}

		obj, exists, err := e.endpointsStore.GetByKey(namespacedName(svc.Namespace, svc.Name))
		if exists && err == nil {
			e.enqueue(obj.(*apiv1.Endpoints))
		}

		if err != nil {
			e.logger.Error("retrieving endpoints failed", "err", err)
		}
	}
	_, err = e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
		// TODO(fabxc): potentially remove add and delete event handlers. Those should
		// be triggered via the endpoint handlers already.
		AddFunc: func(o any) {
			svcAddCount.Inc()
			serviceUpdate(o)
		},
		UpdateFunc: func(_, o any) {
			svcUpdateCount.Inc()
			serviceUpdate(o)
		},
		DeleteFunc: func(o any) {
			svcDeleteCount.Inc()
			serviceUpdate(o)
		},
	})
	if err != nil {
		l.Error("Error adding services event handler.", "err", err)
Repository: prometheus/prometheus
File: tsdb/chunkenc/float_histogram_test.go (Go)

Code before:
				Schema:        schema,
				Count:         10,
				Sum:           15.0,
				ZeroThreshold: 1e-100,
				PositiveSpans: []histogram.Span{
					{Offset: 0, Length: 2},
					{Offset: 1, Length: 2},
				},
				PositiveBuckets: []float64{1, 2, 3, 4},
			}

			c := NewFloatHistogramChunk()
			app, err := c.Appender()
			require.NoError(t, err)

			_, _, _, err = app.AppendFloatHistogram(nil, 1, h, false)
			require.NoError(t, err)

			it := c.Iterator(nil)
			require.Equal(t, ValNone, it.Next())
			require.EqualError(t, it.Err(), fmt.Sprintf("invalid histogram schema %d", schema))
		})
	}
}

func TestFloatHistogramIteratorReduceShema(t *testing.T) {
	for _, schema := range []int32{9, 52} {
		t.Run(fmt.Sprintf("schema %d", schema), func(t *testing.T) {
			h := &histogram.FloatHistogram{
				Schema:        schema,
				Count:         10,
				Sum:           15.0,
				ZeroThreshold: 1e-100,
				PositiveSpans: []histogram.Span{
					{Offset: 0, Length: 2},
					{Offset: 1, Length: 2},
				},
				PositiveBuckets: []float64{1, 2, 3, 4},
			}

			c := NewFloatHistogramChunk()
			app, err := c.Appender()
			require.NoError(t, err)

			_, _, _, err = app.AppendFloatHistogram(nil, 1, h, false)
			require.NoError(t, err)

			it := c.Iterator(nil)
			require.Equal(t, ValFloatHistogram, it.Next())
			_, rh := it.AtFloatHistogram(nil)
			require.Equal(t, histogram.ExponentialSchemaMax, rh.Schema)

Review comment (suggestion):
```suggestion
func TestFloatHistogramIteratorReduceSchema(t *testing.T) {
```

Code after:
				Schema:        schema,
				Count:         10,
				Sum:           15.0,
				ZeroThreshold: 1e-100,
				PositiveSpans: []histogram.Span{
					{Offset: 0, Length: 2},
					{Offset: 1, Length: 2},
				},
				PositiveBuckets: []float64{1, 2, 3, 4},
			}

			c := NewFloatHistogramChunk()
			app, err := c.Appender()
			require.NoError(t, err)

			_, _, _, err = app.AppendFloatHistogram(nil, 1, h, false)
			require.NoError(t, err)

			it := c.Iterator(nil)
			require.Equal(t, ValNone, it.Next())
			require.ErrorIs(t, it.Err(), histogram.ErrHistogramsUnknownSchema)
		})
	}
}

func TestFloatHistogramIteratorReduceSchema(t *testing.T) {
	for _, schema := range []int32{9, 52} {
		t.Run(fmt.Sprintf("schema %d", schema), func(t *testing.T) {
			h := &histogram.FloatHistogram{
				Schema:        schema,
				Count:         10,
				Sum:           15.0,
				ZeroThreshold: 1e-100,
				PositiveSpans: []histogram.Span{
					{Offset: 0, Length: 2},
					{Offset: 1, Length: 2},
				},
				PositiveBuckets: []float64{1, 2, 3, 4},
			}

			c := NewFloatHistogramChunk()
			app, err := c.Appender()
			require.NoError(t, err)

			_, _, _, err = app.AppendFloatHistogram(nil, 1, h, false)
			require.NoError(t, err)

			it := c.Iterator(nil)
			require.Equal(t, ValFloatHistogram, it.Next())
			_, rh := it.AtFloatHistogram(nil)
			require.Equal(t, histogram.ExponentialSchemaMax, rh.Schema)
Repository: prometheus/prometheus
File: cmd/promtool/metrics_test.go (Go)

Code before:
	"net/http/httptest"
	"net/url"
	"os"
	"testing"
	"time"

	"github.com/stretchr/testify/require"
)

func TestPushMetrics(t *testing.T) {
	tests := []struct {
		name           string
		metricsData    string
		expectedStatus int
		serverHandler  http.HandlerFunc
	}{
		{
			name: "successful push with v1",
			metricsData: `# HELP test_metric A test metric
# TYPE test_metric gauge
test_metric{label="value1"} 42.0
test_metric{label="value2"} 43.0
`,
			expectedStatus: successExitCode,
			serverHandler: func(w http.ResponseWriter, r *http.Request) {
				// Verify request headers
				require.Equal(t, "snappy", r.Header.Get("Content-Encoding"))
				require.Equal(t, "application/x-protobuf", r.Header.Get("Content-Type"))
				require.Equal(t, "0.1.0", r.Header.Get("X-Prometheus-Remote-Write-Version"))

				// Read the body to ensure it's not empty
				body, err := io.ReadAll(r.Body)
				require.NoError(t, err)
				require.NotEmpty(t, body, "Request body should not be empty")

				w.WriteHeader(http.StatusNoContent)
			},
		},
		{
			name: "successful push with v2 and stats",
			metricsData: `# HELP test_counter A test counter
# TYPE test_counter counter
test_counter 100
`,
			expectedStatus: successExitCode,
			serverHandler: func(w http.ResponseWriter, _ *http.Request) {
				// Set v2 response headers with statistics
				w.Header().Set("X-Prometheus-Remote-Write-Samples-Written", "1")
				w.Header().Set("X-Prometheus-Remote-Write-Histograms-Written", "0")
				w.Header().Set("X-Prometheus-Remote-Write-Exemplars-Written", "0")
				w.WriteHeader(http.StatusNoContent)

Review comment (suggestion):
Let's make all comments full English sentences, ok? 

```suggestion
				// Verify request headers.
```

(and all below)

Code after:
	"net/http/httptest"
	"net/url"
	"os"
	"testing"
	"time"

	remoteapi "github.com/prometheus/client_golang/exp/api/remote"
	"github.com/stretchr/testify/require"
)

func TestPushMetrics(t *testing.T) {
	tests := []struct {
		name        string
		metricsData string
	}{
		{
			name: "successful push with gauge metrics",
			metricsData: `# HELP test_metric A test metric
# TYPE test_metric gauge
test_metric{label="value1"} 42.0
test_metric{label="value2"} 43.0
`,
		},
		{
			name: "successful push with counter metrics",
			metricsData: `# HELP test_counter A test counter
# TYPE test_counter counter
test_counter 100
`,
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			// Create test server using client_golang's remote write handler.
			store := &mockStorage{}
			handler := remoteapi.NewWriteHandler(
				store,
				remoteapi.MessageTypes{remoteapi.WriteV1MessageType},
			)

			server := httptest.NewServer(handler)
			defer server.Close()

			serverURL, err := url.Parse(server.URL)
			require.NoError(t, err)

			// Create a temp file with metrics data.
			tmpFile := t.TempDir() + "/metrics.txt"
			err = os.WriteFile(tmpFile, []byte(tc.metricsData), 0o644)
			require.NoError(t, err)
Repository: prometheus/prometheus
File: storage/remote/client.go (Go)

Code before:
		if err != nil {
			return nil, err
		}
	}

	if conf.GoogleIAMConfig != nil {
		t, err = googleiam.NewRoundTripper(conf.GoogleIAMConfig, t)
		if err != nil {
			return nil, err
		}
	}

	writeProtoMsg := config.RemoteWriteProtoMsgV1
	if conf.WriteProtoMsg != "" {
		writeProtoMsg = conf.WriteProtoMsg
	}
	httpClient.Transport = otelhttp.NewTransport(
		t,
		otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace {
			return otelhttptrace.NewClientTrace(ctx, otelhttptrace.WithoutSubSpans())
		}))

	// Initialize the client_golang remote write API
	writeAPI, err := remoteapi.NewAPI(conf.URL.String(), remoteapi.WithAPIHTTPClient(httpClient))
	if err != nil {
		return nil, fmt.Errorf("failed to create remote write API: %w", err)
	}

	return &Client{
		remoteName:       name,
		urlString:        conf.URL.String(),
		Client:           httpClient,
		retryOnRateLimit: conf.RetryOnRateLimit,
		timeout:          time.Duration(conf.Timeout),
		writeProtoMsg:    writeProtoMsg,
		writeCompression: compression.Snappy,
		writeAPI:         writeAPI,
	}, nil
}

func newInjectHeadersRoundTripper(h map[string]string, underlyingRT http.RoundTripper) *injectHeadersRoundTripper {
	return &injectHeadersRoundTripper{headers: h, RoundTripper: underlyingRT}
}

type injectHeadersRoundTripper struct {
	headers map[string]string
	http.RoundTripper
}

func (t *injectHeadersRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	for key, value := range t.headers {

Review comment (bug):
We are not strict with this (IMO we should), but it's clear it failed (we are creating an error type), so it's enough to just say what failed (where).

```suggestion
		return nil, fmt.Errorf("create remote write API: %w", err)
```

Code after:
	}

	if conf.GoogleIAMConfig != nil {
		t, err = googleiam.NewRoundTripper(conf.GoogleIAMConfig, t)
		if err != nil {
			return nil, err
		}
	}

	writeProtoMsg := remoteapi.WriteV1MessageType
	if conf.WriteProtoMsg != "" {
		writeProtoMsg = conf.WriteProtoMsg
	}
	httpClient.Transport = otelhttp.NewTransport(
		t,
		otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace {
			return otelhttptrace.NewClientTrace(ctx, otelhttptrace.WithoutSubSpans())
		}))

	return &Client{
		remoteName:       name,
		urlString:        conf.URL.String(),
		Client:           httpClient,
		retryOnRateLimit: conf.RetryOnRateLimit,
		timeout:          time.Duration(conf.Timeout),
		writeProtoMsg:    writeProtoMsg,
		writeCompression: remoteapi.SnappyBlockCompression,
	}, nil
}

func newInjectHeadersRoundTripper(h map[string]string, underlyingRT http.RoundTripper) *injectHeadersRoundTripper {
	return &injectHeadersRoundTripper{headers: h, RoundTripper: underlyingRT}
}

type injectHeadersRoundTripper struct {
	headers map[string]string
	http.RoundTripper
}

func (t *injectHeadersRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	for key, value := range t.headers {
		req.Header.Set(key, value)
	}
	return t.RoundTripper.RoundTrip(req)
}

const defaultBackoff = 0

type RecoverableError struct {
	error
	retryAfter model.Duration
Repository: prometheus/prometheus
File: cmd/promtool/metrics.go (Go)

Code before:
		if parseAndPushMetrics(writeAPI, data, labels) {
			fmt.Printf("  SUCCESS: metrics file %s pushed to remote write.\n", file)
			continue
		}
		failed = true
	}

	if failed {
		return failureExitCode
	}

	return successExitCode
}

func parseAndPushMetrics(writeAPI *remoteapi.API, data []byte, labels map[string]string) bool {
	metricsData, err := fmtutil.MetricTextToWriteRequest(bytes.NewReader(data), labels)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	// Use remoteapi.Write which handles marshaling and compression internally.
	// Default to V1 for compatibility.
	_, err = writeAPI.Write(context.Background(), remoteapi.WriteV1MessageType, metricsData)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	return true
}

type setHeadersTransport struct {
	http.RoundTripper
	headers map[string]string
}

func (s *setHeadersTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	for key, value := range s.headers {
		req.Header.Set(key, value)
	}
	return s.RoundTripper.RoundTrip(req)
}


Review comment (suggestion):
Suggestion: We could print statistics here (the first response param you set to `_`). We could add those to err if we want.

Code after:
		if parseAndPushMetrics(writeAPI, data, labels) {
			fmt.Printf("  SUCCESS: metrics file %s pushed to remote write.\n", file)
			continue
		}
		failed = true
	}

	if failed {
		return failureExitCode
	}

	return successExitCode
}

func parseAndPushMetrics(writeAPI *remoteapi.API, data []byte, labels map[string]string) bool {
	metricsData, err := fmtutil.MetricTextToWriteRequest(bytes.NewReader(data), labels)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	// Use remoteapi.Write which handles marshaling and compression internally.
	// TODO: Add feature flags to support V2.
	_, err = writeAPI.Write(context.Background(), remoteapi.WriteV1MessageType, metricsData)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	return true
}

type setHeadersTransport struct {
	http.RoundTripper
	headers map[string]string
}

func (s *setHeadersTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	for key, value := range s.headers {
		req.Header.Set(key, value)
	}
	return s.RoundTripper.RoundTrip(req)
}
Repository: prometheus/prometheus
File: cmd/promtool/metrics.go (Go)

Code before:
		}

		fmt.Printf("Parsing metrics file %s\n", file)
		if parseAndPushMetrics(writeAPI, data, labels) {
			fmt.Printf("  SUCCESS: metrics file %s pushed to remote write.\n", file)
			continue
		}
		failed = true
	}

	if failed {
		return failureExitCode
	}

	return successExitCode
}

func parseAndPushMetrics(writeAPI *remoteapi.API, data []byte, labels map[string]string) bool {
	metricsData, err := fmtutil.MetricTextToWriteRequest(bytes.NewReader(data), labels)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	// Use remoteapi.Write which handles marshaling and compression internally.
	// Default to V1 for compatibility.
	_, err = writeAPI.Write(context.Background(), remoteapi.WriteV1MessageType, metricsData)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	return true
}

type setHeadersTransport struct {
	http.RoundTripper
	headers map[string]string
}

func (s *setHeadersTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	for key, value := range s.headers {
		req.Header.Set(key, value)
	}
	return s.RoundTripper.RoundTrip(req)
}


Review comment (refactor):
This is not really true. This code selects v1, it's not like there is a default or a choice for promtool now.

So let's either:
* Remove this comment and add v2 support in separate PR (e.g. by adding flag what to use)
* Do the flag now in this PR

Code after:
		}

		fmt.Printf("Parsing metrics file %s\n", file)
		if parseAndPushMetrics(writeAPI, data, labels) {
			fmt.Printf("  SUCCESS: metrics file %s pushed to remote write.\n", file)
			continue
		}
		failed = true
	}

	if failed {
		return failureExitCode
	}

	return successExitCode
}

func parseAndPushMetrics(writeAPI *remoteapi.API, data []byte, labels map[string]string) bool {
	metricsData, err := fmtutil.MetricTextToWriteRequest(bytes.NewReader(data), labels)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	// Use remoteapi.Write which handles marshaling and compression internally.
	// TODO: Add feature flags to support V2.
	_, err = writeAPI.Write(context.Background(), remoteapi.WriteV1MessageType, metricsData)
	if err != nil {
		fmt.Fprintln(os.Stderr, "  FAILED:", err)
		return false
	}

	return true
}

type setHeadersTransport struct {
	http.RoundTripper
	headers map[string]string
}

func (s *setHeadersTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	for key, value := range s.headers {
		req.Header.Set(key, value)
	}
	return s.RoundTripper.RoundTrip(req)
}
Repository: prometheus/prometheus
File: web/ui/mantine-ui/src/promql/ast.ts (TypeScript)

Code before:
}

export interface BinaryExpr {
  type: nodeType.binaryExpr;
  op: binaryOperatorType;
  lhs: ASTNode;
  rhs: ASTNode;
  matching: VectorMatching | null;
  bool: boolean;
}

export interface Call {
  type: nodeType.call;
  func: Func;
  args: ASTNode[];
}

export interface MatrixSelector {
  type: nodeType.matrixSelector;
  name: string;
  matchers: LabelMatcher[];
  range: number;
  offset: number;
  timestamp: number | null;
  startOrEnd: StartOrEnd;
  anchored?: boolean;
  smoothed?: boolean;
}

export interface Subquery {
  type: nodeType.subquery;
  expr: ASTNode;
  range: number;
  offset: number;
  step: number;
  timestamp: number | null;
  startOrEnd: StartOrEnd;
}

export interface NumberLiteral {
  type: nodeType.numberLiteral;
  val: string; // Can't be 'number' because JS doesn't support NaN/Inf/-Inf etc.
}

export interface ParenExpr {
  type: nodeType.parenExpr;
  expr: ASTNode;
}

export interface StringLiteral {
  type: nodeType.stringLiteral;

Review comment (suggestion):
Since you always send these fields from the API, maybe better to also mark these fields non-optional here? (removing the `?`)

Code after:
}

export interface BinaryExpr {
  type: nodeType.binaryExpr;
  op: binaryOperatorType;
  lhs: ASTNode;
  rhs: ASTNode;
  matching: VectorMatching | null;
  bool: boolean;
}

export interface Call {
  type: nodeType.call;
  func: Func;
  args: ASTNode[];
}

export interface MatrixSelector {
  type: nodeType.matrixSelector;
  name: string;
  matchers: LabelMatcher[];
  range: number;
  offset: number;
  timestamp: number | null;
  startOrEnd: StartOrEnd;
  anchored: boolean;
  smoothed: boolean;
}

export interface Subquery {
  type: nodeType.subquery;
  expr: ASTNode;
  range: number;
  offset: number;
  step: number;
  timestamp: number | null;
  startOrEnd: StartOrEnd;
}

export interface NumberLiteral {
  type: nodeType.numberLiteral;
  val: string; // Can't be 'number' because JS doesn't support NaN/Inf/-Inf etc.
}

export interface ParenExpr {
  type: nodeType.parenExpr;
  expr: ASTNode;
}

export interface StringLiteral {
  type: nodeType.stringLiteral;
Repository: prometheus/prometheus
File: storage/remote/queue_manager_test.go (Go)

Code before:
		unitLabel         string
		metadata          *metadata.Metadata // nil simulates agent mode.
		expectedType      writev2.Metadata_MetricType
		expectedUnit      string
		enableTypeAndUnit bool
	}{
		{
			name:              "agent_mode_with_type_and_unit_labels_enabled",
			typeLabel:         "gauge",
			unitLabel:         "bytes",
			metadata:          nil, // Agent mode - no metadata records.
			expectedType:      writev2.Metadata_METRIC_TYPE_GAUGE,
			expectedUnit:      "bytes",
			enableTypeAndUnit: true,
		},
		{
			name:              "agent_mode_with_type_no_unit",
			typeLabel:         "counter",
			unitLabel:         "",
			metadata:          nil,
			expectedType:      writev2.Metadata_METRIC_TYPE_COUNTER,
			expectedUnit:      "",
			enableTypeAndUnit: true,
		},
		{
			name:              "agent_mode_disabled_feature",
			typeLabel:         "gauge",
			unitLabel:         "bytes",
			metadata:          nil,
			expectedType:      writev2.Metadata_METRIC_TYPE_UNSPECIFIED,
			expectedUnit:      "",
			enableTypeAndUnit: false,
		},
		{
			name:      "agent_mode_with_explicit_metadata",
			typeLabel: "gauge",
			unitLabel: "bytes",
			metadata: &metadata.Metadata{
				Type: model.MetricTypeGauge,
				Unit: "bytes",
				Help: "Test metric",
			},
			expectedType:      writev2.Metadata_METRIC_TYPE_GAUGE,
			expectedUnit:      "bytes",
			enableTypeAndUnit: true,
		},
		{
			name:      "labels_override_metadata_when_feature_enabled",
			typeLabel: "counter",
			unitLabel: "requests",
			metadata: &metadata.Metadata{

Review comment (suggestion):
```suggestion
			name:              "no_type_and_unit_no_meta",
```

Code after:
		typeLabel         string
		unitLabel         string
		metadata          *metadata.Metadata
		expectedType      writev2.Metadata_MetricType
		expectedUnit      string
		enableTypeAndUnit bool
	}{
		{
			name:              "type_and_unit_no_meta",
			typeLabel:         "gauge",
			unitLabel:         "bytes",
			metadata:          nil,
			expectedType:      writev2.Metadata_METRIC_TYPE_GAUGE,
			expectedUnit:      "bytes",
			enableTypeAndUnit: true,
		},
		{
			name:              "type_no_unit_no_meta",
			typeLabel:         "counter",
			unitLabel:         "",
			metadata:          nil,
			expectedType:      writev2.Metadata_METRIC_TYPE_COUNTER,
			expectedUnit:      "",
			enableTypeAndUnit: true,
		},
		{
			name:              "no_type_and_unit_no_meta",
			typeLabel:         "gauge",
			unitLabel:         "bytes",
			metadata:          nil,
			expectedType:      writev2.Metadata_METRIC_TYPE_UNSPECIFIED,
			expectedUnit:      "",
			enableTypeAndUnit: false,
		},
		{
			name:      "type_and_unit_and_meta",
			typeLabel: "gauge",
			unitLabel: "bytes",
			metadata: &metadata.Metadata{
				Type: model.MetricTypeGauge,
				Unit: "bytes",
				Help: "Test metric",
			},
			expectedType:      writev2.Metadata_METRIC_TYPE_GAUGE,
			expectedUnit:      "bytes",
			enableTypeAndUnit: true,
		},
		{
			name:      "type-and-unit-overrides-meta",
			typeLabel: "counter",
			unitLabel: "requests",