Merge pull request #151 from msiebuhr/fuzz-text
Fuzzer for the text parser.
This commit is contained in:
commit
ab77666071
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2014 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Build only when actually fuzzing
|
||||
// +build gofuzz
|
||||
|
||||
package text
|
||||
|
||||
import "bytes"
|
||||
|
||||
// Fuzz text metric parser with with github.com/dvyukov/go-fuzz:
|
||||
//
|
||||
// go-fuzz-build github.com/prometheus/client_golang/text
|
||||
// go-fuzz -bin text-fuzz.zip -workdir fuzz
|
||||
//
|
||||
// Further input samples should go in the folder fuzz/corpus.
|
||||
func Fuzz(in []byte) int {
|
||||
parser := Parser{}
|
||||
_, err := parser.TextToMetricFamilies(bytes.NewReader(in))
|
||||
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
minimal_metric 1.234
|
||||
another_metric -3e3 103948
|
||||
# Even that:
|
||||
no_labels{} 3
|
||||
# HELP line for non-existing metric will be ignored.
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
# A normal comment.
|
||||
#
|
||||
# TYPE name counter
|
||||
name{labelname="val1",basename="basevalue"} NaN
|
||||
name {labelname="val2",basename="base\"v\\al\nue"} 0.23 1234567890
|
||||
# HELP name two-line\n doc str\\ing
|
||||
|
||||
# HELP name2 doc str"ing 2
|
||||
# TYPE name2 gauge
|
||||
name2{labelname="val2" ,basename = "basevalue2" } +Inf 54321
|
||||
name2{ labelname = "val1" , }-Inf
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
# TYPE my_summary summary
|
||||
my_summary{n1="val1",quantile="0.5"} 110
|
||||
decoy -1 -2
|
||||
my_summary{n1="val1",quantile="0.9"} 140 1
|
||||
my_summary_count{n1="val1"} 42
|
||||
# Latest timestamp wins in case of a summary.
|
||||
my_summary_sum{n1="val1"} 4711 2
|
||||
fake_sum{n1="val1"} 2001
|
||||
# TYPE another_summary summary
|
||||
another_summary_count{n2="val2",n1="val1"} 20
|
||||
my_summary_count{n2="val2",n1="val1"} 5 5
|
||||
another_summary{n1="val1",n2="val2",quantile=".3"} -1.2
|
||||
my_summary_sum{n1="val2"} 08 15
|
||||
my_summary{n1="val3", quantile="0.2"} 4711
|
||||
my_summary{n1="val1",n2="val2",quantile="-12.34",} NaN
|
||||
# some
|
||||
# funny comments
|
||||
# HELP
|
||||
# HELP
|
||||
# HELP my_summary
|
||||
# HELP my_summary
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
# HELP request_duration_microseconds The response latency.
|
||||
# TYPE request_duration_microseconds histogram
|
||||
request_duration_microseconds_bucket{le="100"} 123
|
||||
request_duration_microseconds_bucket{le="120"} 412
|
||||
request_duration_microseconds_bucket{le="144"} 592
|
||||
request_duration_microseconds_bucket{le="172.8"} 1524
|
||||
request_duration_microseconds_bucket{le="+Inf"} 2693
|
||||
request_duration_microseconds_sum 1.7560473e+06
|
||||
request_duration_microseconds_count 2693
|
|
@ -0,0 +1 @@
|
|||
bla 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{label="\t"} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{label="bla"} 3.14 2 3
|
|
@ -0,0 +1 @@
|
|||
metric{label="bla"} blubb
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
# HELP metric one
|
||||
# HELP metric two
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
# TYPE metric counter
|
||||
# TYPE metric untyped
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
metric 4.12
|
||||
# TYPE metric counter
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
# TYPE metric bla
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
# TYPE met-ric
|
|
@ -0,0 +1 @@
|
|||
@invalidmetric{label="bla"} 3.14 2
|
|
@ -0,0 +1 @@
|
|||
{label="bla"} 3.14 2
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
# TYPE metric histogram
|
||||
metric_bucket{le="bla"} 3.14
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
metric{label="new
|
||||
line"} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{@="bla"} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{__name__="bla"} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{label+="bla"} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{label=bla} 3.14
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
# TYPE metric summary
|
||||
metric{quantile="bla"} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{label="bla"+} 3.14
|
|
@ -0,0 +1 @@
|
|||
metric{label="bla"} 3.14 2.72
|
|
@ -0,0 +1 @@
|
|||
m{} 0
|
Loading…
Reference in New Issue