Skip to content

Commit

Permalink
Merge pull request #14 from cloudstruct/feature/debug-endpoint
Browse files Browse the repository at this point in the history
feat: optional debug endpoint
  • Loading branch information
agaffney authored May 2, 2022
2 parents 964d4d1 + 38f7bb3 commit 184ea38
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/cardano-submit-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/cloudstruct/go-cardano-submit-api/internal/api"
"github.com/cloudstruct/go-cardano-submit-api/internal/config"
"github.com/cloudstruct/go-cardano-submit-api/internal/logging"
"net/http"
_ "net/http/pprof"
"os"
)

Expand Down Expand Up @@ -36,6 +38,17 @@ func main() {
}
}()

// Start debug listener
if cfg.Debug.ListenPort > 0 {
logger.Infof("starting debug listener on %s:%d", cfg.Debug.ListenAddress, cfg.Debug.ListenPort)
go func() {
err := http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Debug.ListenAddress, cfg.Debug.ListenPort), nil)
if err != nil {
logger.Fatalf("failed to start debug listener: %s", err)
}
}()
}

// Start API listener
logger.Infof("starting API listener on %s:%d", cfg.Api.ListenAddress, cfg.Api.ListenPort)
if err := api.Start(cfg); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ api:
# This can also be set via the API_LISTEN_PORT environment variable
port: 8090

# The debug endpoint provides access to pprof for debugging purposes. This is
# disabled by default, but it can be enabled by setting the port to a non-zero
# value
debug:
# Listen address for the debug endpoint
#
# This can also be set via the DEBUG_ADDRESS environment variable
address: localhost

# Listen port for the debug endpoint
#
# This can also be set via the DEBUG_PORT environment variable
port: 0

node:
# Path to UNIX socket file for cardano-node
#
Expand Down
10 changes: 10 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
type Config struct {
Logging LoggingConfig `yaml:"logging"`
Api ApiConfig `yaml:"api"`
Debug DebugConfig `yaml:"debug"`
Node NodeConfig `yaml:"node"`
}

Expand All @@ -28,6 +29,11 @@ type ApiConfig struct {
ListenPort uint `yaml:"port" envconfig:"API_LISTEN_PORT"`
}

type DebugConfig struct {
ListenAddress string `yaml:"address" envconfig:"DEBUG_ADDRESS"`
ListenPort uint `yaml:"port" envconfig:"DEBUG_PORT"`
}

type NodeConfig struct {
Network string `yaml:"network" envconfig:"NETWORK"`
NetworkMagic uint32 `yaml:"networkMagic" envconfig:"CARDANO_NODE_NETWORK_MAGIC"`
Expand All @@ -45,6 +51,10 @@ var globalConfig = &Config{
ListenAddress: "",
ListenPort: 8090,
},
Debug: DebugConfig{
ListenAddress: "localhost",
ListenPort: 0,
},
Node: NodeConfig{
Network: "mainnet",
SocketPath: "/node-ipc/node.socket",
Expand Down

0 comments on commit 184ea38

Please sign in to comment.