Skip to content

Commit

Permalink
Moving the config to the livedebugging block
Browse files Browse the repository at this point in the history
Remove config from docs
  • Loading branch information
ravishankar15 committed Dec 18, 2024
1 parent dac428d commit 574403a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 66 deletions.
1 change: 0 additions & 1 deletion docs/sources/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ The following flags are supported:
* `--server.http.memory-addr`: Address to listen for [in-memory HTTP traffic][] on (default `alloy.internal:12345`).
* `--server.http.listen-addr`: Address to listen for HTTP traffic on (default `127.0.0.1:12345`).
* `--server.http.ui-path-prefix`: Base path where the UI is exposed (default `/`).
* `--server.http.live-debugging-buffer-stream-size`: Buffer stream size used for buffering the live debugging entries (default `1000`)
* `--storage.path`: Base directory where components can store data (default `data-alloy/`).
* `--disable-reporting`: Disable [data collection][] (default `false`).
* `--disable-support-bundle`: Disable [support bundle][] endpoint (default `false`).
Expand Down
7 changes: 4 additions & 3 deletions docs/sources/reference/config-blocks/livedebugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ livedebugging {

The following arguments are supported:

| Name | Type | Description | Default | Required |
| --------- | ------ | ----------------------------------- | ------- | -------- |
| `enabled` | `bool` | Enables the live debugging feature. | `false` | no |
| Name | Type | Description | Default | Required |
| -------------------- | ----- | --------------------------------------------------------------- | ------- | -------- |
| `enabled` | `bool`| Enables the live debugging feature. | `false` | no |
| `buffer_stream_size` | `int` | Buffer stream size used for buffering the live debugging entries | 1000 | no |

[debug]: ../../../troubleshoot/debug/
86 changes: 41 additions & 45 deletions internal/alloycli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ import (

func runCommand() *cobra.Command {
r := &alloyRun{
inMemoryAddr: "alloy.internal:12345",
httpListenAddr: "127.0.0.1:12345",
storagePath: "data-alloy/",
minStability: featuregate.StabilityGenerallyAvailable,
uiPrefix: "/",
disableReporting: false,
enablePprof: true,
configFormat: "alloy",
clusterAdvInterfaces: advertise.DefaultInterfaces,
clusterMaxJoinPeers: 5,
clusterRejoinInterval: 60 * time.Second,
disableSupportBundle: false,
liveDebuggingBufferStreamSize: 1000,
inMemoryAddr: "alloy.internal:12345",
httpListenAddr: "127.0.0.1:12345",
storagePath: "data-alloy/",
minStability: featuregate.StabilityGenerallyAvailable,
uiPrefix: "/",
disableReporting: false,
enablePprof: true,
configFormat: "alloy",
clusterAdvInterfaces: advertise.DefaultInterfaces,
clusterMaxJoinPeers: 5,
clusterRejoinInterval: 60 * time.Second,
disableSupportBundle: false,
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -114,8 +113,6 @@ depending on the nature of the reload error.
BoolVar(&r.enablePprof, "server.http.enable-pprof", r.enablePprof, "Enable /debug/pprof profiling endpoints.")
cmd.Flags().
BoolVar(&r.disableSupportBundle, "server.http.disable-support-bundle", r.disableSupportBundle, "Disable /-/support support bundle retrieval.")
cmd.Flags().
IntVar(&r.liveDebuggingBufferStreamSize, "server.http.live-debugging-buffer-stream-size", r.liveDebuggingBufferStreamSize, "Buffer stream size used for buffering the live debugging entries")

// Cluster flags
cmd.Flags().
Expand Down Expand Up @@ -164,33 +161,32 @@ depending on the nature of the reload error.
}

type alloyRun struct {
inMemoryAddr string
httpListenAddr string
storagePath string
minStability featuregate.Stability
uiPrefix string
enablePprof bool
disableReporting bool
clusterEnabled bool
clusterNodeName string
clusterAdvAddr string
clusterJoinAddr string
clusterDiscoverPeers string
clusterAdvInterfaces []string
clusterRejoinInterval time.Duration
clusterMaxJoinPeers int
clusterName string
clusterEnableTLS bool
clusterTLSCAPath string
clusterTLSCertPath string
clusterTLSKeyPath string
clusterTLSServerName string
configFormat string
configBypassConversionErrors bool
configExtraArgs string
enableCommunityComps bool
disableSupportBundle bool
liveDebuggingBufferStreamSize int
inMemoryAddr string
httpListenAddr string
storagePath string
minStability featuregate.Stability
uiPrefix string
enablePprof bool
disableReporting bool
clusterEnabled bool
clusterNodeName string
clusterAdvAddr string
clusterJoinAddr string
clusterDiscoverPeers string
clusterAdvInterfaces []string
clusterRejoinInterval time.Duration
clusterMaxJoinPeers int
clusterName string
clusterEnableTLS bool
clusterTLSCAPath string
clusterTLSCertPath string
clusterTLSKeyPath string
clusterTLSServerName string
configFormat string
configBypassConversionErrors bool
configExtraArgs string
enableCommunityComps bool
disableSupportBundle bool
}

func (fr *alloyRun) Run(cmd *cobra.Command, configPath string) error {
Expand Down Expand Up @@ -320,9 +316,9 @@ func (fr *alloyRun) Run(cmd *cobra.Command, configPath string) error {
liveDebuggingService := livedebugging.New()

uiService := uiservice.New(uiservice.Options{
UIPrefix: fr.uiPrefix,
CallbackManager: liveDebuggingService.Data().(livedebugging.CallbackManager),
LiveDebuggingBufferStreamSize: fr.liveDebuggingBufferStreamSize,
UIPrefix: fr.uiPrefix,
CallbackManager: liveDebuggingService.Data().(livedebugging.CallbackManager),
LiveDebuggingConfig: liveDebuggingService.Data().(livedebugging.ConfigViewer),
})

otelService := otel_service.New(l)
Expand Down
28 changes: 24 additions & 4 deletions internal/service/livedebugging/livedebugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ type DebugDataPublisher interface {
IsActive(componentID ComponentID) bool
}

// ConfigViewer is used by components to access the configs of the live debugging
type ConfigViewer interface {
// returns the buffer stream size used by the UI service
GetBufferStreamSize() int
}

type liveDebugging struct {
loadMut sync.RWMutex
callbacks map[ComponentID]map[CallbackID]func(string)
host service.Host
enabled bool
loadMut sync.RWMutex
callbacks map[ComponentID]map[CallbackID]func(string)
host service.Host
enabled bool
bufferStreamSize int
}

var _ CallbackManager = &liveDebugging{}
var _ DebugDataPublisher = &liveDebugging{}
var _ ConfigViewer = &liveDebugging{}

// NewLiveDebugging creates a new instance of liveDebugging.
func NewLiveDebugging() *liveDebugging {
Expand Down Expand Up @@ -131,3 +139,15 @@ func (s *liveDebugging) SetEnabled(enabled bool) {
defer s.loadMut.Unlock()
s.enabled = enabled
}

func (s *liveDebugging) SetBufferStreamSize(size int) {
s.loadMut.Lock()
defer s.loadMut.Unlock()
s.bufferStreamSize = size
}

func (s *liveDebugging) GetBufferStreamSize() int {
s.loadMut.RLock()
defer s.loadMut.RUnlock()
return s.bufferStreamSize
}
12 changes: 11 additions & 1 deletion internal/service/livedebugging/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ func New() *Service {
}

type Arguments struct {
Enabled bool `alloy:"enabled,attr,optional"`
Enabled bool `alloy:"enabled,attr,optional"`
BufferStreamSize int `alloy:"buffer_stream_size,attr,optional"`
}

// SetToDefault implements syntax.Defaulter.
func (args *Arguments) SetToDefault() {
*args = Arguments{
Enabled: false,
BufferStreamSize: 1000,
}
}

// Data implements service.Service.
Expand Down Expand Up @@ -54,5 +63,6 @@ func (s *Service) Run(ctx context.Context, host service.Host) error {
func (s *Service) Update(args any) error {
newArgs := args.(Arguments)
s.liveDebugging.SetEnabled(newArgs.Enabled)
s.liveDebugging.SetBufferStreamSize(newArgs.BufferStreamSize)
return nil
}
8 changes: 4 additions & 4 deletions internal/service/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const ServiceName = "ui"
// Options are used to configure the UI service. Options are constant for the
// lifetime of the UI service.
type Options struct {
UIPrefix string // Path prefix to host the UI at.
CallbackManager livedebugging.CallbackManager // CallbackManager is used for live debugging in the UI.
LiveDebuggingBufferStreamSize int // Buffer size for the live debugging stream channel
UIPrefix string // Path prefix to host the UI at.
CallbackManager livedebugging.CallbackManager // CallbackManager is used for live debugging in the UI.
LiveDebuggingConfig livedebugging.ConfigViewer // ConfigViewer is used to access the configs of liveDebugging
}

// Service implements the UI service.
Expand Down Expand Up @@ -79,7 +79,7 @@ func (s *Service) Data() any {
func (s *Service) ServiceHandler(host service.Host) (base string, handler http.Handler) {
r := mux.NewRouter()

fa := api.NewAlloyAPI(host, s.opts.CallbackManager, s.opts.LiveDebuggingBufferStreamSize)
fa := api.NewAlloyAPI(host, s.opts.CallbackManager, s.opts.LiveDebuggingConfig)
fa.RegisterRoutes(path.Join(s.opts.UIPrefix, "/api/v0/web"), r)
ui.RegisterRoutes(s.opts.UIPrefix, r)

Expand Down
16 changes: 8 additions & 8 deletions internal/web/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (

// AlloyAPI is a wrapper around the component API.
type AlloyAPI struct {
alloy service.Host
CallbackManager livedebugging.CallbackManager
liveDebuggingBufferStreamSize int
alloy service.Host
CallbackManager livedebugging.CallbackManager
LiveDebuggingConfig livedebugging.ConfigViewer
}

// NewAlloyAPI instantiates a new Alloy API.
func NewAlloyAPI(alloy service.Host, CallbackManager livedebugging.CallbackManager, liveDebuggingBufferStreamSize int) *AlloyAPI {
return &AlloyAPI{alloy: alloy, CallbackManager: CallbackManager, liveDebuggingBufferStreamSize: liveDebuggingBufferStreamSize}
func NewAlloyAPI(alloy service.Host, CallbackManager livedebugging.CallbackManager, LiveDebuggingConfig livedebugging.ConfigViewer) *AlloyAPI {
return &AlloyAPI{alloy: alloy, CallbackManager: CallbackManager, LiveDebuggingConfig: LiveDebuggingConfig}
}

// RegisterRoutes registers all the API's routes.
Expand All @@ -51,7 +51,7 @@ func (a *AlloyAPI) RegisterRoutes(urlPrefix string, r *mux.Router) {
r.Handle(path.Join(urlPrefix, "/remotecfg/components/{id:.+}"), httputil.CompressionHandler{Handler: getComponentHandlerRemoteCfg(a.alloy)})

r.Handle(path.Join(urlPrefix, "/peers"), httputil.CompressionHandler{Handler: getClusteringPeersHandler(a.alloy)})
r.Handle(path.Join(urlPrefix, "/debug/{id:.+}"), liveDebugging(a.alloy, a.CallbackManager, a.liveDebuggingBufferStreamSize))
r.Handle(path.Join(urlPrefix, "/debug/{id:.+}"), liveDebugging(a.alloy, a.CallbackManager, a.LiveDebuggingConfig))
}

func listComponentsHandler(host service.Host) http.HandlerFunc {
Expand Down Expand Up @@ -167,12 +167,12 @@ func getClusteringPeersHandler(host service.Host) http.HandlerFunc {
}
}

func liveDebugging(_ service.Host, callbackManager livedebugging.CallbackManager, liveDebuggingBufferStreamSize int) http.HandlerFunc {
func liveDebugging(_ service.Host, callbackManager livedebugging.CallbackManager, LiveDebuggingConfig livedebugging.ConfigViewer) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
componentID := livedebugging.ComponentID(vars["id"])

dataCh := make(chan string, liveDebuggingBufferStreamSize)
dataCh := make(chan string, LiveDebuggingConfig.GetBufferStreamSize())
ctx := r.Context()

sampleProb := setSampleProb(w, r.URL.Query().Get("sampleProb"))
Expand Down

0 comments on commit 574403a

Please sign in to comment.