Skip to content

Commit

Permalink
wip: clean up some log messages and fix lifecycle server port init
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorris committed Jun 6, 2023
1 parent bb0f87a commit cde897a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
15 changes: 4 additions & 11 deletions pkg/consuldp/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
// defaultLifecycleBindPort is the port which will serve the proxy lifecycle HTTP
// endpoints on the loopback interface.
defaultLifecycleBindPort = "20300"
cdpLifecycleBindAddr = "127.0.0.1:" + defaultLifecycleBindPort
cdpLifecycleBindAddr = "127.0.0.1"
cdpLifecycleUrl = "http://" + cdpLifecycleBindAddr
)

Expand Down Expand Up @@ -105,7 +105,7 @@ func (m *lifecycleConfig) startLifecycleManager(ctx context.Context, bcfg *boots
cdpLifecycleBindPort = strconv.Itoa(m.gracefulPort)
}
m.lifecycleServer = &http.Server{
Addr: cdpLifecycleBindAddr + cdpLifecycleBindPort,
Addr: fmt.Sprintf("%s:%s", cdpLifecycleBindAddr, cdpLifecycleBindPort),
Handler: mux,
}

Expand Down Expand Up @@ -134,21 +134,14 @@ func (m *lifecycleConfig) stopLifecycleServer() {
var errs error

if m.lifecycleServer != nil {
m.logger.Info("stopping the merged server")
err := m.lifecycleServer.Close()
if err != nil {
m.logger.Warn("error while closing lifecycle server", "error", err)
errs = multierror.Append(err, errs)
}
}
if m.lifecycleServer != nil {
m.logger.Info("stopping consul dp promtheus server")
m.logger.Info("stopping the lifecycle management server")
err := m.lifecycleServer.Close()
if err != nil {
m.logger.Warn("error while closing lifecycle server", "error", err)
errs = multierror.Append(err, errs)
}
}

// Check if there were errors and then close the error channel
if errs != nil {
close(m.errorExitCh)
Expand Down
38 changes: 19 additions & 19 deletions pkg/consuldp/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// "fmt"
// "io"
"log"
// "net"
"net"
"net/http"
// "strings"
"sync"
Expand Down Expand Up @@ -102,26 +102,26 @@ func TestLifecycleServerEnabled(t *testing.T) {
require.NoError(t, err)
// require.Equal(t, c.bindAddr, m.promScrapeServer.Addr)

// Have consul-dataplane's metrics server start on an open port.
// And figure out what port was used so we can make requests to it.
// Have consul-dataplane's lifecycle server start on an open port
// and figure out what port was used so we can make requests to it.
// Conveniently, this seems to wait until the server is ready for requests.
/*
portCh := make(chan int, 1)
m.promScrapeServer.Addr = "127.0.0.1:0"
m.promScrapeServer.BaseContext = func(l net.Listener) context.Context {
portCh <- l.Addr().(*net.TCPAddr).Port
return context.Background()
}
var port int
select {
case port = <-portCh:
case <-time.After(5 * time.Second):
}
require.NotEqual(t, port, 0, "test failed to figure out metrics server port")
log.Printf("port = %v", port)
portCh := make(chan int, 1)
m.lifecycleServer.Addr = "127.0.0.1:0"
m.lifecycleServer.BaseContext = func(l net.Listener) context.Context {
portCh <- l.Addr().(*net.TCPAddr).Port
return context.Background()
}

var port int
select {
case port = <-portCh:
case <-time.After(5 * time.Second):
}

require.NotEqual(t, port, 0, "test failed to figure out lifecycle server port")
log.Printf("port = %v", port)

/*
url := fmt.Sprintf("http://127.0.0.1:%d/stats/prometheus", port)
resp, err := http.Get(url)
require.NoError(t, err)
Expand Down

0 comments on commit cde897a

Please sign in to comment.