@@ -30,6 +30,30 @@ func TestPrometheus_Use(t *testing.T) {
3030 unregister (p )
3131}
3232
33+ func TestPrometheus_Buckets (t * testing.T ) {
34+ e := echo .New ()
35+ p := NewPrometheus ("echo" , nil )
36+ p .Use (e )
37+
38+ path := "/ping"
39+
40+ g := gofight .New ()
41+ g .GET (path ).Run (e , func (r gofight.HTTPResponse , rq gofight.HTTPRequest ) { assert .Equal (t , http .StatusNotFound , r .Code ) })
42+
43+ g .GET (p .MetricsPath ).Run (e , func (r gofight.HTTPResponse , rq gofight.HTTPRequest ) {
44+ assert .Equal (t , http .StatusOK , r .Code )
45+ assert .Contains (t , r .Body .String (), fmt .Sprintf ("%s_request_duration_seconds" , p .Subsystem ))
46+ assert .Regexp (t , "request_duration_seconds.*le=\" 0.005\" " , r .Body .String (), "duration should have time bucket (like, 0.005s)" )
47+ assert .NotRegexp (t , "request_duration_seconds.*le=\" 512000\" " , r .Body .String (), "duration should NOT have a size bucket (like, 512K)" )
48+ assert .Regexp (t , "response_size_bytes.*le=\" 512000\" " , r .Body .String (), "response size should have a 512K (size) bucket" )
49+ assert .NotRegexp (t , "response_size_bytes.*le=\" 0.005\" " , r .Body .String (), "response size should NOT have time bucket (like, 0.005s)" )
50+ assert .Regexp (t , "request_size_bytes.*le=\" 512000\" " , r .Body .String (), "request size should have a 512K (size) bucket" )
51+ assert .NotRegexp (t , "request_size_bytes.*le=\" 0.005\" " , r .Body .String (), "request should NOT have time bucket (like, 0.005s)" )
52+ })
53+
54+ unregister (p )
55+ }
56+
3357func TestPath (t * testing.T ) {
3458 p := NewPrometheus ("echo" , nil )
3559 assert .Equal (t , p .MetricsPath , defaultMetricPath , "no usage of path should yield default path" )
0 commit comments