| 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 count | 5 package count |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "time" | 8 "time" |
| 9 | 9 |
| 10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
| 11 | 11 |
| 12 » "github.com/luci/gae" | 12 » "github.com/luci/gae/service/info" |
| 13 ) | 13 ) |
| 14 | 14 |
| 15 // GICounter is the counter object for the GlobalInfo service. | 15 // InfoCounter is the counter object for the GlobalInfo service. |
| 16 type GICounter struct { | 16 type InfoCounter struct { |
| 17 AppID Entry | 17 AppID Entry |
| 18 Datacenter Entry | 18 Datacenter Entry |
| 19 DefaultVersionHostname Entry | 19 DefaultVersionHostname Entry |
| 20 InstanceID Entry | 20 InstanceID Entry |
| 21 IsDevAppServer Entry | 21 IsDevAppServer Entry |
| 22 IsOverQuota Entry | 22 IsOverQuota Entry |
| 23 IsTimeoutError Entry | 23 IsTimeoutError Entry |
| 24 ModuleHostname Entry | 24 ModuleHostname Entry |
| 25 ModuleName Entry | 25 ModuleName Entry |
| 26 RequestID Entry | 26 RequestID Entry |
| 27 ServerSoftware Entry | 27 ServerSoftware Entry |
| 28 ServiceAccount Entry | 28 ServiceAccount Entry |
| 29 VersionID Entry | 29 VersionID Entry |
| 30 Namespace Entry | 30 Namespace Entry |
| 31 AccessToken Entry | 31 AccessToken Entry |
| 32 PublicCertificates Entry | 32 PublicCertificates Entry |
| 33 SignBytes Entry | 33 SignBytes Entry |
| 34 } | 34 } |
| 35 | 35 |
| 36 type giCounter struct { | 36 type infoCounter struct { |
| 37 » c *GICounter | 37 » c *InfoCounter |
| 38 | 38 |
| 39 » gi gae.GlobalInfo | 39 » gi info.Interface |
| 40 } | 40 } |
| 41 | 41 |
| 42 var _ gae.GlobalInfo = (*giCounter)(nil) | 42 var _ info.Interface = (*infoCounter)(nil) |
| 43 | 43 |
| 44 func (g *giCounter) AppID() string { | 44 func (g *infoCounter) AppID() string { |
| 45 g.c.AppID.up() | 45 g.c.AppID.up() |
| 46 return g.gi.AppID() | 46 return g.gi.AppID() |
| 47 } | 47 } |
| 48 | 48 |
| 49 func (g *giCounter) Datacenter() string { | 49 func (g *infoCounter) Datacenter() string { |
| 50 g.c.Datacenter.up() | 50 g.c.Datacenter.up() |
| 51 return g.gi.Datacenter() | 51 return g.gi.Datacenter() |
| 52 } | 52 } |
| 53 | 53 |
| 54 func (g *giCounter) DefaultVersionHostname() string { | 54 func (g *infoCounter) DefaultVersionHostname() string { |
| 55 g.c.DefaultVersionHostname.up() | 55 g.c.DefaultVersionHostname.up() |
| 56 return g.gi.DefaultVersionHostname() | 56 return g.gi.DefaultVersionHostname() |
| 57 } | 57 } |
| 58 | 58 |
| 59 func (g *giCounter) InstanceID() string { | 59 func (g *infoCounter) InstanceID() string { |
| 60 g.c.InstanceID.up() | 60 g.c.InstanceID.up() |
| 61 return g.gi.InstanceID() | 61 return g.gi.InstanceID() |
| 62 } | 62 } |
| 63 | 63 |
| 64 func (g *giCounter) IsDevAppServer() bool { | 64 func (g *infoCounter) IsDevAppServer() bool { |
| 65 g.c.IsDevAppServer.up() | 65 g.c.IsDevAppServer.up() |
| 66 return g.gi.IsDevAppServer() | 66 return g.gi.IsDevAppServer() |
| 67 } | 67 } |
| 68 | 68 |
| 69 func (g *giCounter) IsOverQuota(err error) bool { | 69 func (g *infoCounter) IsOverQuota(err error) bool { |
| 70 g.c.IsOverQuota.up() | 70 g.c.IsOverQuota.up() |
| 71 return g.gi.IsOverQuota(err) | 71 return g.gi.IsOverQuota(err) |
| 72 } | 72 } |
| 73 | 73 |
| 74 func (g *giCounter) IsTimeoutError(err error) bool { | 74 func (g *infoCounter) IsTimeoutError(err error) bool { |
| 75 g.c.IsTimeoutError.up() | 75 g.c.IsTimeoutError.up() |
| 76 return g.gi.IsTimeoutError(err) | 76 return g.gi.IsTimeoutError(err) |
| 77 } | 77 } |
| 78 | 78 |
| 79 func (g *giCounter) ModuleHostname(module, version, instance string) (string, er
ror) { | 79 func (g *infoCounter) ModuleHostname(module, version, instance string) (string,
error) { |
| 80 ret, err := g.gi.ModuleHostname(module, version, instance) | 80 ret, err := g.gi.ModuleHostname(module, version, instance) |
| 81 return ret, g.c.ModuleHostname.up(err) | 81 return ret, g.c.ModuleHostname.up(err) |
| 82 } | 82 } |
| 83 | 83 |
| 84 func (g *giCounter) ModuleName() string { | 84 func (g *infoCounter) ModuleName() string { |
| 85 g.c.ModuleName.up() | 85 g.c.ModuleName.up() |
| 86 return g.gi.ModuleName() | 86 return g.gi.ModuleName() |
| 87 } | 87 } |
| 88 | 88 |
| 89 func (g *giCounter) RequestID() string { | 89 func (g *infoCounter) RequestID() string { |
| 90 g.c.RequestID.up() | 90 g.c.RequestID.up() |
| 91 return g.gi.RequestID() | 91 return g.gi.RequestID() |
| 92 } | 92 } |
| 93 | 93 |
| 94 func (g *giCounter) ServerSoftware() string { | 94 func (g *infoCounter) ServerSoftware() string { |
| 95 g.c.ServerSoftware.up() | 95 g.c.ServerSoftware.up() |
| 96 return g.gi.ServerSoftware() | 96 return g.gi.ServerSoftware() |
| 97 } | 97 } |
| 98 | 98 |
| 99 func (g *giCounter) ServiceAccount() (string, error) { | 99 func (g *infoCounter) ServiceAccount() (string, error) { |
| 100 ret, err := g.gi.ServiceAccount() | 100 ret, err := g.gi.ServiceAccount() |
| 101 return ret, g.c.ServiceAccount.up(err) | 101 return ret, g.c.ServiceAccount.up(err) |
| 102 } | 102 } |
| 103 | 103 |
| 104 func (g *giCounter) VersionID() string { | 104 func (g *infoCounter) VersionID() string { |
| 105 g.c.VersionID.up() | 105 g.c.VersionID.up() |
| 106 return g.gi.VersionID() | 106 return g.gi.VersionID() |
| 107 } | 107 } |
| 108 | 108 |
| 109 func (g *giCounter) Namespace(namespace string) (context.Context, error) { | 109 func (g *infoCounter) Namespace(namespace string) (context.Context, error) { |
| 110 ret, err := g.gi.Namespace(namespace) | 110 ret, err := g.gi.Namespace(namespace) |
| 111 return ret, g.c.Namespace.up(err) | 111 return ret, g.c.Namespace.up(err) |
| 112 } | 112 } |
| 113 | 113 |
| 114 func (g *giCounter) AccessToken(scopes ...string) (token string, expiry time.Tim
e, err error) { | 114 func (g *infoCounter) AccessToken(scopes ...string) (token string, expiry time.T
ime, err error) { |
| 115 token, expiry, err = g.gi.AccessToken(scopes...) | 115 token, expiry, err = g.gi.AccessToken(scopes...) |
| 116 g.c.AccessToken.up(err) | 116 g.c.AccessToken.up(err) |
| 117 return | 117 return |
| 118 } | 118 } |
| 119 | 119 |
| 120 func (g *giCounter) PublicCertificates() ([]gae.GICertificate, error) { | 120 func (g *infoCounter) PublicCertificates() ([]info.Certificate, error) { |
| 121 ret, err := g.gi.PublicCertificates() | 121 ret, err := g.gi.PublicCertificates() |
| 122 return ret, g.c.PublicCertificates.up(err) | 122 return ret, g.c.PublicCertificates.up(err) |
| 123 } | 123 } |
| 124 | 124 |
| 125 func (g *giCounter) SignBytes(bytes []byte) (keyName string, signature []byte, e
rr error) { | 125 func (g *infoCounter) SignBytes(bytes []byte) (keyName string, signature []byte,
err error) { |
| 126 keyName, signature, err = g.gi.SignBytes(bytes) | 126 keyName, signature, err = g.gi.SignBytes(bytes) |
| 127 g.c.SignBytes.up(err) | 127 g.c.SignBytes.up(err) |
| 128 return | 128 return |
| 129 } | 129 } |
| 130 | 130 |
| 131 // FilterGI installs a counter GlobalInfo filter in the context. | 131 // FilterGI installs a counter GlobalInfo filter in the context. |
| 132 func FilterGI(c context.Context) (context.Context, *GICounter) { | 132 func FilterGI(c context.Context) (context.Context, *InfoCounter) { |
| 133 » state := &GICounter{} | 133 » state := &InfoCounter{} |
| 134 » return gae.AddGIFilters(c, func(ic context.Context, gi gae.GlobalInfo) g
ae.GlobalInfo { | 134 » return info.AddFilters(c, func(ic context.Context, gi info.Interface) in
fo.Interface { |
| 135 » » return &giCounter{state, gi} | 135 » » return &infoCounter{state, gi} |
| 136 }), state | 136 }), state |
| 137 } | 137 } |
| OLD | NEW |