diff --git a/CHANGELOG.md b/CHANGELOG.md index 8279c67197..e47e5ede53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Main (unreleased) - Add three new stdlib functions to_base64, from_URLbase64 and to_URLbase64 (@ravishankar15) - Add `ignore_older_than` option for local.file_match (@ravishankar15) - Add livedebugging support for `discover.relabel` (@ravishankar15) +- Performance optimization for live debugging feature (@ravishankar15) - Use a forked `github.com/goccy/go-json` module which reduces the memory consumption of an Alloy instance by 20MB. If Alloy is running certain otelcol components, this reduction will not apply. (@ptodev) diff --git a/docs/sources/reference/config-blocks/livedebugging.md b/docs/sources/reference/config-blocks/livedebugging.md index 4587d95117..af30cb4f2e 100644 --- a/docs/sources/reference/config-blocks/livedebugging.md +++ b/docs/sources/reference/config-blocks/livedebugging.md @@ -30,8 +30,8 @@ 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 | [debug]: ../../../troubleshoot/debug/ diff --git a/internal/component/loki/process/process_test.go b/internal/component/loki/process/process_test.go index 30a035124d..7558b0fc6c 100644 --- a/internal/component/loki/process/process_test.go +++ b/internal/component/loki/process/process_test.go @@ -53,7 +53,7 @@ func TestJSONLabelsStage(t *testing.T) { // The third stage will set some labels from the extracted values above. // Again, if the value is empty, it is inferred that we want to use the // populate the label with extracted value of the same name. - stg := `stage.json { + stg := `stage.json { expressions = {"output" = "log", stream = "stream", timestamp = "time", "extra" = "" } drop_malformed = true } @@ -62,7 +62,7 @@ func TestJSONLabelsStage(t *testing.T) { source = "extra" } stage.labels { - values = { + values = { stream = "", user = "", ts = "timestamp", @@ -679,7 +679,7 @@ func TestLeakyUpdate(t *testing.T) { numLogsToSend := 1 cfg1 := ` - stage.metrics { + stage.metrics { metric.counter { name = "paulin_test1" action = "inc" @@ -688,7 +688,7 @@ func TestLeakyUpdate(t *testing.T) { }` + forwardArgs cfg2 := ` - stage.metrics { + stage.metrics { metric.counter { name = "paulin_test2" action = "inc" @@ -731,7 +731,7 @@ func TestMetricsStageRefresh(t *testing.T) { numLogsToSend := 3 cfgWithMetric := ` - stage.metrics { + stage.metrics { metric.counter { name = "paulin_test" action = "inc" @@ -776,7 +776,7 @@ func TestMetricsStageRefresh(t *testing.T) { // We try having a metric with the same name as before so that we can see if there // is some sort of double registration error for that metric. cfgWithTwoMetrics := ` - stage.metrics { + stage.metrics { metric.counter { name = "paulin_test_3" action = "inc" diff --git a/internal/web/api/api.go b/internal/web/api/api.go index 53592b744a..5164f91854 100644 --- a/internal/web/api/api.go +++ b/internal/web/api/api.go @@ -11,6 +11,7 @@ import ( "path" "strconv" "strings" + "time" "github.com/google/uuid" "github.com/gorilla/mux" @@ -165,13 +166,11 @@ func getClusteringPeersHandler(host service.Host) http.HandlerFunc { } } -func liveDebugging(host service.Host, callbackManager livedebugging.CallbackManager) 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"]) - // Buffer of 1000 entries to handle load spikes and prevent this functionality from eating up too much memory. - // TODO: in the future we may want to make this value configurable to handle heavy load dataCh := make(chan string, 1000) ctx := r.Context() @@ -200,9 +199,12 @@ func liveDebugging(host service.Host, callbackManager livedebugging.CallbackMana return } + flushTicker := time.NewTicker(time.Second) + defer func() { close(dataCh) callbackManager.DeleteCallback(id, componentID) + flushTicker.Stop() }() for { @@ -216,7 +218,7 @@ func liveDebugging(host service.Host, callbackManager livedebugging.CallbackMana if writeErr != nil { return } - // TODO: flushing at a regular interval might be better performance wise + case <-flushTicker.C: w.(http.Flusher).Flush() case <-ctx.Done(): return