Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: tokenserver/appengine/frontend/main.go

Issue 2945013002: grpc: Interceptor to catch panics and convert them to Internal errors. (Closed)
Patch Set: oops Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« grpc/grpcmon/server.go ('K') | « grpc/grpcutil/paniccatcher.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // Package frontend implements HTTP server that handles requests to 'default' 5 // Package frontend implements HTTP server that handles requests to 'default'
6 // module. 6 // module.
7 package frontend 7 package frontend
8 8
9 import ( 9 import (
10 "net/http" 10 "net/http"
11 11
12 "github.com/golang/protobuf/proto" 12 "github.com/golang/protobuf/proto"
13 "golang.org/x/net/context" 13 "golang.org/x/net/context"
14 "google.golang.org/grpc" 14 "google.golang.org/grpc"
15 "google.golang.org/grpc/codes" 15 "google.golang.org/grpc/codes"
16 16
17 "github.com/luci/luci-go/appengine/gaemiddleware" 17 "github.com/luci/luci-go/appengine/gaemiddleware"
18 "github.com/luci/luci-go/common/logging" 18 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/grpc/discovery" 19 "github.com/luci/luci-go/grpc/discovery"
20 "github.com/luci/luci-go/grpc/grpcmon" 20 "github.com/luci/luci-go/grpc/grpcmon"
21 "github.com/luci/luci-go/grpc/grpcutil"
21 "github.com/luci/luci-go/grpc/prpc" 22 "github.com/luci/luci-go/grpc/prpc"
22 "github.com/luci/luci-go/server/auth" 23 "github.com/luci/luci-go/server/auth"
23 "github.com/luci/luci-go/server/router" 24 "github.com/luci/luci-go/server/router"
24 25
25 "github.com/luci/luci-go/tokenserver/api/admin/v1" 26 "github.com/luci/luci-go/tokenserver/api/admin/v1"
26 "github.com/luci/luci-go/tokenserver/api/minter/v1" 27 "github.com/luci/luci-go/tokenserver/api/minter/v1"
27 28
28 "github.com/luci/luci-go/tokenserver/appengine/impl/services/admin/admin srv" 29 "github.com/luci/luci-go/tokenserver/appengine/impl/services/admin/admin srv"
29 "github.com/luci/luci-go/tokenserver/appengine/impl/services/admin/certa uthorities" 30 "github.com/luci/luci-go/tokenserver/appengine/impl/services/admin/certa uthorities"
30 "github.com/luci/luci-go/tokenserver/appengine/impl/services/minter/toke nminter" 31 "github.com/luci/luci-go/tokenserver/appengine/impl/services/minter/toke nminter"
(...skipping 17 matching lines...) Expand all
48 r := router.New() 49 r := router.New()
49 50
50 // Install auth, config and tsmon handlers. 51 // Install auth, config and tsmon handlers.
51 gaemiddleware.InstallHandlers(r) 52 gaemiddleware.InstallHandlers(r)
52 53
53 // The service has no UI, so just redirect to stock RPC explorer. 54 // The service has no UI, so just redirect to stock RPC explorer.
54 r.GET("/", router.MiddlewareChain{}, func(c *router.Context) { 55 r.GET("/", router.MiddlewareChain{}, func(c *router.Context) {
55 http.Redirect(c.Writer, c.Request, "/rpcexplorer/", http.StatusF ound) 56 http.Redirect(c.Writer, c.Request, "/rpcexplorer/", http.StatusF ound)
56 }) 57 })
57 58
58 » // Install all RPC servers. 59 » // Install all RPC servers. Catch panics, report metrics to tsmon (inclu ding
60 » // panics themselves, as Internal errors).
59 api := prpc.Server{ 61 api := prpc.Server{
60 » » UnaryServerInterceptor: grpcmon.NewUnaryServerInterceptor(nil), 62 » » UnaryServerInterceptor: grpcmon.NewUnaryServerInterceptor(grpcut il.NewUnaryServerPanicCatcher(nil)),
61 } 63 }
62 admin.RegisterCertificateAuthoritiesServer(&api, &admin.DecoratedCertifi cateAuthorities{ 64 admin.RegisterCertificateAuthoritiesServer(&api, &admin.DecoratedCertifi cateAuthorities{
63 Service: certauthorities.NewServer(), 65 Service: certauthorities.NewServer(),
64 Prelude: adminPrelude("admin.CertificateAuthorities"), 66 Prelude: adminPrelude("admin.CertificateAuthorities"),
65 }) 67 })
66 admin.RegisterAdminServer(&api, &admin.DecoratedAdmin{ 68 admin.RegisterAdminServer(&api, &admin.DecoratedAdmin{
67 Service: adminsrv.NewServer(), 69 Service: adminsrv.NewServer(),
68 Prelude: adminPrelude("admin.Admin"), 70 Prelude: adminPrelude("admin.Admin"),
69 }) 71 })
70 minter.RegisterTokenMinterServer(&api, tokenminter.NewServer()) // auth inside 72 minter.RegisterTokenMinterServer(&api, tokenminter.NewServer()) // auth inside
71 discovery.Enable(&api) 73 discovery.Enable(&api)
72 api.InstallHandlers(r, gaemiddleware.BaseProd()) 74 api.InstallHandlers(r, gaemiddleware.BaseProd())
73 75
74 // Expose all this stuff. 76 // Expose all this stuff.
75 http.DefaultServeMux.Handle("/", r) 77 http.DefaultServeMux.Handle("/", r)
76 } 78 }
OLDNEW
« grpc/grpcmon/server.go ('K') | « grpc/grpcutil/paniccatcher.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698