Skip to content

Commit

Permalink
fix memory leak from global MeterProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Aug 29, 2024
1 parent 90c6cfd commit b42f8d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"github.com/coreos/go-systemd/v22/daemon"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric/noop"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
jsonpatch "gopkg.in/evanphx/json-patch.v4"
Expand Down Expand Up @@ -121,6 +123,9 @@ import (

func init() {
utilruntime.Must(logsapi.AddFeatureGates(utilfeature.DefaultMutableFeatureGate))
// Prevent memory leak from OTel metrics, which we don't use:
// https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5190
otel.SetMeterProvider(noop.NewMeterProvider())
}

const (
Expand Down
8 changes: 8 additions & 0 deletions staging/src/k8s.io/apiserver/pkg/server/options/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"net"

"github.com/spf13/pflag"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/semconv/v1.12.0"
"google.golang.org/grpc"
Expand All @@ -48,6 +50,12 @@ var (
codecs = serializer.NewCodecFactory(cfgScheme)
)

func init() {
// Prevent memory leak from OTel metrics, which we don't use:
// https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5190
otel.SetMeterProvider(noop.NewMeterProvider())
}

func init() {
install.Install(cfgScheme)
}
Expand Down

0 comments on commit b42f8d3

Please sign in to comment.