(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func TestValidateLabels(t *testing.T) { |
| 106 | cfg := new(Limits) |
| 107 | userID := "testUser" |
| 108 | |
| 109 | reg := prometheus.NewRegistry() |
| 110 | validateMetrics := NewValidateMetrics(reg) |
| 111 | |
| 112 | cfg.MaxLabelValueLength = 25 |
| 113 | cfg.MaxLabelNameLength = 25 |
| 114 | cfg.MaxLabelNamesPerSeries = 2 |
| 115 | cfg.MaxLabelsSizeBytes = 90 |
| 116 | cfg.EnforceMetricName = true |
| 117 | cfg.LimitsPerLabelSet = []LimitsPerLabelSet{ |
| 118 | { |
| 119 | Limits: LimitsPerLabelSetEntry{MaxSeries: 0}, |
| 120 | LabelSet: labels.FromMap(map[string]string{ |
| 121 | model.MetricNameLabel: "foo", |
| 122 | }), |
| 123 | Hash: 0, |
| 124 | }, |
| 125 | // Default partition |
| 126 | { |
| 127 | Limits: LimitsPerLabelSetEntry{MaxSeries: 0}, |
| 128 | LabelSet: labels.EmptyLabels(), |
| 129 | Hash: 1, |
| 130 | }, |
| 131 | } |
| 132 | |
| 133 | for _, c := range []struct { |
| 134 | metric model.Metric |
| 135 | skipLabelNameValidation bool |
| 136 | err error |
| 137 | }{ |
| 138 | { |
| 139 | map[model.LabelName]model.LabelValue{model.MetricNameLabel: "valid", "foo ": "bar"}, |
| 140 | false, |
| 141 | newInvalidLabelError([]cortexpb.LabelAdapter{ |
| 142 | {Name: model.MetricNameLabel, Value: "valid"}, |
| 143 | {Name: "foo ", Value: "bar"}, |
| 144 | }, "foo "), |
| 145 | }, |
| 146 | { |
| 147 | map[model.LabelName]model.LabelValue{model.MetricNameLabel: "valid:name"}, |
| 148 | false, |
| 149 | nil, |
| 150 | }, |
| 151 | { |
| 152 | map[model.LabelName]model.LabelValue{model.MetricNameLabel: "badLabelName", "this_is_a_really_really_long_name_that_should_cause_an_error": "test_value_please_ignore"}, |
| 153 | false, |
| 154 | newLabelNameTooLongError([]cortexpb.LabelAdapter{ |
| 155 | {Name: model.MetricNameLabel, Value: "badLabelName"}, |
| 156 | {Name: "this_is_a_really_really_long_name_that_should_cause_an_error", Value: "test_value_please_ignore"}, |
| 157 | }, "this_is_a_really_really_long_name_that_should_cause_an_error", cfg.MaxLabelNameLength), |
| 158 | }, |
| 159 | { |
| 160 | map[model.LabelName]model.LabelValue{model.MetricNameLabel: "badLabelValue", "much_shorter_name": "test_value_please_ignore_no_really_nothing_to_see_here"}, |
| 161 | false, |
| 162 | newLabelValueTooLongError([]cortexpb.LabelAdapter{ |
nothing calls this directly
no test coverage detected