Skip to content

Commit 117a6ef

Browse files
authored
Cleanup: renames and delete unused file (#86)
* s/tesseraDeadline/httpDeadline * add comments * s/LogOrigin/Origin/g * delete proto_gen.go * add todo
1 parent 72abfe5 commit 117a6ef

File tree

5 files changed

+29
-34
lines changed

5 files changed

+29
-34
lines changed

cmd/gcp/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var (
5252

5353
httpEndpoint = flag.String("http_endpoint", "localhost:6962", "Endpoint for HTTP (host:port).")
5454
metricsEndpoint = flag.String("metrics_endpoint", "", "Endpoint for serving metrics; if left empty, metrics will be visible on --http_endpoint.")
55-
tesseraDeadline = flag.Duration("tessera_deadline", time.Second*10, "Deadline for Tessera requests.")
55+
httpDeadline = flag.Duration("http_deadline", time.Second*10, "Deadline for HTTP requests.")
5656
maskInternalErrors = flag.Bool("mask_internal_errors", false, "Don't return error strings with Internal Server Error HTTP responses.")
5757
tracing = flag.Bool("tracing", false, "If true opencensus Stackdriver tracing will be enabled. See https://opencensus.io/.")
5858
tracingProjectID = flag.String("tracing_project_id", "", "project ID to pass to stackdriver. Can be empty for GCP, consult docs for other platforms.")
@@ -104,7 +104,7 @@ func main() {
104104
// Register handlers for all the configured logs.
105105
opts := sctfe.InstanceOptions{
106106
Validated: vCfg,
107-
Deadline: *tesseraDeadline,
107+
Deadline: *httpDeadline,
108108
MetricFactory: prometheus.MetricFactory{},
109109
RequestLog: new(sctfe.DefaultRequestLog),
110110
MaskInternalErrors: *maskInternalErrors,

handlers.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,20 @@ type AppHandler struct {
100100
// does additional common error and stats processing.
101101
func (a AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
102102
var statusCode int
103-
label0 := a.Info.LogOrigin
103+
label0 := a.Info.Origin
104104
label1 := string(a.Name)
105105
reqsCounter.Inc(label0, label1)
106106
startTime := a.Info.TimeSource.Now()
107107
logCtx := a.Info.RequestLog.Start(r.Context())
108-
a.Info.RequestLog.LogOrigin(logCtx, a.Info.LogOrigin)
108+
a.Info.RequestLog.Origin(logCtx, a.Info.Origin)
109109
defer func() {
110110
latency := a.Info.TimeSource.Now().Sub(startTime).Seconds()
111111
rspLatency.Observe(latency, label0, label1, strconv.Itoa(statusCode))
112112
}()
113-
klog.V(2).Infof("%s: request %v %q => %s", a.Info.LogOrigin, r.Method, r.URL, a.Name)
113+
klog.V(2).Infof("%s: request %v %q => %s", a.Info.Origin, r.Method, r.URL, a.Name)
114+
// TODO(phboneff): add a.Method directly on the handler path and remove this test.
114115
if r.Method != a.Method {
115-
klog.Warningf("%s: %s wrong HTTP method: %v", a.Info.LogOrigin, a.Name, r.Method)
116+
klog.Warningf("%s: %s wrong HTTP method: %v", a.Info.Origin, a.Name, r.Method)
116117
a.Info.SendHTTPError(w, http.StatusMethodNotAllowed, fmt.Errorf("method not allowed: %s", r.Method))
117118
a.Info.RequestLog.Status(logCtx, http.StatusMethodNotAllowed)
118119
return
@@ -135,17 +136,17 @@ func (a AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
135136
var err error
136137
statusCode, err = a.Handler(ctx, a.Info, w, r)
137138
a.Info.RequestLog.Status(ctx, statusCode)
138-
klog.V(2).Infof("%s: %s <= st=%d", a.Info.LogOrigin, a.Name, statusCode)
139+
klog.V(2).Infof("%s: %s <= st=%d", a.Info.Origin, a.Name, statusCode)
139140
rspsCounter.Inc(label0, label1, strconv.Itoa(statusCode))
140141
if err != nil {
141-
klog.Warningf("%s: %s handler error: %v", a.Info.LogOrigin, a.Name, err)
142+
klog.Warningf("%s: %s handler error: %v", a.Info.Origin, a.Name, err)
142143
a.Info.SendHTTPError(w, statusCode, err)
143144
return
144145
}
145146

146147
// Additional check, for consistency the handler must return an error for non-200 st
147148
if statusCode != http.StatusOK {
148-
klog.Warningf("%s: %s handler non 200 without error: %d %v", a.Info.LogOrigin, a.Name, statusCode, err)
149+
klog.Warningf("%s: %s handler non 200 without error: %d %v", a.Info.Origin, a.Name, statusCode, err)
149150
a.Info.SendHTTPError(w, http.StatusInternalServerError, fmt.Errorf("http handler misbehaved, st: %d", statusCode))
150151
return
151152
}
@@ -190,8 +191,8 @@ func NewCertValidationOpts(trustedRoots *x509util.PEMCertPool, currentTime time.
190191

191192
// logInfo holds information for a specific log instance.
192193
type logInfo struct {
193-
// LogOrigin identifies the log, as per https://c2sp.org/static-ct-api
194-
LogOrigin string
194+
// Origin identifies the log, as per https://c2sp.org/static-ct-api
195+
Origin string
195196
// TimeSource is a TimeSource that can be injected for testing
196197
TimeSource TimeSource
197198
// RequestLog is a logger for various request / processing / response debug
@@ -219,7 +220,7 @@ func newLogInfo(
219220
cfg := instanceOpts.Validated
220221

221222
li := &logInfo{
222-
LogOrigin: cfg.Origin,
223+
Origin: cfg.Origin,
223224
storage: storage,
224225
signer: signer,
225226
TimeSource: timeSource,
@@ -297,7 +298,7 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
297298
// Check the contents of the request and convert to slice of certificates.
298299
addChainReq, err := ParseBodyAsJSONChain(r)
299300
if err != nil {
300-
return http.StatusBadRequest, fmt.Errorf("%s: failed to parse add-chain body: %s", li.LogOrigin, err)
301+
return http.StatusBadRequest, fmt.Errorf("%s: failed to parse add-chain body: %s", li.Origin, err)
301302
}
302303
// Log the DERs now because they might not parse as valid X.509.
303304
for _, der := range addChainReq.Chain {
@@ -319,22 +320,22 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
319320
return http.StatusBadRequest, fmt.Errorf("failed to build MerkleTreeLeaf: %s", err)
320321
}
321322

322-
klog.V(2).Infof("%s: %s => storage.GetCertIndex", li.LogOrigin, method)
323+
klog.V(2).Infof("%s: %s => storage.GetCertIndex", li.Origin, method)
323324
sctDedupInfo, isDup, err := li.storage.GetCertDedupInfo(ctx, chain[0])
324325
idx := sctDedupInfo.Idx
325326
if err != nil {
326327
return http.StatusInternalServerError, fmt.Errorf("couldn't deduplicate the request: %s", err)
327328
}
328329

329330
if isDup {
330-
klog.V(3).Infof("%s: %s - found duplicate entry at index %d", li.LogOrigin, method, idx)
331+
klog.V(3).Infof("%s: %s - found duplicate entry at index %d", li.Origin, method, idx)
331332
entry.Timestamp = sctDedupInfo.Timestamp
332333
} else {
333334
if err := li.storage.AddIssuerChain(ctx, chain[1:]); err != nil {
334335
return http.StatusInternalServerError, fmt.Errorf("failed to store issuer chain: %s", err)
335336
}
336337

337-
klog.V(2).Infof("%s: %s => storage.Add", li.LogOrigin, method)
338+
klog.V(2).Infof("%s: %s => storage.Add", li.Origin, method)
338339
idx, err = li.storage.Add(ctx, entry)()
339340
if err != nil {
340341
if errors.Is(err, tessera.ErrPushback) {
@@ -346,7 +347,7 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
346347
// We store the index for this certificate in the deduplication storage immediately.
347348
// It might be stored again later, if a local deduplication storage is synced, potentially
348349
// with a smaller value.
349-
klog.V(2).Infof("%s: %s => storage.AddCertIndex", li.LogOrigin, method)
350+
klog.V(2).Infof("%s: %s => storage.AddCertIndex", li.Origin, method)
350351
err = li.storage.AddCertDedupInfo(ctx, chain[0], dedup.SCTDedupInfo{Idx: idx, Timestamp: entry.Timestamp})
351352
// TODO: block log writes if deduplication breaks
352353
if err != nil {
@@ -381,9 +382,9 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
381382
// reason is logged and http status is already set
382383
return http.StatusInternalServerError, fmt.Errorf("failed to write response: %s", err)
383384
}
384-
klog.V(3).Infof("%s: %s <= SCT", li.LogOrigin, method)
385+
klog.V(3).Infof("%s: %s <= SCT", li.Origin, method)
385386
if sct.Timestamp == timeMillis {
386-
lastSCTTimestamp.Set(float64(sct.Timestamp), li.LogOrigin)
387+
lastSCTTimestamp.Set(float64(sct.Timestamp), li.Origin)
387388
}
388389

389390
return http.StatusOK, nil
@@ -409,14 +410,14 @@ func getRoots(_ context.Context, li *logInfo, w http.ResponseWriter, _ *http.Req
409410
enc := json.NewEncoder(w)
410411
err := enc.Encode(jsonMap)
411412
if err != nil {
412-
klog.Warningf("%s: get_roots failed: %v", li.LogOrigin, err)
413+
klog.Warningf("%s: get_roots failed: %v", li.Origin, err)
413414
return http.StatusInternalServerError, fmt.Errorf("get-roots failed with: %s", err)
414415
}
415416

416417
return http.StatusOK, nil
417418
}
418419

419-
// deadlineTime calculates the future time an RPC should expire based on our config
420+
// deadlineTime calculates the future time a request should expire based on our config.
420421
func deadlineTime(li *logInfo) time.Time {
421422
return li.TimeSource.Now().Add(li.instanceOpts.Deadline)
422423
}
@@ -440,9 +441,9 @@ func verifyAddChain(li *logInfo, req ct.AddChainRequest, expectingPrecert bool)
440441
// The type of the leaf must match the one the handler expects
441442
if isPrecert != expectingPrecert {
442443
if expectingPrecert {
443-
klog.Warningf("%s: Cert (or precert with invalid CT ext) submitted as precert chain: %q", li.LogOrigin, req.Chain)
444+
klog.Warningf("%s: Cert (or precert with invalid CT ext) submitted as precert chain: %q", li.Origin, req.Chain)
444445
} else {
445-
klog.Warningf("%s: Precert (or cert with invalid CT ext) submitted as cert chain: %q", li.LogOrigin, req.Chain)
446+
klog.Warningf("%s: Precert (or cert with invalid CT ext) submitted as cert chain: %q", li.Origin, req.Chain)
446447
}
447448
return nil, fmt.Errorf("cert / precert mismatch: %T", expectingPrecert)
448449
}

instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type InstanceOptions struct {
3535
Validated *ValidatedLogConfig
3636
// CreateStorage instantiates a Tessera storage implementation with a signer option.
3737
CreateStorage func(context.Context, note.Signer) (*CTStorage, error)
38-
// Deadline is a timeout for Tessera requests.
38+
// Deadline is a timeout for HTTP requests.
3939
Deadline time.Duration
4040
// MetricFactory allows creating metrics.
4141
MetricFactory monitoring.MetricFactory

proto_gen.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

requestlog.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type RequestLog interface {
3838
// The returned context should be used in all the following calls to
3939
// this API. This is normally arranged by the request handler code.
4040
Start(context.Context) context.Context
41-
// LogOrigin will be called once per request to set the log prefix.
42-
LogOrigin(context.Context, string)
41+
// Origin will be called once per request to set the log prefix.
42+
Origin(context.Context, string)
4343
// AddDERToChain will be called once for each certificate in a submitted
4444
// chain. It's called early in request processing so the supplied bytes
4545
// have not been checked for validity. Calls will be in order of the
@@ -71,8 +71,8 @@ func (dlr *DefaultRequestLog) Start(ctx context.Context) context.Context {
7171
return ctx
7272
}
7373

74-
// LogOrigin logs the origin of the CT log that this request is for.
75-
func (dlr *DefaultRequestLog) LogOrigin(_ context.Context, p string) {
74+
// Origin logs the origin of the CT log that this request is for.
75+
func (dlr *DefaultRequestLog) Origin(_ context.Context, p string) {
7676
klog.V(vLevel).Infof("RL: LogOrigin: %s", p)
7777
}
7878

0 commit comments

Comments
 (0)