various error catch cleanups

This commit is contained in:
Roland Shoemaker 2015-04-14 18:08:35 -07:00
parent 12a5756a24
commit e9ac01f0f1
8 changed files with 22 additions and 46 deletions

View File

@ -38,7 +38,7 @@ const (
var openCalls int64 = 0 var openCalls int64 = 0
func timeDelivery(d amqp.Delivery, stats statsd.Statter, logger *blog.AuditLogger, deliveryTimings map[string]time.Time) { func timeDelivery(d amqp.Delivery, stats statsd.Statter, deliveryTimings map[string]time.Time) {
// If d is a call add to deliveryTimings and increment openCalls, if it is a // If d is a call add to deliveryTimings and increment openCalls, if it is a
// response then get time.Since original call from deliveryTiming, send timing metric, and // response then get time.Since original call from deliveryTiming, send timing metric, and
// decrement openCalls, in both cases send the gauges RpcCallsOpen and RpcBodySize // decrement openCalls, in both cases send the gauges RpcCallsOpen and RpcBodySize
@ -52,18 +52,12 @@ func timeDelivery(d amqp.Delivery, stats statsd.Statter, logger *blog.AuditLogge
respTime := time.Since(rpcSent) respTime := time.Since(rpcSent)
delete(deliveryTimings, fmt.Sprintf("%s:%s", d.CorrelationId, d.RoutingKey)) delete(deliveryTimings, fmt.Sprintf("%s:%s", d.CorrelationId, d.RoutingKey))
if err := stats.TimingDuration(fmt.Sprintf("RpcCallTime.%s", d.Type), respTime, 1.0); err != nil { stats.TimingDuration(fmt.Sprintf("RpcCallTime.%s", d.Type), respTime, 1.0)
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server: %s", err))
}
} }
} }
if err := stats.Gauge("RpcCallsOpen", openCalls, 1.0); err != nil { stats.Gauge("RpcCallsOpen", openCalls, 1.0)
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server: %s", err)) stats.Gauge("RpcBodySize", int64(len(d.Body)), 1.0)
}
if err := stats.Gauge("RpcBodySize", int64(len(d.Body)), 1.0); err != nil {
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server: %s", err))
}
} }
func startMonitor(rpcCh *amqp.Channel, logger *blog.AuditLogger, stats statsd.Statter) { func startMonitor(rpcCh *amqp.Channel, logger *blog.AuditLogger, stats statsd.Statter) {
@ -124,7 +118,7 @@ func startMonitor(rpcCh *amqp.Channel, logger *blog.AuditLogger, stats statsd.St
// Run forever. // Run forever.
for d := range deliveries { for d := range deliveries {
go timeDelivery(d, stats, logger, deliveryTimings) go timeDelivery(d, stats, deliveryTimings)
// Pass each message to the Analysis Engine // Pass each message to the Analysis Engine
err = ae.ProcessMessage(d) err = ae.ProcessMessage(d)
@ -152,7 +146,7 @@ func main() {
ch := cmd.AmqpChannel(c.AMQP.Server) ch := cmd.AmqpChannel(c.AMQP.Server)
go cmd.ProfileCmd("AM", stats, auditlogger) go cmd.ProfileCmd("AM", stats)
startMonitor(ch, auditlogger, stats) startMonitor(ch, auditlogger, stats)
} }

View File

@ -28,7 +28,7 @@ func main() {
cai, err := ca.NewCertificateAuthorityImpl(auditlogger, c.CA.Server, c.CA.AuthKey, c.CA.Profile) cai, err := ca.NewCertificateAuthorityImpl(auditlogger, c.CA.Server, c.CA.AuthKey, c.CA.Profile)
cmd.FailOnError(err, "Failed to create CA impl") cmd.FailOnError(err, "Failed to create CA impl")
go cmd.ProfileCmd("CA", stats, auditlogger) go cmd.ProfileCmd("CA", stats)
for { for {

View File

@ -27,7 +27,7 @@ func main() {
rai := ra.NewRegistrationAuthorityImpl(auditlogger) rai := ra.NewRegistrationAuthorityImpl(auditlogger)
go cmd.ProfileCmd("RA", stats, auditlogger) go cmd.ProfileCmd("RA", stats)
for { for {

View File

@ -31,7 +31,7 @@ func main() {
sai, err := sa.NewSQLStorageAuthority(auditlogger, c.SA.DBDriver, c.SA.DBName) sai, err := sa.NewSQLStorageAuthority(auditlogger, c.SA.DBDriver, c.SA.DBName)
cmd.FailOnError(err, "Failed to create SA impl") cmd.FailOnError(err, "Failed to create SA impl")
go cmd.ProfileCmd("SA", stats, auditlogger) go cmd.ProfileCmd("SA", stats)
for { for {

View File

@ -25,7 +25,7 @@ func main() {
auditlogger, err := blog.Dial(c.Syslog.Network, c.Syslog.Server, c.Syslog.Tag, stats) auditlogger, err := blog.Dial(c.Syslog.Network, c.Syslog.Server, c.Syslog.Tag, stats)
cmd.FailOnError(err, "Could not connect to Syslog") cmd.FailOnError(err, "Could not connect to Syslog")
go cmd.ProfileCmd("VA", stats, auditlogger) go cmd.ProfileCmd("VA", stats)
vai := va.NewValidationAuthorityImpl(auditlogger, c.CA.TestMode) vai := va.NewValidationAuthorityImpl(auditlogger, c.CA.TestMode)

View File

@ -79,7 +79,7 @@ func main() {
wfe.SA = &sac wfe.SA = &sac
wfe.Stats = stats wfe.Stats = stats
go cmd.ProfileCmd("WFE", stats, auditlogger) go cmd.ProfileCmd("WFE", stats)
go func() { go func() {
// sit around and reconnect to AMQP if the channel // sit around and reconnect to AMQP if the channel

View File

@ -65,6 +65,9 @@ func main() {
auditlogger, err := blog.Dial(c.Syslog.Network, c.Syslog.Server, c.Syslog.Tag, stats) auditlogger, err := blog.Dial(c.Syslog.Network, c.Syslog.Server, c.Syslog.Tag, stats)
cmd.FailOnError(err, "Could not connect to Syslog") cmd.FailOnError(err, "Could not connect to Syslog")
// Run StatsD profiling
go cmd.ProfileCmd("Monolith", stats)
// Create the components // Create the components
wfe := wfe.NewWebFrontEndImpl(auditlogger) wfe := wfe.NewWebFrontEndImpl(auditlogger)
sa, err := sa.NewSQLStorageAuthority(auditlogger, c.SA.DBDriver, c.SA.DBName) sa, err := sa.NewSQLStorageAuthority(auditlogger, c.SA.DBDriver, c.SA.DBName)

View File

@ -167,43 +167,22 @@ func RunUntilSignaled(logger *blog.AuditLogger, server *rpc.AmqpRPCServer, close
logger.Warning("Reconnecting to AMQP...") logger.Warning("Reconnecting to AMQP...")
} }
func ProfileCmd(profileName string, stats statsd.Statter, logger *blog.AuditLogger) { func ProfileCmd(profileName string, stats statsd.Statter) {
for { for {
var memoryStats runtime.MemStats var memoryStats runtime.MemStats
runtime.ReadMemStats(&memoryStats) runtime.ReadMemStats(&memoryStats)
if err := stats.Gauge(fmt.Sprintf("Gostats.%s.Goroutines", profileName), int64(runtime.NumGoroutine()), 1.0); err != nil { stats.Gauge(fmt.Sprintf("Gostats.%s.Goroutines", profileName), int64(runtime.NumGoroutine()), 1.0)
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err))
break
}
if err := stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.Objects", profileName), int64(memoryStats.HeapObjects), 1.0); err != nil { stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.Objects", profileName), int64(memoryStats.HeapObjects), 1.0)
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err)) stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.Idle", profileName), int64(memoryStats.HeapIdle), 1.0)
break stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.InUse", profileName), int64(memoryStats.HeapInuse), 1.0)
} stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.Released", profileName), int64(memoryStats.HeapReleased), 1.0)
if err := stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.Idle", profileName), int64(memoryStats.HeapIdle), 1.0); err != nil {
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err))
break
}
if err := stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.InUse", profileName), int64(memoryStats.HeapInuse), 1.0); err != nil {
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err))
break
}
if err := stats.Gauge(fmt.Sprintf("Gostats.%s.Heap.Released", profileName), int64(memoryStats.HeapReleased), 1.0); err != nil {
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err))
break
}
gcPauseAvg := int64(memoryStats.PauseTotalNs) / int64(len(memoryStats.PauseNs)) gcPauseAvg := int64(memoryStats.PauseTotalNs) / int64(len(memoryStats.PauseNs))
if err := stats.Timing(fmt.Sprintf("Gostats.%s.Gc.PauseAvg", profileName), gcPauseAvg, 1.0); err != nil { stats.Timing(fmt.Sprintf("Gostats.%s.Gc.PauseAvg", profileName), gcPauseAvg, 1.0)
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err)) stats.Gauge(fmt.Sprintf("Gostats.%s.Gc.NextAt", profileName), int64(memoryStats.NextGC), 1.0)
break
}
if err := stats.Gauge(fmt.Sprintf("Gostats.%s.Gc.NextAt", profileName), int64(memoryStats.NextGC), 1.0); err != nil {
logger.Warning(fmt.Sprintf("Could not send stats to Statsd server, stopping ProfileCmd: %s", err))
break
}
time.Sleep(time.Second) time.Sleep(time.Second)
} }