Skip to content

Commit 23d6240

Browse files
authored
Don't register HTTP/JSON handlers (#1677)
* Don't register HTTP/JSON handlers * Use grpcurl in quota setup scripts * Update quota README to use grpcurl * Changelog * Remove grpc gateway generated files * Remove grpc-gateway dependency
1 parent fe78e13 commit 23d6240

File tree

17 files changed

+28
-2916
lines changed

17 files changed

+28
-2916
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
script: ./integration/integration_test.sh && HAMMER_OPTS="--operations=150" ./integration/maphammer.sh 3
117117
- name: "integration (etcd)"
118118
env: GOFLAGS='-race' ETCD_DIR="${GOPATH}/bin" GO_TEST_TIMEOUT=20m
119-
install: go install go.etcd.io/etcd go.etcd.io/etcd/etcdctl
119+
install: go install go.etcd.io/etcd go.etcd.io/etcd/etcdctl github.com/fullstorydev/grpcurl/cmd/grpcurl
120120
script: ./integration/integration_test.sh && HAMMER_OPTS="--operations=50" ./integration/maphammer.sh 3
121121
- name: "integration (batched_queue)"
122122
env: GOFLAGS='-race --tags=batched_queue' GO_TEST_TIMEOUT=20m

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
Not yet released; provisionally v1.4.0 (may change).
66

7+
### HTTP APIs
8+
9+
The HTTP/JSON APIs have been removed in favor of a pure gRPC intereface.
10+
[grpcurl](https://github.com/fullstorydev/grpcurl) is the recommended way
11+
of interacting with the gRPC API from the commandline.
12+
713
### Server Binaries
814

915
The `trillian_log_server`, `trillian_log_signer` and `trillian_map_server`

cmd/internal/serverutil/main.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/google/trillian/server/interceptor"
3131
"github.com/google/trillian/util"
3232
"github.com/google/trillian/util/clock"
33-
"github.com/grpc-ecosystem/grpc-gateway/runtime"
3433
"github.com/prometheus/client_golang/prometheus/promhttp"
3534
"google.golang.org/grpc"
3635
"google.golang.org/grpc/credentials"
@@ -55,8 +54,8 @@ const (
5554

5655
// Main encapsulates the data and logic to start a Trillian server (Log or Map).
5756
type Main struct {
58-
// Endpoints for RPC and HTTP/REST servers.
59-
// HTTP/REST is optional, if empty it'll not be bound.
57+
// Endpoints for RPC and HTTP servers.
58+
// HTTP is optional, if empty it'll not be bound.
6059
RPCEndpoint, HTTPEndpoint string
6160

6261
// TLS Certificate and Key files for the server.
@@ -69,8 +68,6 @@ type Main struct {
6968
StatsPrefix string
7069
QuotaDryRun bool
7170

72-
// RegisterHandlerFn is called to register REST-proxy handlers.
73-
RegisterHandlerFn func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error
7471
// RegisterServerFn is called to register RPC servers.
7572
RegisterServerFn func(*grpc.Server, extension.Registry) error
7673

@@ -130,16 +127,6 @@ func (m *Main) Run(ctx context.Context) error {
130127
reflection.Register(srv)
131128

132129
if endpoint := m.HTTPEndpoint; endpoint != "" {
133-
gatewayMux := runtime.NewServeMux()
134-
opts := []grpc.DialOption{grpc.WithInsecure()}
135-
if err := m.RegisterHandlerFn(ctx, gatewayMux, m.RPCEndpoint, opts); err != nil {
136-
return err
137-
}
138-
if err := trillian.RegisterTrillianAdminHandlerFromEndpoint(ctx, gatewayMux, m.RPCEndpoint, opts); err != nil {
139-
return err
140-
}
141-
142-
http.Handle("/", gatewayMux)
143130
http.Handle("/metrics", promhttp.Handler())
144131
http.HandleFunc("/healthz", m.healthz)
145132

cmd/trillian_log_server/main.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343
"github.com/google/trillian/storage"
4444
"github.com/google/trillian/util/clock"
4545
etcdutil "github.com/google/trillian/util/etcd"
46-
"github.com/grpc-ecosystem/grpc-gateway/runtime"
4746
"google.golang.org/grpc"
4847

4948
// Register key ProtoHandlers
@@ -64,7 +63,7 @@ import (
6463

6564
var (
6665
rpcEndpoint = flag.String("rpc_endpoint", "localhost:8090", "Endpoint for RPC requests (host:port)")
67-
httpEndpoint = flag.String("http_endpoint", "localhost:8091", "Endpoint for HTTP metrics and REST requests on (host:port, empty means disabled)")
66+
httpEndpoint = flag.String("http_endpoint", "localhost:8091", "Endpoint for HTTP metrics (host:port, empty means disabled)")
6867
healthzTimeout = flag.Duration("healthz_timeout", time.Second*5, "Timeout used during healthz checks")
6968
tlsCertFile = flag.String("tls_cert_file", "", "Path to the TLS server certificate. If unset, the server will use unsecured connections.")
7069
tlsKeyFile = flag.String("tls_key_file", "", "Path to the TLS server key. If unset, the server will use unsecured connections.")
@@ -164,15 +163,6 @@ func main() {
164163
QuotaDryRun: *quotaDryRun,
165164
DBClose: sp.Close,
166165
Registry: registry,
167-
RegisterHandlerFn: func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error {
168-
if err := trillian.RegisterTrillianLogHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil {
169-
return err
170-
}
171-
if *quota.System == etcd.QuotaManagerName {
172-
return quotapb.RegisterQuotaHandlerFromEndpoint(ctx, mux, endpoint, opts)
173-
}
174-
return nil
175-
},
176166
RegisterServerFn: func(s *grpc.Server, registry extension.Registry) error {
177167
logServer := server.NewTrillianLogRPCServer(registry, clock.System)
178168
if err := logServer.IsHealthy(); err != nil {

cmd/trillian_log_signer/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/google/trillian/util/election2"
4242
etcdelect "github.com/google/trillian/util/election2/etcd"
4343
etcdutil "github.com/google/trillian/util/etcd"
44-
"github.com/grpc-ecosystem/grpc-gateway/runtime"
4544
"google.golang.org/grpc"
4645

4746
tpb "github.com/google/trillian"
@@ -194,10 +193,6 @@ func main() {
194193
StatsPrefix: "logsigner",
195194
DBClose: sp.Close,
196195
Registry: registry,
197-
RegisterHandlerFn: func(_ context.Context, _ *runtime.ServeMux, _ string, _ []grpc.DialOption) error {
198-
// No HTTP APIs are being exported.
199-
return nil
200-
},
201196
RegisterServerFn: func(s *grpc.Server, _ extension.Registry) error {
202197
tpb.RegisterTrillianLogSequencerServer(s, &struct{}{})
203198
return nil

cmd/trillian_map_server/main.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/google/trillian/server"
4141
"github.com/google/trillian/storage"
4242
etcdutil "github.com/google/trillian/util/etcd"
43-
"github.com/grpc-ecosystem/grpc-gateway/runtime"
4443
"google.golang.org/grpc"
4544

4645
// Register key ProtoHandlers
@@ -62,7 +61,7 @@ import (
6261

6362
var (
6463
rpcEndpoint = flag.String("rpc_endpoint", "localhost:8090", "Endpoint for RPC requests (host:port)")
65-
httpEndpoint = flag.String("http_endpoint", "localhost:8091", "Endpoint for HTTP metrics and REST requests on (host:port, empty means disabled)")
64+
httpEndpoint = flag.String("http_endpoint", "localhost:8091", "Endpoint for HTTP metrics (host:port, empty means disabled)")
6665
healthzTimeout = flag.Duration("healthz_timeout", time.Second*5, "Timeout used during healthz checks")
6766
tlsCertFile = flag.String("tls_cert_file", "", "Path to the TLS server certificate. If unset, the server will use unsecured connections.")
6867
tlsKeyFile = flag.String("tls_key_file", "", "Path to the TLS server key. If unset, the server will use unsecured connections.")
@@ -154,15 +153,6 @@ func main() {
154153
QuotaDryRun: *quotaDryRun,
155154
DBClose: sp.Close,
156155
Registry: registry,
157-
RegisterHandlerFn: func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error {
158-
if err := trillian.RegisterTrillianMapHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil {
159-
return err
160-
}
161-
if *quota.System == etcd.QuotaManagerName {
162-
return quotapb.RegisterQuotaHandlerFromEndpoint(ctx, mux, endpoint, opts)
163-
}
164-
return nil
165-
},
166156
RegisterServerFn: func(s *grpc.Server, registry extension.Registry) error {
167157
mapServer := server.NewTrillianMapServer(registry,
168158
server.TrillianMapServerOptions{

gen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package trillian
1717
//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/googleapis/googleapis --go_out=plugins=grpc,paths=source_relative:. trillian_log_api.proto trillian_log_sequencer_api.proto trillian_map_api.proto trillian_admin_api.proto trillian.proto --doc_out=markdown,api.md:./docs/
1818
//go:generate protoc -I=. --go_out=paths=source_relative:. crypto/sigpb/sigpb.proto
1919
//go:generate protoc -I=. --go_out=paths=source_relative:. crypto/keyspb/keyspb.proto
20-
//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/googleapis/googleapis --grpc-gateway_out=logtostderr=true,paths=source_relative:. trillian_log_api.proto trillian_map_api.proto trillian_admin_api.proto trillian.proto
2120

2221
//go:generate mockgen -package tmock -destination testonly/tmock/mock_log_server.go github.com/google/trillian TrillianLogServer
2322
//go:generate mockgen -package tmock -destination testonly/tmock/mock_map_server.go github.com/google/trillian TrillianMapServer

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/google/uuid v1.1.1 // indirect
3232
github.com/gorilla/websocket v1.4.1 // indirect
3333
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
34-
github.com/grpc-ecosystem/grpc-gateway v1.12.1
34+
github.com/grpc-ecosystem/grpc-gateway v1.12.1 // indirect
3535
github.com/huandu/xstrings v1.2.0 // indirect
3636
github.com/imdario/mergo v0.3.8 // indirect
3737
github.com/jstemmer/go-junit-report v0.9.1 // indirect

integration/functions.sh

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ log_prep_test() {
179179

180180
# Setup etcd quotas, if applicable
181181
if [[ ${has_etcd} -eq 1 ]]; then
182-
setup_etcd_quotas "${HTTP_SERVER_1}"
182+
setup_etcd_quotas "${RPC_SERVER_1}"
183183
fi
184184

185185
# Start a set of signers.
@@ -231,10 +231,10 @@ log_stop_test() {
231231
# setup_etcd_quotas creates the etcd quota configurations used by tests.
232232
#
233233
# Parameters:
234-
# - server : HTTP endpoint for the quota API (eg, logserver http port)
234+
# - server : GRPC endpoint for the quota API (eg, logserver grpc port)
235235
#
236236
# Outputs:
237-
# DELETE and POST responses.
237+
# DeleteConfig and CreateConfig responses.
238238
#
239239
# Returns:
240240
# 0 if success, non-zero otherwise.
@@ -243,15 +243,10 @@ setup_etcd_quotas() {
243243
local name='quotas/global/write/config'
244244

245245
# Remove the config before creating. It's OK if it doesn't exist.
246-
local delete_output=$(curl -s -X DELETE "${server}/v1beta1/${name}")
247-
printf 'DELETE %s: %s\n' "${name}" "${delete_output}"
248-
249-
local create_output=$(curl \
250-
-d '@-' \
251-
-s \
252-
-H 'Content-Type: application/json' \
253-
-X POST \
254-
"${server}/v1beta1/${name}" <<EOF
246+
local delete_output=$(grpcurl -plaintext -d "name: ${name}" ${server} quotapb.Quota.DeleteConfig )
247+
printf 'quotapb.Quota.DeleteConfig %s: %s\n' "${name}" "${delete_output}"
248+
249+
local create_output=$(grpcurl -plaintext -d @ ${server} quotapb.Quota.CreateConfig <<EOF
255250
{
256251
"name": "${name}",
257252
"config": {
@@ -263,7 +258,7 @@ setup_etcd_quotas() {
263258
}
264259
EOF
265260
)
266-
printf 'POST %s: %s\n' "${name}" "${create_output}"
261+
printf 'quotapb.Quota.CreateConfig %s: %s\n' "${name}" "${create_output}"
267262

268263
# Success responses have the config name in them
269264
echo "${create_output}" | grep '"name":' > /dev/null

quota/etcd/README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
Package etcd (and its subpackages) contain an etcd-based
44
[quota.Manager](https://github.com/google/trillian/blob/3cf59cdfd0/quota/quota.go#L101)
5-
implementation, with a corresponding REST-based configuration service.
5+
implementation, with a corresponding configuration service.
66

77
## Usage
88

99
First, ensure both `logserver` and `logsigner` are started with the
10-
`--etcd_servers` and `--quota_system=etcd` flags, in addition to other flags.
11-
`logserver` must also be started with a non-empty `--http_endpoint` flag, so the
12-
REST quota API can be bound.
10+
`--etcd_servers` and `--quota_system=etcd` flags.
1311

1412
For example:
1513

1614
```bash
1715
trillian_log_server \
1816
--etcd_servers=... \
19-
--http_endpoint=localhost:8091 \
17+
--rpc_endpoint=localhost:8090 \
2018
--quota_system=etcd
2119

2220
trillian_log_signer --etcd_servers=... --quota_system=etcd
@@ -25,19 +23,14 @@ trillian_log_signer --etcd_servers=... --quota_system=etcd
2523
If correctly started, the servers will be using etcd quotas. The default
2624
configuration is empty, which means no quotas are enforced.
2725

28-
The REST quota API may be used to create and update configurations.
26+
The quota API may be used to create and update configurations.
2927

3028
For example, the command below creates a sequencing-based, `global/write` quota.
3129
Assuming an expected sequencing performance of 50 QPS, the `max_tokens`
3230
specified below implies a backlog of 4h.
3331

3432
```bash
35-
curl \
36-
-d '@-' \
37-
-s \
38-
-H 'Content-Type: application/json' \
39-
-X POST \
40-
'localhost:8091/v1beta1/quotas/global/write/config' <<EOF
33+
grpcurl -plaintext -d @ localhost:8090 v1beta1/quotas/global/write/config <<EOF
4134
{
4235
"name": "quotas/global/write/config",
4336
"config": {
@@ -53,11 +46,11 @@ EOF
5346
To list all configured quotas, run:
5447

5548
```bash
56-
curl 'localhost:8091/v1beta1/quotas?view=FULL'
49+
grpcurl -plaintext -d '{"view": "FULL"}' localhost:8090 v1beta1/quotas
5750
```
5851

5952
Quotas may be retrieved individually or via a series of filters, updated and
60-
deleted through the REST API as well. See
53+
deleted through the quota API as well. See
6154
[quotapb.proto](https://github.com/google/trillian/blob/master/quota/etcd/quotapb/quotapb.proto)
6255
for an in-depth description of entities and available methods.
6356

0 commit comments

Comments
 (0)