]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/go.opencensus.io/plugin/ochttp/stats.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / go.opencensus.io / plugin / ochttp / stats.go
1 // Copyright 2018, OpenCensus Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package ochttp
16
17 import (
18 "go.opencensus.io/stats"
19 "go.opencensus.io/stats/view"
20 "go.opencensus.io/tag"
21 )
22
23 // The following client HTTP measures are supported for use in custom views.
24 var (
25 // Deprecated: Use a Count aggregation over one of the other client measures to achieve the same effect.
26 ClientRequestCount = stats.Int64("opencensus.io/http/client/request_count", "Number of HTTP requests started", stats.UnitDimensionless)
27 // Deprecated: Use ClientSentBytes.
28 ClientRequestBytes = stats.Int64("opencensus.io/http/client/request_bytes", "HTTP request body size if set as ContentLength (uncompressed)", stats.UnitBytes)
29 // Deprecated: Use ClientReceivedBytes.
30 ClientResponseBytes = stats.Int64("opencensus.io/http/client/response_bytes", "HTTP response body size (uncompressed)", stats.UnitBytes)
31 // Deprecated: Use ClientRoundtripLatency.
32 ClientLatency = stats.Float64("opencensus.io/http/client/latency", "End-to-end latency", stats.UnitMilliseconds)
33 )
34
35 // Client measures supported for use in custom views.
36 var (
37 ClientSentBytes = stats.Int64(
38 "opencensus.io/http/client/sent_bytes",
39 "Total bytes sent in request body (not including headers)",
40 stats.UnitBytes,
41 )
42 ClientReceivedBytes = stats.Int64(
43 "opencensus.io/http/client/received_bytes",
44 "Total bytes received in response bodies (not including headers but including error responses with bodies)",
45 stats.UnitBytes,
46 )
47 ClientRoundtripLatency = stats.Float64(
48 "opencensus.io/http/client/roundtrip_latency",
49 "Time between first byte of request headers sent to last byte of response received, or terminal error",
50 stats.UnitMilliseconds,
51 )
52 )
53
54 // The following server HTTP measures are supported for use in custom views:
55 var (
56 ServerRequestCount = stats.Int64("opencensus.io/http/server/request_count", "Number of HTTP requests started", stats.UnitDimensionless)
57 ServerRequestBytes = stats.Int64("opencensus.io/http/server/request_bytes", "HTTP request body size if set as ContentLength (uncompressed)", stats.UnitBytes)
58 ServerResponseBytes = stats.Int64("opencensus.io/http/server/response_bytes", "HTTP response body size (uncompressed)", stats.UnitBytes)
59 ServerLatency = stats.Float64("opencensus.io/http/server/latency", "End-to-end latency", stats.UnitMilliseconds)
60 )
61
62 // The following tags are applied to stats recorded by this package. Host, Path
63 // and Method are applied to all measures. StatusCode is not applied to
64 // ClientRequestCount or ServerRequestCount, since it is recorded before the status is known.
65 var (
66 // Host is the value of the HTTP Host header.
67 //
68 // The value of this tag can be controlled by the HTTP client, so you need
69 // to watch out for potentially generating high-cardinality labels in your
70 // metrics backend if you use this tag in views.
71 Host, _ = tag.NewKey("http.host")
72
73 // StatusCode is the numeric HTTP response status code,
74 // or "error" if a transport error occurred and no status code was read.
75 StatusCode, _ = tag.NewKey("http.status")
76
77 // Path is the URL path (not including query string) in the request.
78 //
79 // The value of this tag can be controlled by the HTTP client, so you need
80 // to watch out for potentially generating high-cardinality labels in your
81 // metrics backend if you use this tag in views.
82 Path, _ = tag.NewKey("http.path")
83
84 // Method is the HTTP method of the request, capitalized (GET, POST, etc.).
85 Method, _ = tag.NewKey("http.method")
86
87 // KeyServerRoute is a low cardinality string representing the logical
88 // handler of the request. This is usually the pattern registered on the a
89 // ServeMux (or similar string).
90 KeyServerRoute, _ = tag.NewKey("http_server_route")
91 )
92
93 // Client tag keys.
94 var (
95 // KeyClientMethod is the HTTP method, capitalized (i.e. GET, POST, PUT, DELETE, etc.).
96 KeyClientMethod, _ = tag.NewKey("http_client_method")
97 // KeyClientPath is the URL path (not including query string).
98 KeyClientPath, _ = tag.NewKey("http_client_path")
99 // KeyClientStatus is the HTTP status code as an integer (e.g. 200, 404, 500.), or "error" if no response status line was received.
100 KeyClientStatus, _ = tag.NewKey("http_client_status")
101 // KeyClientHost is the value of the request Host header.
102 KeyClientHost, _ = tag.NewKey("http_client_host")
103 )
104
105 // Default distributions used by views in this package.
106 var (
107 DefaultSizeDistribution = view.Distribution(0, 1024, 2048, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456, 1073741824, 4294967296)
108 DefaultLatencyDistribution = view.Distribution(0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
109 )
110
111 // Package ochttp provides some convenience views.
112 // You still need to register these views for data to actually be collected.
113 var (
114 ClientSentBytesDistribution = &view.View{
115 Name: "opencensus.io/http/client/sent_bytes",
116 Measure: ClientSentBytes,
117 Aggregation: DefaultSizeDistribution,
118 Description: "Total bytes sent in request body (not including headers), by HTTP method and response status",
119 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
120 }
121
122 ClientReceivedBytesDistribution = &view.View{
123 Name: "opencensus.io/http/client/received_bytes",
124 Measure: ClientReceivedBytes,
125 Aggregation: DefaultSizeDistribution,
126 Description: "Total bytes received in response bodies (not including headers but including error responses with bodies), by HTTP method and response status",
127 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
128 }
129
130 ClientRoundtripLatencyDistribution = &view.View{
131 Name: "opencensus.io/http/client/roundtrip_latency",
132 Measure: ClientRoundtripLatency,
133 Aggregation: DefaultLatencyDistribution,
134 Description: "End-to-end latency, by HTTP method and response status",
135 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
136 }
137
138 ClientCompletedCount = &view.View{
139 Name: "opencensus.io/http/client/completed_count",
140 Measure: ClientRoundtripLatency,
141 Aggregation: view.Count(),
142 Description: "Count of completed requests, by HTTP method and response status",
143 TagKeys: []tag.Key{KeyClientMethod, KeyClientStatus},
144 }
145 )
146
147 var (
148 // Deprecated: No direct replacement, but see ClientCompletedCount.
149 ClientRequestCountView = &view.View{
150 Name: "opencensus.io/http/client/request_count",
151 Description: "Count of HTTP requests started",
152 Measure: ClientRequestCount,
153 Aggregation: view.Count(),
154 }
155
156 // Deprecated: Use ClientSentBytesDistribution.
157 ClientRequestBytesView = &view.View{
158 Name: "opencensus.io/http/client/request_bytes",
159 Description: "Size distribution of HTTP request body",
160 Measure: ClientSentBytes,
161 Aggregation: DefaultSizeDistribution,
162 }
163
164 // Deprecated: Use ClientReceivedBytesDistribution.
165 ClientResponseBytesView = &view.View{
166 Name: "opencensus.io/http/client/response_bytes",
167 Description: "Size distribution of HTTP response body",
168 Measure: ClientReceivedBytes,
169 Aggregation: DefaultSizeDistribution,
170 }
171
172 // Deprecated: Use ClientRoundtripLatencyDistribution.
173 ClientLatencyView = &view.View{
174 Name: "opencensus.io/http/client/latency",
175 Description: "Latency distribution of HTTP requests",
176 Measure: ClientRoundtripLatency,
177 Aggregation: DefaultLatencyDistribution,
178 }
179
180 // Deprecated: Use ClientCompletedCount.
181 ClientRequestCountByMethod = &view.View{
182 Name: "opencensus.io/http/client/request_count_by_method",
183 Description: "Client request count by HTTP method",
184 TagKeys: []tag.Key{Method},
185 Measure: ClientSentBytes,
186 Aggregation: view.Count(),
187 }
188
189 // Deprecated: Use ClientCompletedCount.
190 ClientResponseCountByStatusCode = &view.View{
191 Name: "opencensus.io/http/client/response_count_by_status_code",
192 Description: "Client response count by status code",
193 TagKeys: []tag.Key{StatusCode},
194 Measure: ClientRoundtripLatency,
195 Aggregation: view.Count(),
196 }
197 )
198
199 var (
200 ServerRequestCountView = &view.View{
201 Name: "opencensus.io/http/server/request_count",
202 Description: "Count of HTTP requests started",
203 Measure: ServerRequestCount,
204 Aggregation: view.Count(),
205 }
206
207 ServerRequestBytesView = &view.View{
208 Name: "opencensus.io/http/server/request_bytes",
209 Description: "Size distribution of HTTP request body",
210 Measure: ServerRequestBytes,
211 Aggregation: DefaultSizeDistribution,
212 }
213
214 ServerResponseBytesView = &view.View{
215 Name: "opencensus.io/http/server/response_bytes",
216 Description: "Size distribution of HTTP response body",
217 Measure: ServerResponseBytes,
218 Aggregation: DefaultSizeDistribution,
219 }
220
221 ServerLatencyView = &view.View{
222 Name: "opencensus.io/http/server/latency",
223 Description: "Latency distribution of HTTP requests",
224 Measure: ServerLatency,
225 Aggregation: DefaultLatencyDistribution,
226 }
227
228 ServerRequestCountByMethod = &view.View{
229 Name: "opencensus.io/http/server/request_count_by_method",
230 Description: "Server request count by HTTP method",
231 TagKeys: []tag.Key{Method},
232 Measure: ServerRequestCount,
233 Aggregation: view.Count(),
234 }
235
236 ServerResponseCountByStatusCode = &view.View{
237 Name: "opencensus.io/http/server/response_count_by_status_code",
238 Description: "Server response count by status code",
239 TagKeys: []tag.Key{StatusCode},
240 Measure: ServerLatency,
241 Aggregation: view.Count(),
242 }
243 )
244
245 // DefaultClientViews are the default client views provided by this package.
246 // Deprecated: No replacement. Register the views you would like individually.
247 var DefaultClientViews = []*view.View{
248 ClientRequestCountView,
249 ClientRequestBytesView,
250 ClientResponseBytesView,
251 ClientLatencyView,
252 ClientRequestCountByMethod,
253 ClientResponseCountByStatusCode,
254 }
255
256 // DefaultServerViews are the default server views provided by this package.
257 // Deprecated: No replacement. Register the views you would like individually.
258 var DefaultServerViews = []*view.View{
259 ServerRequestCountView,
260 ServerRequestBytesView,
261 ServerResponseBytesView,
262 ServerLatencyView,
263 ServerRequestCountByMethod,
264 ServerResponseCountByStatusCode,
265 }