{"action":"created","issue":{"url":"https://api.github.com/repos/prometheus/prometheus/issues/2131","repository_url":"https://api.github.com/repos/prometheus/prometheus","labels_url":"https://api.github.com/repos/prometheus/prometheus/issues/2131/labels{/name}","comments_url":"https://api.github.com/repos/prometheus/prometheus/issues/2131/comments","events_url":"https://api.github.com/repos/prometheus/prometheus/issues/2131/events","html_url":"https://github.com/prometheus/prometheus/issues/2131","id":185858132,"number":2131,"title":"BucketQuantile return NaN when count is ZERO","user":{"login":"yancl","id":822378,"avatar_url":"https://avatars.githubusercontent.com/u/822378?v=3","gravatar_id":"","url":"https://api.github.com/users/yancl","html_url":"https://github.com/yancl","followers_url":"https://api.github.com/users/yancl/followers","following_url":"https://api.github.com/users/yancl/following{/other_user}","gists_url":"https://api.github.com/users/yancl/gists{/gist_id}","starred_url":"https://api.github.com/users/yancl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yancl/subscriptions","organizations_url":"https://api.github.com/users/yancl/orgs","repos_url":"https://api.github.com/users/yancl/repos","events_url":"https://api.github.com/users/yancl/events{/privacy}","received_events_url":"https://api.github.com/users/yancl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-28T07:39:22Z","updated_at":"2016-10-28T07:50:05Z","closed_at":null,"body":"Hi, \r\n\r\n  When testing our service with quantile, we found that the return value is NaN when there is\r\nno request, that means the first bucket's count is **zero**, so will you please return the first bucket's upperBound or **zero** when the count is **zero** ?\r\n\r\n```\r\n// change\r\nif count == 0 {\r\n    return bucketEnd // or 0\r\n}\r\nreturn bucketStart + (bucketEnd-bucketStart)*float64(rank/count)\r\n```\r\n\r\n```\r\n//source\r\nfunc bucketQuantile(q model.SampleValue, buckets buckets) float64 {\r\n\tif q < 0 {\r\n\t\treturn math.Inf(-1)\r\n\t}\r\n\tif q > 1 {\r\n\t\treturn math.Inf(+1)\r\n\t}\r\n\tif len(buckets) < 2 {\r\n\t\treturn math.NaN()\r\n\t}\r\n\tsort.Sort(buckets)\r\n\tif !math.IsInf(buckets[len(buckets)-1].upperBound, +1) {\r\n\t\treturn math.NaN()\r\n\t}\r\n\r\n\trank := q * buckets[len(buckets)-1].count\r\n\tb := sort.Search(len(buckets)-1, func(i int) bool { return buckets[i].count >= rank })\r\n\r\n\tif b == len(buckets)-1 {\r\n\t\treturn buckets[len(buckets)-2].upperBound\r\n\t}\r\n\tif b == 0 && buckets[0].upperBound <= 0 {\r\n\t\treturn buckets[0].upperBound\r\n\t}\r\n\tvar (\r\n\t\tbucketStart float64\r\n\t\tbucketEnd   = buckets[b].upperBound\r\n\t\tcount       = buckets[b].count\r\n\t)\r\n\tif b > 0 {\r\n\t\tbucketStart = buckets[b-1].upperBound\r\n\t\tcount -= buckets[b-1].count\r\n\t\trank -= buckets[b-1].count\r\n\t}\r\n\treturn bucketStart + (bucketEnd-bucketStart)*float64(rank/count)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/prometheus/prometheus/issues/comments/256858402","html_url":"https://github.com/prometheus/prometheus/issues/2131#issuecomment-256858402","issue_url":"https://api.github.com/repos/prometheus/prometheus/issues/2131","id":256858402,"user":{"login":"brian-brazil","id":7115638,"avatar_url":"https://avatars.githubusercontent.com/u/7115638?v=3","gravatar_id":"","url":"https://api.github.com/users/brian-brazil","html_url":"https://github.com/brian-brazil","followers_url":"https://api.github.com/users/brian-brazil/followers","following_url":"https://api.github.com/users/brian-brazil/following{/other_user}","gists_url":"https://api.github.com/users/brian-brazil/gists{/gist_id}","starred_url":"https://api.github.com/users/brian-brazil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brian-brazil/subscriptions","organizations_url":"https://api.github.com/users/brian-brazil/orgs","repos_url":"https://api.github.com/users/brian-brazil/repos","events_url":"https://api.github.com/users/brian-brazil/events{/privacy}","received_events_url":"https://api.github.com/users/brian-brazil/received_events","type":"User","site_admin":false},"created_at":"2016-10-28T07:50:05Z","updated_at":"2016-10-28T07:50:05Z","body":"NaN is the correct result when there is no data. This is in line with `_sum / _count` which also returns NaN in that case."}}
{"actor":{"display_login":"brian-brazil"}}