Merge pull request #10 from apcera/monitor

Config file support for monitor http port
This commit is contained in:
Derek Collison
2013-07-30 18:37:21 -07:00
6 changed files with 20 additions and 9 deletions

View File

@@ -93,7 +93,6 @@ func (lx *lexer) nextItem() item {
lx.state = lx.state(lx)
}
}
panic("not reached")
}
func lex(input string) *lexer {

View File

@@ -7,6 +7,7 @@ import (
"log"
"net/http"
_ "net/http/pprof"
"os"
"strings"
"github.com/apcera/gnatsd/server"
@@ -69,7 +70,8 @@ func main() {
if configFile != "" {
fileOpts, err = server.ProcessConfigFile(configFile)
if err != nil {
panic(err)
log.Printf("%v\n", err)
os.Exit(1)
}
}
@@ -87,7 +89,7 @@ func main() {
s.StartRouting()
}
// Profiler
// Pprof http endpoint for the profiler.
go func() {
log.Println(http.ListenAndServe("localhost:6062", nil))
}()

View File

@@ -4,6 +4,8 @@
port: 4242
net: apcera.me # net interface
http_port: 8222
authorization {
user: derek
password: bella

View File

@@ -82,6 +82,8 @@ func ProcessConfigFile(configFile string) (*Options, error) {
opts.Username = auth.user
opts.Password = auth.pass
opts.AuthTimeout = auth.timeout
case "http_port", "monitor_port":
opts.HttpPort = int(v.(int64))
case "cluster":
cm := v.(map[string]interface{})
if err := parseCluster(cm, opts); err != nil {

View File

@@ -39,6 +39,7 @@ func TestConfigFile(t *testing.T) {
Debug: false,
Trace: true,
Logtime: false,
HttpPort: 8222,
}
opts, err := ProcessConfigFile("./configs/test.conf")
@@ -47,7 +48,8 @@ func TestConfigFile(t *testing.T) {
}
if !reflect.DeepEqual(golden, opts) {
t.Fatal("Options are incorrect from config file")
t.Fatalf("Options are incorrect.\nexpected: %+v\ngot: %+v",
golden, opts)
}
}
@@ -61,6 +63,7 @@ func TestMergeOverrides(t *testing.T) {
Debug: true,
Trace: true,
Logtime: false,
HttpPort: DEFAULT_HTTP_PORT,
}
fopts, err := ProcessConfigFile("./configs/test.conf")
if err != nil {
@@ -69,12 +72,15 @@ func TestMergeOverrides(t *testing.T) {
// Overrides via flags
opts := &Options{
Port: 2222,
Password: "spooky",
Debug: true,
Port: 2222,
Password: "spooky",
Debug: true,
HttpPort: DEFAULT_HTTP_PORT,
}
merged := MergeOptions(fopts, opts)
if !reflect.DeepEqual(golden, merged) {
t.Fatal("Options are incorrect from config file")
t.Fatalf("Options are incorrect.\nexpected: %+v\ngot: %+v",
golden, merged)
}
}

View File

@@ -34,7 +34,7 @@ func TestRouteConfig(t *testing.T) {
golden.Routes = []*url.URL{r1, r2}
if !reflect.DeepEqual(golden, opts) {
t.Fatalf("Options are incorrect from config file.\nexpected: %+v\ngot: %+v",
t.Fatalf("Options are incorrect.\nexpected: %+v\ngot: %+v",
golden, opts)
}
}