@ -684,6 +684,7 @@ func newBasicScrapeLoop(t testing.TB, ctx context.Context, scraper scraper, app
false ,
newTestScrapeMetrics ( t ) ,
false ,
model . LegacyValidation ,
)
}
@ -826,6 +827,7 @@ func TestScrapeLoopRun(t *testing.T) {
false ,
scrapeMetrics ,
false ,
model . LegacyValidation ,
)
// The loop must terminate during the initial offset if the context
@ -970,6 +972,7 @@ func TestScrapeLoopMetadata(t *testing.T) {
false ,
scrapeMetrics ,
false ,
model . LegacyValidation ,
)
defer cancel ( )
@ -1065,6 +1068,40 @@ func TestScrapeLoopFailWithInvalidLabelsAfterRelabel(t *testing.T) {
require . Equal ( t , 0 , seriesAdded )
}
func TestScrapeLoopFailLegacyUnderUTF8 ( t * testing . T ) {
// Test that scrapes fail when default validation is utf8 but scrape config is
// legacy.
model . NameValidationScheme = model . UTF8Validation
defer func ( ) {
model . NameValidationScheme = model . LegacyValidation
} ( )
s := teststorage . New ( t )
defer s . Close ( )
ctx , cancel := context . WithCancel ( context . Background ( ) )
defer cancel ( )
sl := newBasicScrapeLoop ( t , ctx , & testScraper { } , s . Appender , 0 )
sl . validationScheme = model . LegacyValidation
slApp := sl . appender ( ctx )
total , added , seriesAdded , err := sl . append ( slApp , [ ] byte ( "{\"test.metric\"} 1\n" ) , "" , time . Time { } )
require . ErrorContains ( t , err , "invalid metric name or label names" )
require . NoError ( t , slApp . Rollback ( ) )
require . Equal ( t , 1 , total )
require . Equal ( t , 0 , added )
require . Equal ( t , 0 , seriesAdded )
// When scrapeloop has validation set to UTF-8, the metric is allowed.
sl . validationScheme = model . UTF8Validation
slApp = sl . appender ( ctx )
total , added , seriesAdded , err = sl . append ( slApp , [ ] byte ( "{\"test.metric\"} 1\n" ) , "" , time . Time { } )
require . NoError ( t , err )
require . Equal ( t , 1 , total )
require . Equal ( t , 1 , added )
require . Equal ( t , 1 , seriesAdded )
}
func makeTestMetrics ( n int ) [ ] byte {
// Construct a metrics string to parse
sb := bytes . Buffer { }