From 5c518531be64eb3ded5575b31e8cb69f1ed3704f Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 30 Apr 2017 12:35:07 +1000 Subject: [PATCH] Integrate StackImpact profiling --- irc/config.go | 11 +++++++++++ oragono.go | 16 ++++++++++++++++ oragono.yaml | 19 ++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/irc/config.go b/irc/config.go index 8e370ee1..7af7532c 100644 --- a/irc/config.go +++ b/irc/config.go @@ -173,6 +173,13 @@ func (sts *STSConfig) Value() string { return val } +// StackImpactConfig is the config used for StackImpact's profiling. +type StackImpactConfig struct { + Enabled bool + AgentKey string `yaml:"agent-key"` + AppName string `yaml:"app-name"` +} + // Config defines the overall configuration. type Config struct { Network struct { @@ -215,6 +222,10 @@ type Config struct { Logging []LoggingConfig + Debug struct { + StackImpact StackImpactConfig + } + Limits struct { AwayLen uint `yaml:"awaylen"` ChanListModes uint `yaml:"chan-list-modes"` diff --git a/oragono.go b/oragono.go index 3b691629..a19b2e4f 100644 --- a/oragono.go +++ b/oragono.go @@ -16,6 +16,7 @@ import ( "github.com/DanielOaks/oragono/irc/logger" "github.com/DanielOaks/oragono/mkcerts" "github.com/docopt/docopt-go" + stackimpact "github.com/stackimpact/stackimpact-go" "golang.org/x/crypto/ssh/terminal" ) @@ -107,6 +108,21 @@ Options: if !arguments["--quiet"].(bool) { logger.Info("startup", fmt.Sprintf("Oragono v%s starting", irc.SemVer)) } + + // profiling + if config.Debug.StackImpact.Enabled { + if config.Debug.StackImpact.AgentKey == "" || config.Debug.StackImpact.AppName == "" { + logger.Error("startup", "Could not start StackImpact - agent-key or app-name are undefined") + return + } + + agent := stackimpact.NewAgent() + agent.Start(stackimpact.Options{AgentKey: config.Debug.StackImpact.AgentKey, AppName: config.Debug.StackImpact.AppName}) + defer agent.RecordPanic() + + logger.Info("startup", fmt.Sprintf("StackImpact profiling started as %s", config.Debug.StackImpact.AppName)) + } + server, err := irc.NewServer(configfile, config, logger) if err != nil { logger.Error("startup", fmt.Sprintf("Could not load server: %s", err.Error())) diff --git a/oragono.yaml b/oragono.yaml index b3a760bf..80d4cdc0 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -26,7 +26,7 @@ server: ":6697": key: tls.key cert: tls.crt - + # strict transport security, to get clients to automagically use TLS sts: # whether to advertise STS @@ -74,7 +74,7 @@ server: # whether to throttle limits or not enabled: true - # how wide the cidr should be for IPv4 + # how wide the cidr should be for IPv4 cidr-len-ipv4: 24 # how wide the cidr should be for IPv6 @@ -94,7 +94,7 @@ server: # whether to throttle connections or not enabled: true - # how wide the cidr should be for IPv4 + # how wide the cidr should be for IPv4 cidr-len-ipv4: 32 # how wide the cidr should be for IPv6 @@ -236,6 +236,19 @@ logging: type: localconnect localconnect-ip level: debug +# debug options +debug: + # enabling StackImpact profiling + stackimpact: + # whether to use StackImpact + enabled: false + + # the AgentKey to use + agent-key: examplekeyhere + + # the app name to report + app-name: Oragono + # datastore configuration datastore: # path to the datastore