Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance optimization for live debugging feature #2294

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 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,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/
12 changes: 6 additions & 6 deletions internal/component/loki/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -62,7 +62,7 @@ func TestJSONLabelsStage(t *testing.T) {
source = "extra"
}
stage.labels {
values = {
values = {
stream = "",
user = "",
ts = "timestamp",
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestLeakyUpdate(t *testing.T) {
numLogsToSend := 1

cfg1 := `
stage.metrics {
stage.metrics {
metric.counter {
name = "paulin_test1"
action = "inc"
Expand All @@ -688,7 +688,7 @@ func TestLeakyUpdate(t *testing.T) {
}` + forwardArgs

cfg2 := `
stage.metrics {
stage.metrics {
metric.counter {
name = "paulin_test2"
action = "inc"
Expand Down Expand Up @@ -731,7 +731,7 @@ func TestMetricsStageRefresh(t *testing.T) {
numLogsToSend := 3

cfgWithMetric := `
stage.metrics {
stage.metrics {
metric.counter {
name = "paulin_test"
action = "inc"
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions internal/web/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"strconv"
"strings"
"time"

"github.com/google/uuid"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Loading