Skip to content

Commit

Permalink
Merge pull request moby#49210 from thaJeztah/internalize_fd_count
Browse files Browse the repository at this point in the history
pkg/fileutils: move GetTotalUsedFds internal in daemon
  • Loading branch information
thaJeztah authored Jan 3, 2025
2 parents b7ae700 + a51baca commit 7b95ccc
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 56 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ issues:
path: "api/types/(volume|container)/"
linters:
- revive
# FIXME temporarily suppress these until we migrated these to internal.
- text: "SA1019: fileutils\\.GetTotalUsedFds"
linters:
- staticcheck
# FIXME temporarily suppress these (see https://github.com/gotestyourself/gotest.tools/issues/272)
- text: "SA1019: (assert|cmp|is)\\.ErrorType is deprecated"
linters:
Expand Down
4 changes: 2 additions & 2 deletions daemon/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/cmd/dockerd/debug"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/daemon/internal/filedescriptors"
"github.com/docker/docker/daemon/logger"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/internal/platform"
"github.com/docker/docker/pkg/fileutils"
"github.com/docker/docker/pkg/meminfo"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/pkg/parsers/operatingsystem"
Expand Down Expand Up @@ -225,7 +225,7 @@ func (daemon *Daemon) fillContainerStates(v *system.Info) {
// https://github.com/docker/cli/blob/v20.10.12/cli/command/system/info.go#L239-L244
func (daemon *Daemon) fillDebugInfo(ctx context.Context, v *system.Info) {
v.Debug = debug.IsEnabled()
v.NFd = fileutils.GetTotalUsedFds(ctx)
v.NFd = filedescriptors.GetTotalUsedFds(ctx)
v.NGoroutines = runtime.NumGoroutine()
v.NEventsListener = daemon.EventsService.SubscribersCount()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fileutils
package filedescriptors

import (
"context"
Expand All @@ -13,8 +13,6 @@ import (

// GetTotalUsedFds Returns the number of used File Descriptors by
// reading it via /proc filesystem.
//
// Deprecated: this function is only used internally, and will be removed in the next release.
func GetTotalUsedFds(ctx context.Context) int {
ctx, span := tracing.StartSpan(ctx, "GetTotalUsedFds")
defer span.End()
Expand Down
14 changes: 14 additions & 0 deletions daemon/internal/filedescriptors/filiedescriptors_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package filedescriptors

import (
"context"
"testing"
)

func BenchmarkGetTotalUsedFds(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = GetTotalUsedFds(ctx)
}
}
11 changes: 11 additions & 0 deletions daemon/internal/filedescriptors/filiedescriptors_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !linux

package filedescriptors

import "context"

// GetTotalUsedFds Returns the number of used File Descriptors. Not supported
// on Windows.
func GetTotalUsedFds(context.Context) int {
return -1
}
27 changes: 0 additions & 27 deletions pkg/fileutils/fileutils_darwin.go

This file was deleted.

9 changes: 0 additions & 9 deletions pkg/fileutils/fileutils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fileutils // import "github.com/docker/docker/pkg/fileutils"

import (
"context"
"errors"
"os"
"path"
Expand Down Expand Up @@ -241,11 +240,3 @@ func TestCreateIfNotExistsFile(t *testing.T) {
t.Errorf("Should have been a file, seems it's not")
}
}

func BenchmarkGetTotalUsedFds(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = GetTotalUsedFds(ctx)
}
}
11 changes: 0 additions & 11 deletions pkg/fileutils/fileutils_windows.go

This file was deleted.

0 comments on commit 7b95ccc

Please sign in to comment.