From ba56daba071210001e298058107208c5c7ba8d73 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Mon, 8 Jul 2019 15:46:49 +0200 Subject: [PATCH 1/8] Update prometheus client, remove deprecated InstrumentHandler method --- .golangci.yml | 4 -- go.mod | 12 +++-- go.sum | 34 ++++++++++++--- pkg/extprom/instrument_server.go | 75 ++++++++++++++++++++++++++++++++ pkg/query/api/v1.go | 3 +- pkg/rule/api/v1.go | 5 +-- pkg/ui/bucket.go | 4 +- pkg/ui/query.go | 4 +- pkg/ui/rule.go | 4 +- 9 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 pkg/extprom/instrument_server.go diff --git a/.golangci.yml b/.golangci.yml index 95a92fb61a..cd3a87e632 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,10 +4,6 @@ linters-settings: issues: exclude-rules: - # TODO: move away from deprecated prometheus.InstrumentHandler{,Func} - - linters: - - staticcheck - text: "SA1019:" # These are not being checked since these methods exist # so that no one else could implement them. - linters: diff --git a/go.mod b/go.mod index 8eb8d9985f..bb5c3216a2 100644 --- a/go.mod +++ b/go.mod @@ -32,17 +32,21 @@ require ( github.com/opentracing/basictracer-go v1.0.0 github.com/opentracing/opentracing-go v1.1.0 github.com/pkg/errors v0.8.1 - github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 - github.com/prometheus/common v0.4.0 + github.com/prometheus/client_golang v1.0.0 + github.com/prometheus/common v0.6.0 + github.com/prometheus/procfs v0.0.3 // indirect github.com/prometheus/prometheus v2.9.2+incompatible github.com/prometheus/tsdb v0.8.0 github.com/uber-go/atomic v1.4.0 // indirect github.com/uber/jaeger-client-go v2.16.0+incompatible github.com/uber/jaeger-lib v2.0.0+incompatible go.uber.org/atomic v1.4.0 // indirect + golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect + golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 - golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 - golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 + golang.org/x/sync v0.0.0-20190423024810-112230192c58 + golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect + golang.org/x/text v0.3.2 google.golang.org/api v0.3.2 google.golang.org/grpc v1.19.1 gopkg.in/alecthomas/kingpin.v2 v2.2.6 diff --git a/go.sum b/go.sum index 0aa85f1de3..a1d11a5eb0 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/aws/aws-sdk-go v0.0.0-20180507225419-00862f899353 h1:qFKf58XUUvHaEz0z github.com/aws/aws-sdk-go v0.0.0-20180507225419-00862f899353/go.mod h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/biogo/store v0.0.0-20160505134755-913427a1d5e8/go.mod h1:Iev9Q3MErcn+w3UOJD/DkEzllvugfdx7bGcMOFhvr/4= github.com/cenk/backoff v2.0.0+incompatible/go.mod h1:7FtoeaSnHoZnmZzz47cM35Y9nSW7tNyaidugnHTaFDE= @@ -106,6 +108,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCy github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v0.0.0-20150304233714-bbcb9da2d746 h1:M6d2zDTA4cKXT6OwFsJxlo5tWrAukj3KfvJ1zcBatnA= @@ -167,6 +171,7 @@ github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7 h1:SMvOWPJCES github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 h1:/UewZcckqhvnnS0C6r3Sher2hSEbVmM6Ogpcjen08+Y= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -198,8 +203,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.8 h1:1QYRAKU3lN5cRfLCkPU08hwvLJFhvjP6MqNMmQz6ZVI= github.com/miekg/dns v1.1.8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.13 h1:x7DQtkU0cedzeS8TD36tT/w1Hm4rDtfCaYYAHE7TTBI= -github.com/miekg/dns v1.1.13/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15 h1:CSSIDtllwGLMoA6zjdKnaE6Tx6eVUxQ29LUgGetiDCI= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/minio/cli v1.20.0/go.mod h1:bYxnK0uS629N3Bq+AOZZ+6lwF77Sodk4+UL9vNuXhOY= @@ -221,6 +224,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/mozillazg/go-cos v0.12.0 h1:b9hUd5HjrDe10BUfkyiLYI1+z4M2kAgKasktszx9pO4= github.com/mozillazg/go-cos v0.12.0/go.mod h1:Zp6DvvXn0RUOXGJ2chmWt2bLEqRAnJnS3DnAZsJsoaE= @@ -263,17 +267,25 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= +github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x7enabFceM= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f h1:BVwpUVJDADN2ufcGik7W992pyps0wZ888b/y9GXcLTU= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.3.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.0 h1:7etb9YClo3a6HjLzfl6rIQaU+FDfi0VSX39io3aQ+DM= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= +github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1 h1:/K3IL0Z1quvmJ7X0A1AwNEK7CRkVK3YwfOU/QAL4WGg= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= +github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/prometheus v2.9.2+incompatible h1:5QVnXpkSsbbG59TyZ99clRfaHQy2QuIlTv6dEgS66C4= github.com/prometheus/prometheus v2.9.2+incompatible/go.mod h1:vdLuLLM0uqhLSofrQ7Nev2b/rQUyZ+pkT3zF7LB/i1g= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= @@ -327,6 +339,8 @@ golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -345,6 +359,9 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -353,6 +370,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -368,13 +387,16 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20170424234030-8be79e1e0910 h1:bCMaBn7ph495H+x72gEvgcv+mDRd9dElbzo/mVCMxX4= golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/pkg/extprom/instrument_server.go b/pkg/extprom/instrument_server.go new file mode 100644 index 0000000000..21219567d0 --- /dev/null +++ b/pkg/extprom/instrument_server.go @@ -0,0 +1,75 @@ +package extprom + +import ( + "net/http" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" +) + +var ( + requestDuration = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "http_request_duration_seconds", + Help: "Tracks the latencies for HTTP requests.", + }, + []string{"code", "handler", "method"}, + ) + + requestSize = prometheus.NewSummaryVec( + prometheus.SummaryOpts{ + Name: "http_request_size_bytes", + Help: "Tracks the size of HTTP requests.", + }, + []string{"code", "handler", "method"}, + ) + + requestsTotal = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Name: "http_requests_total", + Help: "Tracks the number of HTTP requests.", + }, []string{"code", "handler", "method"}, + ) + + responseSize = prometheus.NewSummaryVec( + prometheus.SummaryOpts{ + Name: "http_response_size_bytes", + Help: "Tracks the size of HTTP responses.", + }, + []string{"code", "handler", "method"}, + ) +) + +func init() { + prometheus.MustRegister(requestDuration, requestSize, requestsTotal, responseSize) +} + +// NewInstrumentedHandler wraps the given HTTP handler for instrumentation. It +// registers four metric collectors (if not already done) and reports HTTP +// metrics to the (newly or already) registered collectors: http_requests_total +// (CounterVec), http_request_duration_seconds (Histogram), +// http_request_size_bytes (Summary), http_response_size_bytes (Summary). Each +// has a constant label named "handler" with the provided handlerName as +// value. http_requests_total is a metric vector partitioned by HTTP method +// (label name "method") and HTTP status code (label name "code"). +func NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { + return NewInstrumentedHandlerFunc(handlerName, handler.ServeHTTP) +} + +// NewInstrumentedHandlerFunc wraps the given function for instrumentation. It +// otherwise works in the same way as NewInstrumentedHandler. +func NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc { + return promhttp.InstrumentHandlerDuration( + requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}), + promhttp.InstrumentHandlerRequestSize( + requestSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), + promhttp.InstrumentHandlerCounter( + requestsTotal.MustCurryWith(prometheus.Labels{"handler": handlerName}), + promhttp.InstrumentHandlerResponseSize( + responseSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), + http.HandlerFunc(next), + ), + ), + ), + ) +} diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index 0d3645eab1..ba718ff7c4 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -29,6 +29,7 @@ import ( "github.com/NYTimes/gziphandler" "github.com/go-kit/kit/log" + "github.com/improbable-eng/thanos/pkg/extprom" "github.com/improbable-eng/thanos/pkg/query" "github.com/improbable-eng/thanos/pkg/runutil" "github.com/improbable-eng/thanos/pkg/tracing" @@ -162,7 +163,7 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log. w.WriteHeader(http.StatusNoContent) } }) - return prometheus.InstrumentHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) + return extprom.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) } r.Options("/*path", instr("options", api.options)) diff --git a/pkg/rule/api/v1.go b/pkg/rule/api/v1.go index 7a654a711f..e80f5829a3 100644 --- a/pkg/rule/api/v1.go +++ b/pkg/rule/api/v1.go @@ -7,12 +7,12 @@ import ( "github.com/NYTimes/gziphandler" "github.com/go-kit/kit/log" + "github.com/improbable-eng/thanos/pkg/extprom" qapi "github.com/improbable-eng/thanos/pkg/query/api" thanosrule "github.com/improbable-eng/thanos/pkg/rule" "github.com/improbable-eng/thanos/pkg/store/storepb" "github.com/improbable-eng/thanos/pkg/tracing" opentracing "github.com/opentracing/opentracing-go" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/route" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/rules" @@ -47,12 +47,11 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log. w.WriteHeader(http.StatusNoContent) } }) - return prometheus.InstrumentHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) + return extprom.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) } r.Get("/alerts", instr("alerts", api.alerts)) r.Get("/rules", instr("rules", api.rules)) - } type RulesRetriever interface { diff --git a/pkg/ui/bucket.go b/pkg/ui/bucket.go index 0e4d3a91d1..d352dd2083 100644 --- a/pkg/ui/bucket.go +++ b/pkg/ui/bucket.go @@ -6,7 +6,7 @@ import ( "time" "github.com/go-kit/kit/log" - "github.com/prometheus/client_golang/prometheus" + "github.com/improbable-eng/thanos/pkg/extprom" "github.com/prometheus/common/route" ) @@ -31,7 +31,7 @@ func NewBucketUI(logger log.Logger, label string) *Bucket { // Register registers http routes for bucket UI. func (b *Bucket) Register(r *route.Router) { - instrf := prometheus.InstrumentHandlerFunc + instrf := extprom.NewInstrumentedHandlerFunc r.Get("/", instrf("root", b.root)) r.Get("/static/*filepath", instrf("static", b.serveStaticAsset)) diff --git a/pkg/ui/query.go b/pkg/ui/query.go index 3bc5d243ea..78ec7a1e78 100644 --- a/pkg/ui/query.go +++ b/pkg/ui/query.go @@ -11,8 +11,8 @@ import ( "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/component" + "github.com/improbable-eng/thanos/pkg/extprom" "github.com/improbable-eng/thanos/pkg/query" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/common/route" "github.com/prometheus/common/version" @@ -67,7 +67,7 @@ func queryTmplFuncs() template.FuncMap { // Register registers new GET routes for subpages and retirects from / to /graph. func (q *Query) Register(r *route.Router) { - instrf := prometheus.InstrumentHandlerFunc + instrf := extprom.NewInstrumentedHandlerFunc r.Get("/", instrf("root", q.root)) r.Get("/graph", instrf("graph", q.graph)) diff --git a/pkg/ui/rule.go b/pkg/ui/rule.go index 5d2a442294..091641abc5 100644 --- a/pkg/ui/rule.go +++ b/pkg/ui/rule.go @@ -11,9 +11,9 @@ import ( "time" "github.com/go-kit/kit/log" + "github.com/improbable-eng/thanos/pkg/extprom" thanosrule "github.com/improbable-eng/thanos/pkg/rule" "github.com/improbable-eng/thanos/pkg/store/storepb" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/route" "github.com/prometheus/prometheus/rules" ) @@ -146,7 +146,7 @@ func (ru *Rule) root(w http.ResponseWriter, r *http.Request) { } func (ru *Rule) Register(r *route.Router) { - instrf := prometheus.InstrumentHandlerFunc + instrf := extprom.NewInstrumentedHandlerFunc r.Get("/", instrf("root", ru.root)) r.Get("/alerts", instrf("alerts", ru.alerts)) From 0f3b1983aa0f74c0fe003d8da9649f6d2d3eb70c Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Mon, 8 Jul 2019 17:53:17 +0200 Subject: [PATCH 2/8] Remove package level variables. Rename package --- cmd/thanos/bucket.go | 3 +- cmd/thanos/query.go | 7 +- cmd/thanos/rule.go | 7 +- pkg/extprom/http/instrument_server.go | 107 ++++++++++++++++++++++++++ pkg/extprom/instrument_server.go | 75 ------------------ pkg/query/api/v1.go | 6 +- pkg/query/api/v1_test.go | 3 +- pkg/rule/api/v1.go | 6 +- pkg/ui/bucket.go | 6 +- pkg/ui/query.go | 6 +- pkg/ui/rule.go | 6 +- 11 files changed, 136 insertions(+), 96 deletions(-) create mode 100644 pkg/extprom/http/instrument_server.go delete mode 100644 pkg/extprom/instrument_server.go diff --git a/cmd/thanos/bucket.go b/cmd/thanos/bucket.go index d8a3f53b72..a7d69792e0 100644 --- a/cmd/thanos/bucket.go +++ b/cmd/thanos/bucket.go @@ -14,6 +14,7 @@ import ( "github.com/improbable-eng/thanos/pkg/block" "github.com/improbable-eng/thanos/pkg/block/metadata" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/improbable-eng/thanos/pkg/objstore" "github.com/improbable-eng/thanos/pkg/objstore/client" "github.com/improbable-eng/thanos/pkg/runutil" @@ -310,7 +311,7 @@ func registerBucketWeb(m map[string]setupFunc, root *kingpin.CmdClause, name str router := route.New() bucketUI := ui.NewBucketUI(logger, *label) - bucketUI.Register(router) + bucketUI.Register(router, extpromhttp.NewServerInstrumentor()) if *interval < 5*time.Minute { level.Warn(logger).Log("msg", "Refreshing more often than 5m could lead to large data transfers") diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index e5b4291fb7..f5c5be8282 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -20,6 +20,7 @@ import ( "github.com/improbable-eng/thanos/pkg/discovery/cache" "github.com/improbable-eng/thanos/pkg/discovery/dns" "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/improbable-eng/thanos/pkg/query" v1 "github.com/improbable-eng/thanos/pkg/query/api" "github.com/improbable-eng/thanos/pkg/runutil" @@ -397,11 +398,13 @@ func runQuery( "web.prefix-header": webPrefixHeaderName, } - ui.NewQueryUI(logger, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix)) + ins := extpromhttp.NewServerInstrumentor() + + ui.NewQueryUI(logger, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) api := v1.NewAPI(logger, reg, engine, queryableCreator, enableAutodownsampling, enablePartialResponse) - api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger) + api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger, ins) router.Get("/-/healthy", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) diff --git a/cmd/thanos/rule.go b/cmd/thanos/rule.go index 548ae900f9..c38636580c 100644 --- a/cmd/thanos/rule.go +++ b/cmd/thanos/rule.go @@ -25,6 +25,7 @@ import ( "github.com/improbable-eng/thanos/pkg/discovery/cache" "github.com/improbable-eng/thanos/pkg/discovery/dns" "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/improbable-eng/thanos/pkg/objstore/client" "github.com/improbable-eng/thanos/pkg/promclient" thanosrule "github.com/improbable-eng/thanos/pkg/rule" @@ -527,10 +528,12 @@ func runRule( "web.prefix-header": webPrefixHeaderName, } - ui.NewRuleUI(logger, ruleMgrs, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix)) + ins := extpromhttp.NewServerInstrumentor() + + ui.NewRuleUI(logger, ruleMgrs, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) api := v1.NewAPI(logger, ruleMgrs) - api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger) + api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger, ins) mux := http.NewServeMux() registerMetrics(mux, reg) diff --git a/pkg/extprom/http/instrument_server.go b/pkg/extprom/http/instrument_server.go new file mode 100644 index 0000000000..206c9808af --- /dev/null +++ b/pkg/extprom/http/instrument_server.go @@ -0,0 +1,107 @@ +package http + +import ( + "net/http" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" +) + +// ServerInstrumentor holds necessary metrics to instrument an http.Server +// and provides necessary behaviors +type ServerInstrumentor interface { + // NewInstrumentedHandler wraps the given HTTP handler for instrumentation. + NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc + // NewInstrumentedHandlerFunc wraps the given function for instrumentation. + NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc +} + +type nopServerInstrumentor struct{} + +func (ins nopServerInstrumentor) NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { + return ins.NewInstrumentedHandlerFunc(handlerName, handler.ServeHTTP) +} + +func (ins nopServerInstrumentor) NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc { + return http.HandlerFunc(next) +} + +// NewNopServerInstrumentor provides a ServerInstrumentor which does nothing +func NewNopServerInstrumentor() ServerInstrumentor { + return nopServerInstrumentor{} +} + +type serverInstrumentor struct { + requestDuration *prometheus.HistogramVec + requestSize *prometheus.SummaryVec + requestsTotal *prometheus.CounterVec + responseSize *prometheus.SummaryVec +} + +// NewServerInstrumentor provides default ServerInstrumentor +func NewServerInstrumentor() ServerInstrumentor { + ins := serverInstrumentor{ + requestDuration: prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "http_request_duration_seconds", + Help: "Tracks the latencies for HTTP requests.", + }, + []string{"code", "handler", "method"}, + ), + + requestSize: prometheus.NewSummaryVec( + prometheus.SummaryOpts{ + Name: "http_request_size_bytes", + Help: "Tracks the size of HTTP requests.", + }, + []string{"code", "handler", "method"}, + ), + + requestsTotal: prometheus.NewCounterVec( + prometheus.CounterOpts{ + Name: "http_requests_total", + Help: "Tracks the number of HTTP requests.", + }, []string{"code", "handler", "method"}, + ), + + responseSize: prometheus.NewSummaryVec( + prometheus.SummaryOpts{ + Name: "http_response_size_bytes", + Help: "Tracks the size of HTTP responses.", + }, + []string{"code", "handler", "method"}, + ), + } + prometheus.MustRegister(ins.requestDuration, ins.requestSize, ins.requestsTotal, ins.responseSize) + return &ins +} + +// NewInstrumentedHandler wraps the given HTTP handler for instrumentation. It +// registers four metric collectors (if not already done) and reports HTTP +// metrics to the (newly or already) registered collectors: http_requests_total +// (CounterVec), http_request_duration_seconds (Histogram), +// http_request_size_bytes (Summary), http_response_size_bytes (Summary). Each +// has a constant label named "handler" with the provided handlerName as +// value. http_requests_total is a metric vector partitioned by HTTP method +// (label name "method") and HTTP status code (label name "code"). +func (ins *serverInstrumentor) NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { + return ins.NewInstrumentedHandlerFunc(handlerName, handler.ServeHTTP) +} + +// NewInstrumentedHandlerFunc wraps the given function for instrumentation. It +// otherwise works in the same way as NewInstrumentedHandler. +func (ins *serverInstrumentor) NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc { + return promhttp.InstrumentHandlerDuration( + ins.requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}), + promhttp.InstrumentHandlerRequestSize( + ins.requestSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), + promhttp.InstrumentHandlerCounter( + ins.requestsTotal.MustCurryWith(prometheus.Labels{"handler": handlerName}), + promhttp.InstrumentHandlerResponseSize( + ins.responseSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), + http.HandlerFunc(next), + ), + ), + ), + ) +} diff --git a/pkg/extprom/instrument_server.go b/pkg/extprom/instrument_server.go deleted file mode 100644 index 21219567d0..0000000000 --- a/pkg/extprom/instrument_server.go +++ /dev/null @@ -1,75 +0,0 @@ -package extprom - -import ( - "net/http" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" -) - -var ( - requestDuration = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Name: "http_request_duration_seconds", - Help: "Tracks the latencies for HTTP requests.", - }, - []string{"code", "handler", "method"}, - ) - - requestSize = prometheus.NewSummaryVec( - prometheus.SummaryOpts{ - Name: "http_request_size_bytes", - Help: "Tracks the size of HTTP requests.", - }, - []string{"code", "handler", "method"}, - ) - - requestsTotal = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "http_requests_total", - Help: "Tracks the number of HTTP requests.", - }, []string{"code", "handler", "method"}, - ) - - responseSize = prometheus.NewSummaryVec( - prometheus.SummaryOpts{ - Name: "http_response_size_bytes", - Help: "Tracks the size of HTTP responses.", - }, - []string{"code", "handler", "method"}, - ) -) - -func init() { - prometheus.MustRegister(requestDuration, requestSize, requestsTotal, responseSize) -} - -// NewInstrumentedHandler wraps the given HTTP handler for instrumentation. It -// registers four metric collectors (if not already done) and reports HTTP -// metrics to the (newly or already) registered collectors: http_requests_total -// (CounterVec), http_request_duration_seconds (Histogram), -// http_request_size_bytes (Summary), http_response_size_bytes (Summary). Each -// has a constant label named "handler" with the provided handlerName as -// value. http_requests_total is a metric vector partitioned by HTTP method -// (label name "method") and HTTP status code (label name "code"). -func NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { - return NewInstrumentedHandlerFunc(handlerName, handler.ServeHTTP) -} - -// NewInstrumentedHandlerFunc wraps the given function for instrumentation. It -// otherwise works in the same way as NewInstrumentedHandler. -func NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc { - return promhttp.InstrumentHandlerDuration( - requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}), - promhttp.InstrumentHandlerRequestSize( - requestSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), - promhttp.InstrumentHandlerCounter( - requestsTotal.MustCurryWith(prometheus.Labels{"handler": handlerName}), - promhttp.InstrumentHandlerResponseSize( - responseSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), - http.HandlerFunc(next), - ), - ), - ), - ) -} diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index ba718ff7c4..2d6b858372 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -29,7 +29,7 @@ import ( "github.com/NYTimes/gziphandler" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/improbable-eng/thanos/pkg/query" "github.com/improbable-eng/thanos/pkg/runutil" "github.com/improbable-eng/thanos/pkg/tracing" @@ -151,7 +151,7 @@ func NewAPI( } // Register the API's endpoints in the given router. -func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger) { +func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger, ins extpromhttp.ServerInstrumentor) { instr := func(name string, f ApiFunc) http.HandlerFunc { hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { SetCORS(w) @@ -163,7 +163,7 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log. w.WriteHeader(http.StatusNoContent) } }) - return extprom.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) + return ins.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) } r.Options("/*path", instr("options", api.options)) diff --git a/pkg/query/api/v1_test.go b/pkg/query/api/v1_test.go index c5fbd88742..8504d6c1b8 100644 --- a/pkg/query/api/v1_test.go +++ b/pkg/query/api/v1_test.go @@ -31,6 +31,7 @@ import ( "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/compact" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/improbable-eng/thanos/pkg/query" "github.com/improbable-eng/thanos/pkg/testutil" opentracing "github.com/opentracing/opentracing-go" @@ -774,7 +775,7 @@ func TestParseDuration(t *testing.T) { func TestOptionsMethod(t *testing.T) { r := route.New() api := &API{} - api.Register(r, &opentracing.NoopTracer{}, log.NewNopLogger()) + api.Register(r, &opentracing.NoopTracer{}, log.NewNopLogger(), extpromhttp.NewNopServerInstrumentor()) s := httptest.NewServer(r) defer s.Close() diff --git a/pkg/rule/api/v1.go b/pkg/rule/api/v1.go index e80f5829a3..105e84548b 100644 --- a/pkg/rule/api/v1.go +++ b/pkg/rule/api/v1.go @@ -7,7 +7,7 @@ import ( "github.com/NYTimes/gziphandler" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" qapi "github.com/improbable-eng/thanos/pkg/query/api" thanosrule "github.com/improbable-eng/thanos/pkg/rule" "github.com/improbable-eng/thanos/pkg/store/storepb" @@ -35,7 +35,7 @@ func NewAPI( } } -func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger) { +func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger, ins extpromhttp.ServerInstrumentor) { instr := func(name string, f qapi.ApiFunc) http.HandlerFunc { hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { qapi.SetCORS(w) @@ -47,7 +47,7 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log. w.WriteHeader(http.StatusNoContent) } }) - return extprom.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) + return ins.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) } r.Get("/alerts", instr("alerts", api.alerts)) diff --git a/pkg/ui/bucket.go b/pkg/ui/bucket.go index d352dd2083..d4b8b0cd25 100644 --- a/pkg/ui/bucket.go +++ b/pkg/ui/bucket.go @@ -6,7 +6,7 @@ import ( "time" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/prometheus/common/route" ) @@ -30,8 +30,8 @@ func NewBucketUI(logger log.Logger, label string) *Bucket { } // Register registers http routes for bucket UI. -func (b *Bucket) Register(r *route.Router) { - instrf := extprom.NewInstrumentedHandlerFunc +func (b *Bucket) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { + instrf := ins.NewInstrumentedHandlerFunc r.Get("/", instrf("root", b.root)) r.Get("/static/*filepath", instrf("static", b.serveStaticAsset)) diff --git a/pkg/ui/query.go b/pkg/ui/query.go index 78ec7a1e78..1f0b265de3 100644 --- a/pkg/ui/query.go +++ b/pkg/ui/query.go @@ -11,7 +11,7 @@ import ( "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/component" - "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" "github.com/improbable-eng/thanos/pkg/query" "github.com/prometheus/common/model" "github.com/prometheus/common/route" @@ -66,8 +66,8 @@ func queryTmplFuncs() template.FuncMap { } // Register registers new GET routes for subpages and retirects from / to /graph. -func (q *Query) Register(r *route.Router) { - instrf := extprom.NewInstrumentedHandlerFunc +func (q *Query) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { + instrf := ins.NewInstrumentedHandlerFunc r.Get("/", instrf("root", q.root)) r.Get("/graph", instrf("graph", q.graph)) diff --git a/pkg/ui/rule.go b/pkg/ui/rule.go index 091641abc5..0f4277556f 100644 --- a/pkg/ui/rule.go +++ b/pkg/ui/rule.go @@ -11,7 +11,7 @@ import ( "time" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/extprom" + extpromhttp "github.com/improbable-eng/thanos/pkg/extprom/http" thanosrule "github.com/improbable-eng/thanos/pkg/rule" "github.com/improbable-eng/thanos/pkg/store/storepb" "github.com/prometheus/common/route" @@ -145,8 +145,8 @@ func (ru *Rule) root(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, path.Join(prefix, "/alerts"), http.StatusFound) } -func (ru *Rule) Register(r *route.Router) { - instrf := extprom.NewInstrumentedHandlerFunc +func (ru *Rule) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { + instrf := ins.NewInstrumentedHandlerFunc r.Get("/", instrf("root", ru.root)) r.Get("/alerts", instrf("alerts", ru.alerts)) From f50c42931bc6919a01a47e99c5d3c70a80f3a8d8 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Tue, 9 Jul 2019 11:29:55 +0200 Subject: [PATCH 3/8] Do not use global default registry --- cmd/thanos/bucket.go | 2 +- cmd/thanos/query.go | 2 +- cmd/thanos/rule.go | 2 +- pkg/extprom/http/instrument_server.go | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/thanos/bucket.go b/cmd/thanos/bucket.go index a7d69792e0..f586854ded 100644 --- a/cmd/thanos/bucket.go +++ b/cmd/thanos/bucket.go @@ -311,7 +311,7 @@ func registerBucketWeb(m map[string]setupFunc, root *kingpin.CmdClause, name str router := route.New() bucketUI := ui.NewBucketUI(logger, *label) - bucketUI.Register(router, extpromhttp.NewServerInstrumentor()) + bucketUI.Register(router, extpromhttp.NewServerInstrumentor(reg)) if *interval < 5*time.Minute { level.Warn(logger).Log("msg", "Refreshing more often than 5m could lead to large data transfers") diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index f5c5be8282..d0d98fadbe 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -398,7 +398,7 @@ func runQuery( "web.prefix-header": webPrefixHeaderName, } - ins := extpromhttp.NewServerInstrumentor() + ins := extpromhttp.NewServerInstrumentor(reg) ui.NewQueryUI(logger, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) diff --git a/cmd/thanos/rule.go b/cmd/thanos/rule.go index c38636580c..58f1b55d37 100644 --- a/cmd/thanos/rule.go +++ b/cmd/thanos/rule.go @@ -528,7 +528,7 @@ func runRule( "web.prefix-header": webPrefixHeaderName, } - ins := extpromhttp.NewServerInstrumentor() + ins := extpromhttp.NewServerInstrumentor(reg) ui.NewRuleUI(logger, ruleMgrs, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) diff --git a/pkg/extprom/http/instrument_server.go b/pkg/extprom/http/instrument_server.go index 206c9808af..05556af824 100644 --- a/pkg/extprom/http/instrument_server.go +++ b/pkg/extprom/http/instrument_server.go @@ -39,7 +39,7 @@ type serverInstrumentor struct { } // NewServerInstrumentor provides default ServerInstrumentor -func NewServerInstrumentor() ServerInstrumentor { +func NewServerInstrumentor(reg *prometheus.Registry) ServerInstrumentor { ins := serverInstrumentor{ requestDuration: prometheus.NewHistogramVec( prometheus.HistogramOpts{ @@ -72,7 +72,7 @@ func NewServerInstrumentor() ServerInstrumentor { []string{"code", "handler", "method"}, ), } - prometheus.MustRegister(ins.requestDuration, ins.requestSize, ins.requestsTotal, ins.responseSize) + reg.MustRegister(ins.requestDuration, ins.requestSize, ins.requestsTotal, ins.responseSize) return &ins } From 9501ace35194b1b5c76dac98afb94e940905c6a9 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Tue, 9 Jul 2019 13:45:01 +0200 Subject: [PATCH 4/8] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 923e6cd0e5..5cc987f208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ We use *breaking* word for marking changes that are not backward compatible (rel - [#1284](https://github.com/improbable-eng/thanos/pull/1284) Add support for multiple label-sets in Info gRPC service. This deprecates the single `Labels` slice of the `InfoResponse`, in a future release backward compatible handling for the single set of Labels will be removed. Upgrading to v0.6.0 or higher is advised. +- [#1314](https://github.com/improbable-eng/thanos/pull/1314) Updates `prometheus/client_golang`. Remove usages of [deprecated methods](https://github.com/prometheus/client_golang/blob/505eaef017263e299324067d40ca2c48f6a2cf50/prometheus/http.go#L122) by introducing a wrapper package which mimics the same behaviour while using new APIs and fixes stated issues. As a result, removes `http_request_duration_microseconds` (Summary) and adds `http_request_duration_seconds` (Histogram). + ## [v0.5.0](https://github.com/improbable-eng/thanos/releases/tag/v0.5.0) - 2019.06.05 TL;DR: Store LRU cache is no longer leaking, Upgraded Thanos UI to Prometheus 2.9, Fixed auto-downsampling, Moved to Go 1.12.5 and more. From 4a655845f35a8e701e7c63611e1450e525a3d10a Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Tue, 9 Jul 2019 16:04:21 +0200 Subject: [PATCH 5/8] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc987f208..585c54e649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel - [#1284](https://github.com/improbable-eng/thanos/pull/1284) Add support for multiple label-sets in Info gRPC service. This deprecates the single `Labels` slice of the `InfoResponse`, in a future release backward compatible handling for the single set of Labels will be removed. Upgrading to v0.6.0 or higher is advised. -- [#1314](https://github.com/improbable-eng/thanos/pull/1314) Updates `prometheus/client_golang`. Remove usages of [deprecated methods](https://github.com/prometheus/client_golang/blob/505eaef017263e299324067d40ca2c48f6a2cf50/prometheus/http.go#L122) by introducing a wrapper package which mimics the same behaviour while using new APIs and fixes stated issues. As a result, removes `http_request_duration_microseconds` (Summary) and adds `http_request_duration_seconds` (Histogram). +- [#1314](https://github.com/improbable-eng/thanos/pull/1314) Removes `http_request_duration_microseconds` (Summary) and adds `http_request_duration_seconds` (Histogram) from http server instrumentation used in Thanos APIs and UIs. ## [v0.5.0](https://github.com/improbable-eng/thanos/releases/tag/v0.5.0) - 2019.06.05 From 1444f0d4de45d859db70684c9479dececb77e71a Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Tue, 9 Jul 2019 16:20:20 +0200 Subject: [PATCH 6/8] Simplify API for handler --- pkg/extprom/http/instrument_server.go | 18 ++++-------------- pkg/ui/bucket.go | 4 +++- pkg/ui/query.go | 4 +++- pkg/ui/rule.go | 4 +++- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pkg/extprom/http/instrument_server.go b/pkg/extprom/http/instrument_server.go index 05556af824..f527f9879b 100644 --- a/pkg/extprom/http/instrument_server.go +++ b/pkg/extprom/http/instrument_server.go @@ -12,18 +12,14 @@ import ( type ServerInstrumentor interface { // NewInstrumentedHandler wraps the given HTTP handler for instrumentation. NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc - // NewInstrumentedHandlerFunc wraps the given function for instrumentation. - NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc } type nopServerInstrumentor struct{} func (ins nopServerInstrumentor) NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { - return ins.NewInstrumentedHandlerFunc(handlerName, handler.ServeHTTP) -} - -func (ins nopServerInstrumentor) NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc { - return http.HandlerFunc(next) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler.ServeHTTP(w, r) + }) } // NewNopServerInstrumentor provides a ServerInstrumentor which does nothing @@ -85,12 +81,6 @@ func NewServerInstrumentor(reg *prometheus.Registry) ServerInstrumentor { // value. http_requests_total is a metric vector partitioned by HTTP method // (label name "method") and HTTP status code (label name "code"). func (ins *serverInstrumentor) NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { - return ins.NewInstrumentedHandlerFunc(handlerName, handler.ServeHTTP) -} - -// NewInstrumentedHandlerFunc wraps the given function for instrumentation. It -// otherwise works in the same way as NewInstrumentedHandler. -func (ins *serverInstrumentor) NewInstrumentedHandlerFunc(handlerName string, next func(http.ResponseWriter, *http.Request)) http.HandlerFunc { return promhttp.InstrumentHandlerDuration( ins.requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}), promhttp.InstrumentHandlerRequestSize( @@ -99,7 +89,7 @@ func (ins *serverInstrumentor) NewInstrumentedHandlerFunc(handlerName string, ne ins.requestsTotal.MustCurryWith(prometheus.Labels{"handler": handlerName}), promhttp.InstrumentHandlerResponseSize( ins.responseSize.MustCurryWith(prometheus.Labels{"handler": handlerName}), - http.HandlerFunc(next), + handler, ), ), ), diff --git a/pkg/ui/bucket.go b/pkg/ui/bucket.go index d4b8b0cd25..baef93837f 100644 --- a/pkg/ui/bucket.go +++ b/pkg/ui/bucket.go @@ -31,7 +31,9 @@ func NewBucketUI(logger log.Logger, label string) *Bucket { // Register registers http routes for bucket UI. func (b *Bucket) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { - instrf := ins.NewInstrumentedHandlerFunc + instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { + return ins.NewInstrumentedHandler(name, http.HandlerFunc(next)) + } r.Get("/", instrf("root", b.root)) r.Get("/static/*filepath", instrf("static", b.serveStaticAsset)) diff --git a/pkg/ui/query.go b/pkg/ui/query.go index 1f0b265de3..3e59c75ef3 100644 --- a/pkg/ui/query.go +++ b/pkg/ui/query.go @@ -67,7 +67,9 @@ func queryTmplFuncs() template.FuncMap { // Register registers new GET routes for subpages and retirects from / to /graph. func (q *Query) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { - instrf := ins.NewInstrumentedHandlerFunc + instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { + return ins.NewInstrumentedHandler(name, http.HandlerFunc(next)) + } r.Get("/", instrf("root", q.root)) r.Get("/graph", instrf("graph", q.graph)) diff --git a/pkg/ui/rule.go b/pkg/ui/rule.go index 0f4277556f..299d0918e4 100644 --- a/pkg/ui/rule.go +++ b/pkg/ui/rule.go @@ -146,7 +146,9 @@ func (ru *Rule) root(w http.ResponseWriter, r *http.Request) { } func (ru *Rule) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { - instrf := ins.NewInstrumentedHandlerFunc + instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { + return ins.NewInstrumentedHandler(name, http.HandlerFunc(next)) + } r.Get("/", instrf("root", ru.root)) r.Get("/alerts", instrf("alerts", ru.alerts)) From f4356d0d4ca480fb57f5957117cc4f760f2e6114 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Tue, 9 Jul 2019 16:35:21 +0200 Subject: [PATCH 7/8] Add missing comment periods --- pkg/extprom/http/instrument_server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/extprom/http/instrument_server.go b/pkg/extprom/http/instrument_server.go index f527f9879b..aabd74900f 100644 --- a/pkg/extprom/http/instrument_server.go +++ b/pkg/extprom/http/instrument_server.go @@ -8,7 +8,7 @@ import ( ) // ServerInstrumentor holds necessary metrics to instrument an http.Server -// and provides necessary behaviors +// and provides necessary behaviors. type ServerInstrumentor interface { // NewInstrumentedHandler wraps the given HTTP handler for instrumentation. NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc @@ -22,7 +22,7 @@ func (ins nopServerInstrumentor) NewInstrumentedHandler(handlerName string, hand }) } -// NewNopServerInstrumentor provides a ServerInstrumentor which does nothing +// NewNopServerInstrumentor provides a ServerInstrumentor which does nothing. func NewNopServerInstrumentor() ServerInstrumentor { return nopServerInstrumentor{} } @@ -34,7 +34,7 @@ type serverInstrumentor struct { responseSize *prometheus.SummaryVec } -// NewServerInstrumentor provides default ServerInstrumentor +// NewServerInstrumentor provides default ServerInstrumentor. func NewServerInstrumentor(reg *prometheus.Registry) ServerInstrumentor { ins := serverInstrumentor{ requestDuration: prometheus.NewHistogramVec( From a02335e7d4f0bb204ace94ef89697c1f22c6ff5c Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Wed, 10 Jul 2019 10:35:15 +0200 Subject: [PATCH 8/8] Rename instrumentation handler package --- cmd/thanos/bucket.go | 2 +- cmd/thanos/query.go | 2 +- cmd/thanos/rule.go | 2 +- pkg/extprom/http/instrument_server.go | 30 +++++++++++++-------------- pkg/query/api/v1.go | 4 ++-- pkg/query/api/v1_test.go | 2 +- pkg/rule/api/v1.go | 4 ++-- pkg/ui/bucket.go | 4 ++-- pkg/ui/query.go | 4 ++-- pkg/ui/rule.go | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cmd/thanos/bucket.go b/cmd/thanos/bucket.go index f586854ded..ce8b7b966c 100644 --- a/cmd/thanos/bucket.go +++ b/cmd/thanos/bucket.go @@ -311,7 +311,7 @@ func registerBucketWeb(m map[string]setupFunc, root *kingpin.CmdClause, name str router := route.New() bucketUI := ui.NewBucketUI(logger, *label) - bucketUI.Register(router, extpromhttp.NewServerInstrumentor(reg)) + bucketUI.Register(router, extpromhttp.NewInstrumentationMiddleware(reg)) if *interval < 5*time.Minute { level.Warn(logger).Log("msg", "Refreshing more often than 5m could lead to large data transfers") diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index d0d98fadbe..612d47e10b 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -398,7 +398,7 @@ func runQuery( "web.prefix-header": webPrefixHeaderName, } - ins := extpromhttp.NewServerInstrumentor(reg) + ins := extpromhttp.NewInstrumentationMiddleware(reg) ui.NewQueryUI(logger, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) diff --git a/cmd/thanos/rule.go b/cmd/thanos/rule.go index 58f1b55d37..8c8f10fc49 100644 --- a/cmd/thanos/rule.go +++ b/cmd/thanos/rule.go @@ -528,7 +528,7 @@ func runRule( "web.prefix-header": webPrefixHeaderName, } - ins := extpromhttp.NewServerInstrumentor(reg) + ins := extpromhttp.NewInstrumentationMiddleware(reg) ui.NewRuleUI(logger, ruleMgrs, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) diff --git a/pkg/extprom/http/instrument_server.go b/pkg/extprom/http/instrument_server.go index aabd74900f..87ffbb8e19 100644 --- a/pkg/extprom/http/instrument_server.go +++ b/pkg/extprom/http/instrument_server.go @@ -7,36 +7,36 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -// ServerInstrumentor holds necessary metrics to instrument an http.Server +// InstrumentationMiddleware holds necessary metrics to instrument an http.Server // and provides necessary behaviors. -type ServerInstrumentor interface { - // NewInstrumentedHandler wraps the given HTTP handler for instrumentation. - NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc +type InstrumentationMiddleware interface { + // NewHandler wraps the given HTTP handler for instrumentation. + NewHandler(handlerName string, handler http.Handler) http.HandlerFunc } -type nopServerInstrumentor struct{} +type nopInstrumentationMiddleware struct{} -func (ins nopServerInstrumentor) NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { +func (ins nopInstrumentationMiddleware) NewHandler(handlerName string, handler http.Handler) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handler.ServeHTTP(w, r) }) } -// NewNopServerInstrumentor provides a ServerInstrumentor which does nothing. -func NewNopServerInstrumentor() ServerInstrumentor { - return nopServerInstrumentor{} +// NewNopInstrumentationMiddleware provides a InstrumentationMiddleware which does nothing. +func NewNopInstrumentationMiddleware() InstrumentationMiddleware { + return nopInstrumentationMiddleware{} } -type serverInstrumentor struct { +type defaultInstrumentationMiddleware struct { requestDuration *prometheus.HistogramVec requestSize *prometheus.SummaryVec requestsTotal *prometheus.CounterVec responseSize *prometheus.SummaryVec } -// NewServerInstrumentor provides default ServerInstrumentor. -func NewServerInstrumentor(reg *prometheus.Registry) ServerInstrumentor { - ins := serverInstrumentor{ +// NewInstrumentationMiddleware provides default InstrumentationMiddleware. +func NewInstrumentationMiddleware(reg *prometheus.Registry) InstrumentationMiddleware { + ins := defaultInstrumentationMiddleware{ requestDuration: prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "http_request_duration_seconds", @@ -72,7 +72,7 @@ func NewServerInstrumentor(reg *prometheus.Registry) ServerInstrumentor { return &ins } -// NewInstrumentedHandler wraps the given HTTP handler for instrumentation. It +// NewHandler wraps the given HTTP handler for instrumentation. It // registers four metric collectors (if not already done) and reports HTTP // metrics to the (newly or already) registered collectors: http_requests_total // (CounterVec), http_request_duration_seconds (Histogram), @@ -80,7 +80,7 @@ func NewServerInstrumentor(reg *prometheus.Registry) ServerInstrumentor { // has a constant label named "handler" with the provided handlerName as // value. http_requests_total is a metric vector partitioned by HTTP method // (label name "method") and HTTP status code (label name "code"). -func (ins *serverInstrumentor) NewInstrumentedHandler(handlerName string, handler http.Handler) http.HandlerFunc { +func (ins *defaultInstrumentationMiddleware) NewHandler(handlerName string, handler http.Handler) http.HandlerFunc { return promhttp.InstrumentHandlerDuration( ins.requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}), promhttp.InstrumentHandlerRequestSize( diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index 2d6b858372..ecf3a86b56 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -151,7 +151,7 @@ func NewAPI( } // Register the API's endpoints in the given router. -func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger, ins extpromhttp.ServerInstrumentor) { +func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger, ins extpromhttp.InstrumentationMiddleware) { instr := func(name string, f ApiFunc) http.HandlerFunc { hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { SetCORS(w) @@ -163,7 +163,7 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log. w.WriteHeader(http.StatusNoContent) } }) - return ins.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) + return ins.NewHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) } r.Options("/*path", instr("options", api.options)) diff --git a/pkg/query/api/v1_test.go b/pkg/query/api/v1_test.go index 8504d6c1b8..dc550c33da 100644 --- a/pkg/query/api/v1_test.go +++ b/pkg/query/api/v1_test.go @@ -775,7 +775,7 @@ func TestParseDuration(t *testing.T) { func TestOptionsMethod(t *testing.T) { r := route.New() api := &API{} - api.Register(r, &opentracing.NoopTracer{}, log.NewNopLogger(), extpromhttp.NewNopServerInstrumentor()) + api.Register(r, &opentracing.NoopTracer{}, log.NewNopLogger(), extpromhttp.NewNopInstrumentationMiddleware()) s := httptest.NewServer(r) defer s.Close() diff --git a/pkg/rule/api/v1.go b/pkg/rule/api/v1.go index 105e84548b..558c38305c 100644 --- a/pkg/rule/api/v1.go +++ b/pkg/rule/api/v1.go @@ -35,7 +35,7 @@ func NewAPI( } } -func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger, ins extpromhttp.ServerInstrumentor) { +func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.Logger, ins extpromhttp.InstrumentationMiddleware) { instr := func(name string, f qapi.ApiFunc) http.HandlerFunc { hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { qapi.SetCORS(w) @@ -47,7 +47,7 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log. w.WriteHeader(http.StatusNoContent) } }) - return ins.NewInstrumentedHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) + return ins.NewHandler(name, tracing.HTTPMiddleware(tracer, name, logger, gziphandler.GzipHandler(hf))) } r.Get("/alerts", instr("alerts", api.alerts)) diff --git a/pkg/ui/bucket.go b/pkg/ui/bucket.go index baef93837f..28159cdd25 100644 --- a/pkg/ui/bucket.go +++ b/pkg/ui/bucket.go @@ -30,9 +30,9 @@ func NewBucketUI(logger log.Logger, label string) *Bucket { } // Register registers http routes for bucket UI. -func (b *Bucket) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { +func (b *Bucket) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) { instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { - return ins.NewInstrumentedHandler(name, http.HandlerFunc(next)) + return ins.NewHandler(name, http.HandlerFunc(next)) } r.Get("/", instrf("root", b.root)) diff --git a/pkg/ui/query.go b/pkg/ui/query.go index 3e59c75ef3..13c731b5ed 100644 --- a/pkg/ui/query.go +++ b/pkg/ui/query.go @@ -66,9 +66,9 @@ func queryTmplFuncs() template.FuncMap { } // Register registers new GET routes for subpages and retirects from / to /graph. -func (q *Query) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { +func (q *Query) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) { instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { - return ins.NewInstrumentedHandler(name, http.HandlerFunc(next)) + return ins.NewHandler(name, http.HandlerFunc(next)) } r.Get("/", instrf("root", q.root)) diff --git a/pkg/ui/rule.go b/pkg/ui/rule.go index 299d0918e4..5e1735287e 100644 --- a/pkg/ui/rule.go +++ b/pkg/ui/rule.go @@ -145,9 +145,9 @@ func (ru *Rule) root(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, path.Join(prefix, "/alerts"), http.StatusFound) } -func (ru *Rule) Register(r *route.Router, ins extpromhttp.ServerInstrumentor) { +func (ru *Rule) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) { instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { - return ins.NewInstrumentedHandler(name, http.HandlerFunc(next)) + return ins.NewHandler(name, http.HandlerFunc(next)) } r.Get("/", instrf("root", ru.root))