Repository: prometheus/prometheus
File: storage/remote/queue_manager_test.go (Go)

Code before:

// TestPopulateV2TimeSeries_AgentMode verifies that type and unit labels are properly
// extracted from labels even when d.metadata is nil (agent mode scenario).
func TestPopulateV2TimeSeries_AgentMode(t *testing.T) {
	symbolTable := writev2.NewSymbolTable()

	testCases := []struct {
		name              string
		typeLabel         string
		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",
			},

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

Code after:

// TestPopulateV2TimeSeries_MetadataAndTypeAndUnit verifies that type and unit labels are properly
// extracted from labels even when d.metadata is not nil (agent mode scenario).
// Regression test for https://github.com/prometheus/prometheus/issues/17381.
func TestPopulateV2TimeSeries_MetadataAndTypeAndUnit(t *testing.T) {
	symbolTable := writev2.NewSymbolTable()

	testCases := []struct {
		name              string
		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",