Skip to content

Commit 24dea0a

Browse files
committed
fix lint and tests
Signed-off-by: 7h3-3mp7y-m4n <emailtorash@gmail.com>
1 parent 30ac251 commit 24dea0a

File tree

20 files changed

+218
-112
lines changed

20 files changed

+218
-112
lines changed

pkg/alertmanager/alertmanagerpb/alertmanager.pb.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/alertmanager/alertspb/alerts.pb.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cortexpb/cortex.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/distributor/distributor_test.go

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,59 +2036,140 @@ func TestDistributor_Push_ShouldGuaranteeShardingTokenConsistencyOverTheTime(t *
20362036
}
20372037
}
20382038

2039+
// func TestDistributor_Push_LabelNameValidation(t *testing.T) {
2040+
// model.NameValidationScheme = model.LegacyValidation
2041+
// t.Parallel()
2042+
// inputLabels := labels.Labels{
2043+
// {Name: model.MetricNameLabel, Value: "foo"},
2044+
// {Name: "999.illegal", Value: "baz"},
2045+
// }
2046+
// ctx := user.InjectOrgID(context.Background(), "user")
2047+
2048+
// tests := map[string]struct {
2049+
// inputLabels labels.Labels
2050+
// skipLabelNameValidationCfg bool
2051+
// skipLabelNameValidationReq bool
2052+
// errExpected bool
2053+
// errMessage string
2054+
// }{
2055+
// "label name validation is on by default": {
2056+
// inputLabels: inputLabels,
2057+
// errExpected: true,
2058+
// errMessage: `sample invalid label: "999.illegal" metric "foo{999.illegal=\"baz\"}"`,
2059+
// },
2060+
// "label name validation can be skipped via config": {
2061+
// inputLabels: inputLabels,
2062+
// skipLabelNameValidationCfg: true,
2063+
// errExpected: false,
2064+
// },
2065+
// "label name validation can be skipped via WriteRequest parameter": {
2066+
// inputLabels: inputLabels,
2067+
// skipLabelNameValidationReq: true,
2068+
// errExpected: false,
2069+
// },
2070+
// }
2071+
2072+
// for testName, tc := range tests {
2073+
// tc := tc
2074+
// for _, histogram := range []bool{true, false} {
2075+
// histogram := histogram
2076+
// t.Run(fmt.Sprintf("%s, histogram=%s", testName, strconv.FormatBool(histogram)), func(t *testing.T) {
2077+
// t.Parallel()
2078+
// ds, _, _, _ := prepare(t, prepConfig{
2079+
// numIngesters: 2,
2080+
// happyIngesters: 2,
2081+
// numDistributors: 1,
2082+
// shuffleShardSize: 1,
2083+
// skipLabelNameValidation: tc.skipLabelNameValidationCfg,
2084+
// })
2085+
// req := mockWriteRequest([]labels.Labels{tc.inputLabels}, 42, 100000, histogram)
2086+
// req.SkipLabelNameValidation = tc.skipLabelNameValidationReq
2087+
// _, err := ds[0].Push(ctx, req)
2088+
// if tc.errExpected {
2089+
// fromError, _ := status.FromError(err)
2090+
// assert.Equal(t, tc.errMessage, fromError.Message())
2091+
// } else {
2092+
// assert.Nil(t, err)
2093+
// }
2094+
// })
2095+
// }
2096+
// }
2097+
// }
20392098
func TestDistributor_Push_LabelNameValidation(t *testing.T) {
2040-
t.Parallel()
2041-
inputLabels := labels.Labels{
2042-
{Name: model.MetricNameLabel, Value: "foo"},
2043-
{Name: "999.illegal", Value: "baz"},
2044-
}
20452099
ctx := user.InjectOrgID(context.Background(), "user")
20462100

20472101
tests := map[string]struct {
20482102
inputLabels labels.Labels
20492103
skipLabelNameValidationCfg bool
20502104
skipLabelNameValidationReq bool
2105+
useUTF8Validation bool
20512106
errExpected bool
20522107
errMessage string
20532108
}{
20542109
"label name validation is on by default": {
2055-
inputLabels: inputLabels,
2110+
inputLabels: labels.Labels{
2111+
{Name: model.MetricNameLabel, Value: "foo"},
2112+
{Name: "999.illegal", Value: "baz"},
2113+
},
20562114
errExpected: true,
20572115
errMessage: `sample invalid label: "999.illegal" metric "foo{999.illegal=\"baz\"}"`,
20582116
},
20592117
"label name validation can be skipped via config": {
2060-
inputLabels: inputLabels,
2118+
inputLabels: labels.Labels{
2119+
{Name: model.MetricNameLabel, Value: "foo"},
2120+
{Name: "999.illegal", Value: "baz"},
2121+
},
20612122
skipLabelNameValidationCfg: true,
20622123
errExpected: false,
20632124
},
20642125
"label name validation can be skipped via WriteRequest parameter": {
2065-
inputLabels: inputLabels,
2126+
inputLabels: labels.Labels{
2127+
{Name: model.MetricNameLabel, Value: "foo"},
2128+
{Name: "999.illegal", Value: "baz"},
2129+
},
20662130
skipLabelNameValidationReq: true,
20672131
errExpected: false,
20682132
},
2133+
"UTF-8 validation allows Unicode label names": {
2134+
inputLabels: labels.Labels{
2135+
{Name: model.MetricNameLabel, Value: "foo"},
2136+
{Name: "Cortex_😃", Value: "baz"},
2137+
},
2138+
useUTF8Validation: true,
2139+
errExpected: false,
2140+
},
20692141
}
20702142

20712143
for testName, tc := range tests {
2072-
tc := tc
20732144
for _, histogram := range []bool{true, false} {
2074-
histogram := histogram
2075-
t.Run(fmt.Sprintf("%s, histogram=%s", testName, strconv.FormatBool(histogram)), func(t *testing.T) {
2076-
t.Parallel()
2145+
t.Run(fmt.Sprintf("%s, histogram=%v", testName, histogram), func(t *testing.T) {
2146+
if tc.useUTF8Validation {
2147+
// nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally for legacy validation testing
2148+
model.NameValidationScheme = model.UTF8Validation
2149+
} else {
2150+
// nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally for legacy validation testing
2151+
model.NameValidationScheme = model.LegacyValidation
2152+
}
2153+
20772154
ds, _, _, _ := prepare(t, prepConfig{
20782155
numIngesters: 2,
20792156
happyIngesters: 2,
20802157
numDistributors: 1,
20812158
shuffleShardSize: 1,
20822159
skipLabelNameValidation: tc.skipLabelNameValidationCfg,
20832160
})
2161+
20842162
req := mockWriteRequest([]labels.Labels{tc.inputLabels}, 42, 100000, histogram)
20852163
req.SkipLabelNameValidation = tc.skipLabelNameValidationReq
2164+
20862165
_, err := ds[0].Push(ctx, req)
2166+
20872167
if tc.errExpected {
2168+
require.Error(t, err)
20882169
fromError, _ := status.FromError(err)
20892170
assert.Equal(t, tc.errMessage, fromError.Message())
20902171
} else {
2091-
assert.Nil(t, err)
2172+
require.NoError(t, err)
20922173
}
20932174
})
20942175
}

pkg/distributor/distributorpb/distributor.pb.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/frontend/v1/frontendv1pb/frontend.pb.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/frontend/v2/frontendv2pb/frontend.pb.go

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ha/ha_tracker.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ingester/client/ingester.pb.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/querier/stats/stats.pb.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)