OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
11 "net/http" | 11 "net/http" |
12 "os" | 12 "os" |
13 "os/signal" | 13 "os/signal" |
14 "runtime" | 14 "runtime" |
15 "sync" | 15 "sync" |
16 "time" | 16 "time" |
17 | 17 |
18 "github.com/luci/luci-go/common/auth" | 18 "github.com/luci/luci-go/common/auth" |
19 "github.com/luci/luci-go/common/clock" | 19 "github.com/luci/luci-go/common/clock" |
20 luciErrors "github.com/luci/luci-go/common/errors" | 20 luciErrors "github.com/luci/luci-go/common/errors" |
21 log "github.com/luci/luci-go/common/logging" | 21 log "github.com/luci/luci-go/common/logging" |
22 "github.com/luci/luci-go/common/logging/gologger" | 22 "github.com/luci/luci-go/common/logging/gologger" |
23 "github.com/luci/luci-go/common/parallel" | 23 "github.com/luci/luci-go/common/parallel" |
24 "github.com/luci/luci-go/common/tsmon" | 24 "github.com/luci/luci-go/common/tsmon" |
25 "github.com/luci/luci-go/common/tsmon/distribution" | 25 "github.com/luci/luci-go/common/tsmon/distribution" |
26 "github.com/luci/luci-go/common/tsmon/field" | 26 "github.com/luci/luci-go/common/tsmon/field" |
27 "github.com/luci/luci-go/common/tsmon/metric" | 27 "github.com/luci/luci-go/common/tsmon/metric" |
| 28 "github.com/luci/luci-go/common/tsmon/types" |
28 "golang.org/x/net/context" | 29 "golang.org/x/net/context" |
29 "google.golang.org/cloud/pubsub" | 30 "google.golang.org/cloud/pubsub" |
30 ) | 31 ) |
31 | 32 |
32 const ( | 33 const ( |
33 // noMessageDelay is the amount of time to sleep after receiving no mess
ages. | 34 // noMessageDelay is the amount of time to sleep after receiving no mess
ages. |
34 noMessageDelay = 1 * time.Second | 35 noMessageDelay = 1 * time.Second |
35 | 36 |
36 // maxMessageSize is the maximum size of a message that the proxy will | 37 // maxMessageSize is the maximum size of a message that the proxy will |
37 // forward. Messages larger than this will be discarded by policy. | 38 // forward. Messages larger than this will be discarded by policy. |
38 maxMessageSize = 1024 * 512 | 39 maxMessageSize = 1024 * 512 |
39 ) | 40 ) |
40 | 41 |
41 var ( | 42 var ( |
42 sentCount = metric.NewCounter("mon_proxy/endpoint/sent", | 43 sentCount = metric.NewCounter("mon_proxy/endpoint/sent", |
43 "Count of messages proxied to the endpoint", | 44 "Count of messages proxied to the endpoint", |
| 45 types.MetricMetadata{}, |
44 field.String("result")) | 46 field.String("result")) |
45 sentDuration = metric.NewCumulativeDistribution("mon_proxy/endpoint/dura
tion", | 47 sentDuration = metric.NewCumulativeDistribution("mon_proxy/endpoint/dura
tion", |
46 "Time taken to send messages to the endpoint, in milliseconds", | 48 "Time taken to send messages to the endpoint, in milliseconds", |
| 49 types.MetricMetadata{Units: types.Milliseconds}, |
47 distribution.DefaultBucketer) | 50 distribution.DefaultBucketer) |
48 ) | 51 ) |
49 | 52 |
50 func init() { | 53 func init() { |
51 // Increase idle connections per host, since we connect to basically two | 54 // Increase idle connections per host, since we connect to basically two |
52 // hosts. | 55 // hosts. |
53 if t, ok := http.DefaultTransport.(*http.Transport); ok { | 56 if t, ok := http.DefaultTransport.(*http.Transport); ok { |
54 t.MaxIdleConnsPerHost = 10000 | 57 t.MaxIdleConnsPerHost = 10000 |
55 } | 58 } |
56 } | 59 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 log.Errorf(log.SetError(ctx, err), "Error during application exe
cution.") | 385 log.Errorf(log.SetError(ctx, err), "Error during application exe
cution.") |
383 return 1 | 386 return 1 |
384 } | 387 } |
385 | 388 |
386 return 0 | 389 return 0 |
387 } | 390 } |
388 | 391 |
389 func main() { | 392 func main() { |
390 os.Exit(mainImpl(os.Args[1:])) | 393 os.Exit(mainImpl(os.Args[1:])) |
391 } | 394 } |
OLD | NEW |