From 7cc3d96a4110f055785e803444aca89c2bcd66d6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 27 Feb 2021 01:01:47 +0200 Subject: [PATCH] lib/fs: follow-up after f3a03c416408bf7d81dee438a10566428962c5ee --- .github/workflows/main.yml | 1 + app/vmagent/Makefile | 4 ---- docs/CHANGELOG.md | 1 + lib/fs/fs.go | 3 ++- lib/fs/fs_nix.go | 18 ------------------ lib/fs/fs_openbsd.go | 18 ------------------ lib/fs/fs_unix.go | 20 +++++++++++++++++--- lib/fs/fs_windows.go | 7 ++----- lib/fs/reader_at.go | 2 +- 9 files changed, 24 insertions(+), 50 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2fcfe52aa..63e9846b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,6 +58,7 @@ jobs: GOOS=darwin go build -mod=vendor ./app/vmbackup GOOS=darwin go build -mod=vendor ./app/vmrestore GOOS=darwin go build -mod=vendor ./app/vmctl + CGO_ENABLED=0 GOOS=windows go build -mod=vendor ./app/vmagent - name: Publish coverage uses: codecov/codecov-action@v1.0.6 with: diff --git a/app/vmagent/Makefile b/app/vmagent/Makefile index e0be998ab..0ee29504d 100644 --- a/app/vmagent/Makefile +++ b/app/vmagent/Makefile @@ -73,10 +73,6 @@ vmagent-ppc64le: vmagent-386: CGO_ENABLED=0 GOARCH=386 $(MAKE) vmagent-local-with-goarch -vmagent-windows: - GOOS=windows CGO_ENABLED=0 $(MAKE) vmagent-local-with-goarch - - vmagent-local-with-goarch: APP_NAME=vmagent $(MAKE) app-local-with-goarch diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8ae0db448..edd86ee81 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,7 @@ * FEATURE: vmagent: optimize [relabeling](https://victoriametrics.github.io/vmagent.html#relabeling) performance for common cases. * FEATURE: add `increase_pure(m[d])` function to MetricsQL. It works the same as `increase(m[d])` except of various edge cases. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962) for details. * FEATURE: increase accuracy for `buckets_limit(limit, buckets)` results for small `limit` values. See [MetricsQL docs](https://victoriametrics.github.io/MetricsQL.html) for details. +* FEATURE: vmagent: initial support for Windows build with `CGO_ENABLED=0 GOOS=windows go build -mod=vendor ./app/vmagent`. See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1036). * BUGFIX: vmagent: properly perform graceful shutdown on `SIGINT` and `SIGTERM` signals. The graceful shutdown has been broken in `v1.54.0`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1065 * BUGFIX: reduce the probability of `duplicate time series` errors when querying Kubernetes metrics. diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 8f8c65943..f417f8257 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -321,7 +321,8 @@ func MustWriteData(w io.Writer, data []byte) { // CreateFlockFile creates flock.lock file in the directory dir // and returns the handler to the file. func CreateFlockFile(dir string) (*os.File, error) { - return createFlockFile(dir) + flockFile := dir + "/flock.lock" + return createFlockFile(flockFile) } // MustGetFreeSpace returns free space for the given directory path. diff --git a/lib/fs/fs_nix.go b/lib/fs/fs_nix.go index df7c51fef..32df8e641 100644 --- a/lib/fs/fs_nix.go +++ b/lib/fs/fs_nix.go @@ -3,27 +3,9 @@ package fs import ( - "os" - - "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "golang.org/x/sys/unix" ) -func mustGetFreeSpace(path string) uint64 { - d, err := os.Open(path) - if err != nil { - logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) - } - defer MustClose(d) - - fd := d.Fd() - var stat unix.Statfs_t - if err := unix.Fstatfs(int(fd), &stat); err != nil { - logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) - } - return freeSpace(stat) -} - func freeSpace(stat unix.Statfs_t) uint64 { return uint64(stat.Bavail) * uint64(stat.Bsize) } diff --git a/lib/fs/fs_openbsd.go b/lib/fs/fs_openbsd.go index 9d48a9ee1..1ab4b9358 100644 --- a/lib/fs/fs_openbsd.go +++ b/lib/fs/fs_openbsd.go @@ -1,27 +1,9 @@ package fs import ( - "os" - - "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "golang.org/x/sys/unix" ) -func mustGetFreeSpace(path string) uint64 { - d, err := os.Open(path) - if err != nil { - logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) - } - defer MustClose(d) - - fd := d.Fd() - var stat unix.Statfs_t - if err := unix.Fstatfs(int(fd), &stat); err != nil { - logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) - } - return freeSpace(stat) -} - func freeSpace(stat unix.Statfs_t) uint64 { return uint64(stat.F_bavail) * uint64(stat.F_bsize) } diff --git a/lib/fs/fs_unix.go b/lib/fs/fs_unix.go index ceb27d3a3..11df30c8b 100644 --- a/lib/fs/fs_unix.go +++ b/lib/fs/fs_unix.go @@ -10,7 +10,7 @@ import ( "golang.org/x/sys/unix" ) -func mmap(fd int, offset int64, length int) (data []byte, err error) { +func mmap(fd int, length int) (data []byte, err error) { return unix.Mmap(fd, 0, length, unix.PROT_READ, unix.MAP_SHARED) } @@ -32,8 +32,7 @@ func mustSyncPath(path string) { } } -func createFlockFile(dir string) (*os.File, error) { - flockFile := dir + "/flock.lock" +func createFlockFile(flockFile string) (*os.File, error) { flockF, err := os.Create(flockFile) if err != nil { return nil, fmt.Errorf("cannot create lock file %q: %w", flockFile, err) @@ -43,3 +42,18 @@ func createFlockFile(dir string) (*os.File, error) { } return flockF, nil } + +func mustGetFreeSpace(path string) uint64 { + d, err := os.Open(path) + if err != nil { + logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) + } + defer MustClose(d) + + fd := d.Fd() + var stat unix.Statfs_t + if err := unix.Fstatfs(int(fd), &stat); err != nil { + logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) + } + return freeSpace(stat) +} diff --git a/lib/fs/fs_windows.go b/lib/fs/fs_windows.go index e92e3391f..a64748cc2 100644 --- a/lib/fs/fs_windows.go +++ b/lib/fs/fs_windows.go @@ -33,11 +33,8 @@ const ( fileDispositionIgnoreReadonlyAttribute = 0x00000010 ) -// createFlockFile creates flock.lock file in the directory dir -// and returns the handler to the file. // https://github.com/juju/fslock/blob/master/fslock_windows.go -func createFlockFile(dir string) (*os.File, error) { - flockFile := dir + "/flock.lock" +func createFlockFile(flockFile string) (*os.File, error) { name, err := windows.UTF16PtrFromString(flockFile) if err != nil { return nil, err @@ -67,7 +64,7 @@ func createFlockFile(dir string) (*os.File, error) { } // stub -func mmap(fd int, offset int64, length int) ([]byte, error) { +func mmap(fd int, length int) ([]byte, error) { return nil, nil } diff --git a/lib/fs/reader_at.go b/lib/fs/reader_at.go index 13850695c..53ccb44c3 100644 --- a/lib/fs/reader_at.go +++ b/lib/fs/reader_at.go @@ -134,7 +134,7 @@ func mmapFile(f *os.File, size int64) ([]byte, error) { if size%4096 != 0 { size += 4096 - size%4096 } - data, err := mmap(int(f.Fd()), 0, int(size)) + data, err := mmap(int(f.Fd()), int(size)) if err != nil { return nil, fmt.Errorf("cannot mmap file with size %d: %w", size, err) }