Issue #239 - Add a build ID method to WFE, and print Info on startup for all

This commit is contained in:
J.C. Jones 2015-05-28 07:38:51 -07:00
parent d1321f2d78
commit 8766edaa93
14 changed files with 63 additions and 4 deletions

View File

@ -12,6 +12,9 @@ OBJECTS = activity-monitor \
boulder-wfe \
ocsp-updater
REVID = $(shell git symbolic-ref --short HEAD):$(shell git rev-parse --short HEAD)
BUILD_ID_VAR = github.com/letsencrypt/boulder/core.BuildID
.PHONY: all build
all: build
@ -23,8 +26,8 @@ pre:
# Compile each of the binaries
$(OBJECTS): pre
go build -o ./bin/$@ cmd/$@/main.go
go build -o ./bin/$@ -ldflags "-X $(BUILD_ID_VAR) $(REVID)" cmd/$@/main.go
clean:
rm -f $(OBJDIR)/*
rmdir $(OBJDIR)
rmdir $(OBJDIR)

View File

@ -12,13 +12,14 @@ package main
import (
"fmt"
"os"
"time"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/streadway/amqp"
"github.com/letsencrypt/boulder/analysis"
"github.com/letsencrypt/boulder/cmd"
blog "github.com/letsencrypt/boulder/log"
"time"
)
const (
@ -150,6 +151,8 @@ func main() {
go cmd.ProfileCmd("AM", stats)
auditlogger.Info(app.VersionString())
startMonitor(ch, auditlogger, stats)
}

View File

@ -58,6 +58,8 @@ func main() {
cas, err := rpc.NewCertificateAuthorityServer(c.AMQP.CA.Server, ch, cai)
cmd.FailOnError(err, "Unable to create CA server")
auditlogger.Info(app.VersionString())
cmd.RunUntilSignaled(auditlogger, cas, closeChan)
}
}

View File

@ -56,6 +56,8 @@ func main() {
ras, err := rpc.NewRegistrationAuthorityServer(c.AMQP.RA.Server, ch, &rai)
cmd.FailOnError(err, "Unable to create RA server")
auditlogger.Info(app.VersionString())
cmd.RunUntilSignaled(auditlogger, ras, closeChan)
}

View File

@ -50,6 +50,8 @@ func main() {
sas := rpc.NewStorageAuthorityServer(c.AMQP.SA.Server, ch, sai)
auditlogger.Info(app.VersionString())
cmd.RunUntilSignaled(auditlogger, sas, closeChan)
}
}

View File

@ -46,6 +46,8 @@ func main() {
vas, err := rpc.NewValidationAuthorityServer(c.AMQP.VA.Server, ch, &vai)
cmd.FailOnError(err, "Unable to create VA server")
auditlogger.Info(app.VersionString())
cmd.RunUntilSignaled(auditlogger, vas, closeChan)
}
}

View File

@ -8,10 +8,10 @@ package main
import (
"fmt"
"net/http"
"time"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/streadway/amqp"
"time"
"github.com/letsencrypt/boulder/cmd"
blog "github.com/letsencrypt/boulder/log"
@ -110,6 +110,8 @@ func main() {
wfe.BaseURL = c.WFE.BaseURL
wfe.HandlePaths()
auditlogger.Info(app.VersionString())
// Add HandlerTimer to output resp time + success/failure stats to statsd
err = http.ListenAndServe(c.WFE.ListenAddress, HandlerTimer(http.DefaultServeMux, stats))
cmd.FailOnError(err, "Error starting HTTP server")

View File

@ -117,6 +117,8 @@ func main() {
wfei.BaseURL = c.WFE.BaseURL
wfei.HandlePaths()
auditlogger.Info(app.VersionString())
fmt.Fprintf(os.Stderr, "Server running, listening on %s...\n", c.WFE.ListenAddress)
err = http.ListenAndServe(c.WFE.ListenAddress, HandlerTimer(http.DefaultServeMux, stats))
cmd.FailOnError(err, "Error starting HTTP server")

View File

@ -19,6 +19,7 @@ import (
"golang.org/x/crypto/ocsp"
"github.com/letsencrypt/boulder/cmd"
"github.com/letsencrypt/boulder/core"
blog "github.com/letsencrypt/boulder/log"
)
@ -134,6 +135,8 @@ func main() {
// Configure HTTP
http.Handle(c.OCSP.Path, cfocsp.Responder{Source: src})
auditlogger.Info(app.VersionString())
// Add HandlerTimer to output resp time + success/failure stats to statsd
err = http.ListenAndServe(c.WFE.ListenAddress, HandlerTimer(http.DefaultServeMux, stats))
cmd.FailOnError(err, "Error starting HTTP server")

View File

@ -181,6 +181,8 @@ func main() {
}
}()
auditlogger.Info(app.VersionString())
// Calculate the cut-off timestamp
dur, err := time.ParseDuration(c.OCSP.MinTimeToExpiry)
cmd.FailOnError(err, "Could not parse MinTimeToExpiry from config.")

View File

@ -38,6 +38,7 @@ import (
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/streadway/amqp"
"github.com/letsencrypt/boulder/ca"
"github.com/letsencrypt/boulder/core"
blog "github.com/letsencrypt/boulder/log"
"github.com/letsencrypt/boulder/rpc"
)
@ -163,6 +164,11 @@ func (as *AppShell) Run() {
FailOnError(err, "Failed to run application")
}
// VersionString produces a friendly Application version string
func (as *AppShell) VersionString() string {
return fmt.Sprintf("%s (version %s, build %s)", as.App.Name, as.App.Version, core.GetBuildID())
}
// FailOnError exits and prints an error message if we encountered a problem
func FailOnError(err error, msg string) {
if err != nil {

View File

@ -28,6 +28,12 @@ import (
"strings"
)
// Package Variables Variables
// BuildID is set by the compiler (using -ldflags "-X core.BuildID $(git rev-parse --short HEAD)")
// and is used by GetBuildID
var BuildID string
// Errors
type NotSupportedError string
@ -232,3 +238,12 @@ func StringToSerial(serial string) (*big.Int, error) {
_, err := fmt.Sscanf(serial, "%032x", &serialNum)
return &serialNum, err
}
// GetBuildID identifies what build is running.
func GetBuildID() (retID string) {
retID = BuildID
if retID == "" {
retID = "Unspecified"
}
return
}

View File

@ -48,3 +48,7 @@ func TestSerialUtils(t *testing.T) {
test.AssertEquals(t, fmt.Sprintf("%v", err), "Serial number should be 32 characters long")
fmt.Println(badSerial)
}
func TestBuildID(t *testing.T) {
test.AssertEquals(t, "Unspecified", GetBuildID())
}

View File

@ -36,6 +36,7 @@ const (
RevokeCertPath = "/acme/revoke-cert/"
TermsPath = "/terms"
IssuerPath = "/acme/issuer-cert"
BuildIDPath = "/build"
)
// WebFrontEndImpl represents a Boulder web service and its resources
@ -88,6 +89,7 @@ func (wfe *WebFrontEndImpl) HandlePaths() {
http.HandleFunc(RevokeCertPath, wfe.RevokeCertificate)
http.HandleFunc(TermsPath, wfe.Terms)
http.HandleFunc(IssuerPath, wfe.Issuer)
http.HandleFunc(BuildIDPath, wfe.BuildID)
}
// Method implementations
@ -744,3 +746,12 @@ func (wfe *WebFrontEndImpl) Issuer(w http.ResponseWriter, r *http.Request) {
wfe.log.Warning(fmt.Sprintf("Could not write response: %s", err))
}
}
// BuildID tells the requestor what build we're running.
func (wfe *WebFrontEndImpl) BuildID(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
if _, err := fmt.Fprintln(w, core.GetBuildID()); err != nil {
wfe.log.Warning(fmt.Sprintf("Could not write response: %s", err))
}
}