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

fix: Prevent the constant logging of cgroup errors on non-linux machines #2264

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Main (unreleased)

### Bugfixes

- Fixed issue with automemlimit logging bad messages and trying to access cgroup on non-linux builds (@dehaansa)

- Fixed issue with reloading configuration and prometheus metrics duplication in `prometheus.write.queue`. (@mattdurham)

- Updated `prometheus.write.queue` to fix issue with TTL comparing different scales of time. (@mattdurham)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/Azure/go-autorest/autorest v0.11.29
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/IBM/sarama v1.43.3
github.com/KimMachineGun/automemlimit v0.6.0
github.com/KimMachineGun/automemlimit v0.6.1
github.com/Lusitaniae/apache_exporter v0.11.1-0.20220518131644-f9522724dab4
github.com/Masterminds/sprig/v3 v3.2.3
github.com/PuerkitoBio/rehttp v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,8 @@ github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H
github.com/Jeffail/gabs v1.1.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c h1:RGWPOewvKIROun94nF7v2cua9qP+thov/7M50KEoeSU=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/KimMachineGun/automemlimit v0.6.0 h1:p/BXkH+K40Hax+PuWWPQ478hPjsp9h1CPDhLlA3Z37E=
github.com/KimMachineGun/automemlimit v0.6.0/go.mod h1:T7xYht7B8r6AG/AqFcUdc7fzd2bIdBKmepfP2S1svPY=
github.com/KimMachineGun/automemlimit v0.6.1 h1:ILa9j1onAAMadBsyyUJv5cack8Y1WT26yLj/V+ulKp8=
github.com/KimMachineGun/automemlimit v0.6.1/go.mod h1:T7xYht7B8r6AG/AqFcUdc7fzd2bIdBKmepfP2S1svPY=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Lusitaniae/apache_exporter v0.11.1-0.20220518131644-f9522724dab4 h1:UEm6tMvLH2t2honcWG0q+h0qr/60++9cuh/fy7hLyMc=
github.com/Lusitaniae/apache_exporter v0.11.1-0.20220518131644-f9522724dab4/go.mod h1:IfUbHkoXypdKnVGHWQ3DLRRRZzIU/JIExQAd9xgxRfw=
Expand Down
25 changes: 25 additions & 0 deletions internal/alloycli/automemlimit_cgroups_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !linux
// +build !linux
ptodev marked this conversation as resolved.
Show resolved Hide resolved

package alloycli

import (
"log/slog"
"os"
"slices"
"strings"

"github.com/KimMachineGun/automemlimit/memlimit"
"github.com/grafana/alloy/internal/runtime/logging"
)

func applyAutoMemLimit(l *logging.Logger) {
// For non-linux builds without cgroups, memlimit will always report an error.
// However, if the system experiment is requested, we can use the system memory limit provider.
// This logic is similar to https://github.com/KimMachineGun/automemlimit/blob/main/memlimit/experiment.go
if v, ok := os.LookupEnv("AUTOMEMLIMIT_EXPERIMENT"); ok {
ptodev marked this conversation as resolved.
Show resolved Hide resolved
if slices.Contains(strings.Split(v, ","), "system") {
memlimit.SetGoMemLimitWithOpts(memlimit.WithProvider(memlimit.FromSystem), memlimit.WithLogger(slog.New(l.Handler())))
ptodev marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
12 changes: 12 additions & 0 deletions internal/alloycli/automemlimit_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package alloycli
ptodev marked this conversation as resolved.
Show resolved Hide resolved

import (
"log/slog"

"github.com/KimMachineGun/automemlimit/memlimit"
"github.com/grafana/alloy/internal/runtime/logging"
)

func applyAutoMemLimit(l *logging.Logger) {
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.New(l.Handler())))
}
6 changes: 2 additions & 4 deletions internal/alloycli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"os/signal"
"path/filepath"
Expand All @@ -16,7 +15,6 @@ import (
"syscall"
"time"

"github.com/KimMachineGun/automemlimit/memlimit"
"github.com/fatih/color"
"github.com/go-kit/log"
"github.com/grafana/ckit/advertise"
Expand Down Expand Up @@ -221,8 +219,8 @@ func (fr *alloyRun) Run(cmd *cobra.Command, configPath string) error {
level.Info(l).Log("boringcrypto enabled", boringcrypto.Enabled)

// Set the memory limit, this will honor GOMEMLIMIT if set
// If there is a cgroup will follow that
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.New(l.Handler())))
// If there is a cgroup on linux it will use that
applyAutoMemLimit(l)

// Enable the profiling.
setMutexBlockProfiling(l)
Expand Down
Loading