Skip to content

Commit

Permalink
Remove the config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishankar15 committed Dec 20, 2024
1 parent 62c8855 commit a039988
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 52 deletions.
1 change: 0 additions & 1 deletion docs/sources/reference/config-blocks/livedebugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ The following arguments are supported:
| 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/
5 changes: 2 additions & 3 deletions internal/alloycli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ 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),
LiveDebuggingConfig: liveDebuggingService.Data().(livedebugging.ConfigViewer),
UIPrefix: fr.uiPrefix,
CallbackManager: liveDebuggingService.Data().(livedebugging.CallbackManager),
})

otelService := otel_service.New(l)
Expand Down
1 change: 0 additions & 1 deletion internal/component/loki/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ func getServiceDataWithLiveDebugging(log *testlivedebugging.Log) func(string) (i
}
ld.SetServiceHost(host)
ld.SetEnabled(true)
ld.SetBufferStreamSize(1000)
ld.AddCallback(
"callback1",
"",
Expand Down
28 changes: 4 additions & 24 deletions internal/service/livedebugging/livedebugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,15 @@ 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
bufferStreamSize int
loadMut sync.RWMutex
callbacks map[ComponentID]map[CallbackID]func(string)
host service.Host
enabled bool
}

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

// NewLiveDebugging creates a new instance of liveDebugging.
func NewLiveDebugging() *liveDebugging {
Expand Down Expand Up @@ -139,15 +131,3 @@ 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: 1 addition & 11 deletions internal/service/livedebugging/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ func New() *Service {
}

type Arguments struct {
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,
}
Enabled bool `alloy:"enabled,attr,optional"`
}

// Data implements service.Service.
Expand Down Expand Up @@ -63,6 +54,5 @@ 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
}
7 changes: 3 additions & 4 deletions internal/service/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ 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.
LiveDebuggingConfig livedebugging.ConfigViewer // ConfigViewer is used to access the configs of liveDebugging
UIPrefix string // Path prefix to host the UI at.
CallbackManager livedebugging.CallbackManager // CallbackManager is used for live debugging in the UI.
}

// Service implements the UI service.
Expand Down Expand Up @@ -79,7 +78,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.LiveDebuggingConfig)
fa := api.NewAlloyAPI(host, s.opts.CallbackManager)
fa.RegisterRoutes(path.Join(s.opts.UIPrefix, "/api/v0/web"), r)
ui.RegisterRoutes(s.opts.UIPrefix, r)

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

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

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

// RegisterRoutes registers all the API's routes.
Expand All @@ -51,7 +50,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.LiveDebuggingConfig))
r.Handle(path.Join(urlPrefix, "/debug/{id:.+}"), liveDebugging(a.alloy, a.CallbackManager))
}

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

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

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

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

0 comments on commit a039988

Please sign in to comment.