This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
Fix CI #1164
Merged
Merged
Fix CI #1164
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1d576ff
remove dead code
gdbelvin 6f241eb
Update kubernetes binary paths
gdbelvin 3a3c2df
Slightly faster grpc matcher
gdbelvin 0b8b70a
DialContext
gdbelvin 3d1ee8a
serveHTTPMetric in separate function
gdbelvin 3492a31
Remove TLS config from grpc server
gdbelvin 17892df
Move runSequencer to its own function
gdbelvin b447127
serveHTTPGateway with listener and dopts
gdbelvin 69dee27
Set transport creds on grpc client
gdbelvin dc40c1f
Fixup mains
gdbelvin b320e44
nits
gdbelvin 9c18e6f
Merge branch 'master' into etcd
gdbelvin e3d391b
Merge branch 'master' into etcd
gdbelvin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ import ( | |
"fmt" | ||
"net" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
|
@@ -44,6 +43,7 @@ import ( | |
"github.com/google/keytransparency/impl/sql/mutationstorage" | ||
|
||
pb "github.com/google/keytransparency/core/api/v1/keytransparency_go_proto" | ||
dir "github.com/google/keytransparency/core/directory" | ||
spb "github.com/google/keytransparency/core/sequencer/sequencer_go_proto" | ||
etcdelect "github.com/google/trillian/util/election2/etcd" | ||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" | ||
|
@@ -115,13 +115,15 @@ func getElectionFactory() (election2.Factory, func()) { | |
func main() { | ||
flag.Parse() | ||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
// Connect to trillian log and map backends. | ||
mconn, err := grpc.Dial(*mapURL, grpc.WithInsecure()) | ||
mconn, err := grpc.DialContext(ctx, *mapURL, grpc.WithInsecure()) | ||
if err != nil { | ||
glog.Exitf("grpc.Dial(%v): %v", *mapURL, err) | ||
} | ||
lconn, err := grpc.Dial(*logURL, grpc.WithInsecure()) | ||
lconn, err := grpc.DialContext(ctx, *logURL, grpc.WithInsecure()) | ||
if err != nil { | ||
glog.Exitf("Failed to connect to %v: %v", *logURL, err) | ||
} | ||
|
@@ -139,12 +141,7 @@ func main() { | |
glog.Exitf("Failed to create directory storage object: %v", err) | ||
} | ||
|
||
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile) | ||
if err != nil { | ||
glog.Exitf("Failed to load server credentials %v", err) | ||
} | ||
grpcServer := grpc.NewServer( | ||
grpc.Creds(creds), | ||
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor), | ||
grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor), | ||
) | ||
|
@@ -154,9 +151,15 @@ func main() { | |
if err != nil { | ||
glog.Exitf("error creating TCP listener: %v", err) | ||
} | ||
addr := lis.Addr().String() | ||
glog.Infof("Listening on %v", lis.Addr().String()) | ||
// Non-blocking dial before we start the server. | ||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure()) | ||
tcreds, err := credentials.NewClientTLSFromFile(*certFile, "localhost") | ||
if err != nil { | ||
glog.Exitf("Failed opening cert file %v: %v", *certFile, err) | ||
} | ||
dopts := []grpc.DialOption{grpc.WithTransportCredentials(tcreds)} | ||
addr := lis.Addr().String() | ||
conn, err := grpc.DialContext(ctx, addr, dopts...) | ||
if err != nil { | ||
glog.Exitf("error connecting to %v: %v", addr, err) | ||
} | ||
|
@@ -190,16 +193,18 @@ func main() { | |
glog.Infof("Signer starting") | ||
|
||
// Run servers | ||
httpServer := startHTTPServer(grpcServer, addr, | ||
go serveHTTPMetric(*metricsAddr) | ||
go serveHTTPGateway(ctx, lis, dopts, grpcServer, | ||
pb.RegisterKeyTransparencyAdminHandlerFromEndpoint, | ||
) | ||
runSequencer(ctx, conn, mconn, directoryStorage) | ||
|
||
cli, err := etcd.NewClient(strings.Split(*etcdServers, ","), 5*time.Second) | ||
if err != nil || cli == nil { | ||
glog.Exitf("Failed to create etcd client: %v", err) | ||
} | ||
// Shutdown. | ||
glog.Errorf("Signer exiting") | ||
} | ||
|
||
// Periodically run batch. | ||
func runSequencer(ctx context.Context, conn, mconn *grpc.ClientConn, | ||
directoryStorage dir.Storage) { | ||
electionFactory, closeFactory := getElectionFactory() | ||
defer closeFactory() | ||
signer := sequencer.New( | ||
|
@@ -210,15 +215,9 @@ func main() { | |
election.NewTracker(electionFactory, 1*time.Hour, prometheus.MetricFactory{}), | ||
) | ||
|
||
cctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
sequencer.PeriodicallyRun(cctx, time.Tick(*refresh), func(ctx context.Context) { | ||
sequencer.PeriodicallyRun(ctx, time.Tick(*refresh), func(ctx context.Context) { | ||
if err := signer.RunBatchForAllDirectories(ctx); err != nil { | ||
glog.Errorf("PeriodicallyRun(RunBatchForAllDirectories): %v", err) | ||
} | ||
}) | ||
|
||
// Shutdown. | ||
httpServer.Shutdown(cctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is the server shut down now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading the documentation closely, |
||
glog.Errorf("Signer exiting") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
certFile
andkeyFile
be marked as deprecated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still use
certFile
andkeyFile
- they just get used as part ofhttp.ServeTLS
rather than the go server itself.