FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

zfs: fix dataset name parsing by vigneshakaviki · Pull Request #3768 · prometheus/node_exporter · GitHub

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion collector/zfs_linux.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ func (c *zfsCollector) parsePoolObjsetFile(reader io.Reader, zpoolPath string, h
zpoolPathElements := strings.Split(zpoolPath, "/")
pathLen := len(zpoolPathElements)
zpoolName = zpoolPathElements[pathLen-2]
datasetName = line[strings.Index(line, parts[2]):]
dataStart := strings.Index(line, parts[1]) + len(parts[1])
datasetName = strings.TrimSpace(line[dataStart:])
continue
}

Expand Down
17 changes: 17 additions & 0 deletions collector/zfs_linux_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package collector
import (
"os"
"path/filepath"
"strings"
"testing"
)

Expand Down Expand Up @@ -363,6 +364,22 @@ func TestZpoolObjsetParsingWithSpace(t *testing.T) {
}
}

func TestZpoolObjsetParsingDatasetInFieldName(t *testing.T) {
const input = "name type data\ndataset_name 7 data\nnwritten 4 1\n"

c := zfsCollector{}
var datasetName string
err := c.parsePoolObjsetFile(strings.NewReader(input), "/proc/spl/kstat/zfs/data/objset-1", func(_ string, dataset string, _ zfsSysctl, _ uint64) {
datasetName = dataset
})
if err != nil {
t.Fatal(err)
}
if datasetName != "data" {
t.Fatalf("Incorrectly parsed dataset name: expected: %q, got: %q", "data", datasetName)
}
}

func TestZpoolObjsetParsing(t *testing.T) {
zpoolPaths, err := filepath.Glob("fixtures/proc/spl/kstat/zfs/*/objset-*")
if err != nil {
Expand Down

Back | FazBrowse Home | New Git URL