Skip to content

Commit

Permalink
fix(core): Bump dependencies, migrate to promslog
Browse files Browse the repository at this point in the history
  • Loading branch information
pdf committed Jan 18, 2025
1 parent aab14c8 commit ccc2b21
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 183 deletions.
42 changes: 21 additions & 21 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
go:
# Whenever the Go version is updated here,
# .circle/config.yml should also be updated.
version: 1.20
# Whenever the Go version is updated here,
# .circle/config.yml should also be updated.
version: 1.23
repository:
path: github.com/pdf/zfs_exporter/v2
path: github.com/pdf/zfs_exporter/v2
build:
flags: -a -tags netgo
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
flags: -a -tags netgo
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
crossbuild:
platforms:
- linux
- illumos
- darwin
- freebsd
- netbsd
- dragonfly
platforms:
- linux
- illumos
- darwin
- freebsd
- netbsd
- dragonfly
tarball:
files:
- LICENSE
- CHANGELOG.md
files:
- LICENSE
- CHANGELOG.md
32 changes: 23 additions & 9 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ endif
GOTEST := $(GO) test
GOTEST_DIR :=
ifneq ($(CIRCLE_JOB),)
ifneq ($(shell which gotestsum),)
ifneq ($(shell command -v gotestsum 2> /dev/null),)
GOTEST_DIR := test-results
GOTEST := gotestsum --junitfile $(GOTEST_DIR)/unit-tests.xml --
endif
endif

PROMU_VERSION ?= 0.14.0
PROMU_VERSION ?= 0.17.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz

SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.51.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
GOLANGCI_LINT_VERSION ?= v1.63.4
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386 arm64))
# If we're in CI and there is an Actions file, that means the linter
# is being run in Actions, so we don't need to run it here.
ifneq (,$(SKIP_GOLANGCI_LINT))
Expand Down Expand Up @@ -169,16 +169,20 @@ common-vet:
common-lint: $(GOLANGCI_LINT)
ifdef GOLANGCI_LINT
@echo ">> running golangci-lint"
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
# Otherwise staticcheck might fail randomly for some reason not yet explained.
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
endif

.PHONY: common-lint-fix
common-lint-fix: $(GOLANGCI_LINT)
ifdef GOLANGCI_LINT
@echo ">> running golangci-lint fix"
$(GOLANGCI_LINT) run --fix $(GOLANGCI_LINT_OPTS) $(pkgs)
endif

.PHONY: common-yamllint
common-yamllint:
@echo ">> running yamllint on all YAML files in the repository"
ifeq (, $(shell which yamllint))
ifeq (, $(shell command -v yamllint 2> /dev/null))
@echo "yamllint not installed so skipping"
else
yamllint .
Expand All @@ -204,6 +208,10 @@ common-tarball: promu
@echo ">> building release tarball"
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)

.PHONY: common-docker-repo-name
common-docker-repo-name:
@echo "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"

.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
common-docker: $(BUILD_DOCKER_ARCHS)
$(BUILD_DOCKER_ARCHS): common-docker-%:
Expand Down Expand Up @@ -267,3 +275,9 @@ $(1)_precheck:
exit 1; \
fi
endef

govulncheck: install-govulncheck
govulncheck ./...

install-govulncheck:
command -v govulncheck > /dev/null || go install golang.org/x/vuln/cmd/govulncheck@latest
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ go install github.com/pdf/zfs_exporter@$version
```
usage: zfs_exporter [<flags>]
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--collector.dataset-filesystem
Enable the dataset-filesystem collector (default: enabled)
--properties.dataset-filesystem="available,logicalused,quota,referenced,used,usedbydataset,written"
Properties to include for the dataset-filesystem collector, comma-separated.
--collector.dataset-snapshot
Enable the dataset-snapshot collector (default: disabled)
--properties.dataset-snapshot="logicalused,referenced,used,written"
Properties to include for the dataset-snapshot collector, comma-separated.
--collector.dataset-volume
Enable the dataset-volume collector (default: enabled)
--properties.dataset-volume="available,logicalused,referenced,used,usedbydataset,volsize,written"
Properties to include for the dataset-volume collector, comma-separated.
--collector.pool Enable the pool collector (default: enabled)
--properties.pool="allocated,dedupratio,fragmentation,free,freeing,health,leaked,readonly,size"
Properties to include for the pool collector, comma-separated.
--web.listen-address=":9134"
Address on which to expose metrics and web interface.
--web.telemetry-path="/metrics"
Path under which to expose metrics.
--web.disable-exporter-metrics
Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).
--deadline=8s Maximum duration that a collection should run before returning cached data. Should
be set to a value shorter than your scrape timeout duration. The current
collection run will continue and update the cache when complete (default: 8s)
--pool=POOL ... Name of the pool(s) to collect, repeat for multiple pools (default: all pools).
--exclude=EXCLUDE ... Exclude datasets/snapshots/volumes that match the provided regex (e.g.
'^rpool/docker/'), may be specified multiple times.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn,
error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--version Show application version.
-h, --[no-]help Show context-sensitive help (also try --help-long and --help-man).
--[no-]collector.dataset-filesystem
Enable the dataset-filesystem collector (default: enabled)
--properties.dataset-filesystem="available,logicalused,quota,referenced,used,usedbydataset,written"
Properties to include for the dataset-filesystem collector, comma-separated.
--[no-]collector.dataset-snapshot
Enable the dataset-snapshot collector (default: disabled)
--properties.dataset-snapshot="logicalused,referenced,used,written"
Properties to include for the dataset-snapshot collector, comma-separated.
--[no-]collector.dataset-volume
Enable the dataset-volume collector (default: enabled)
--properties.dataset-volume="available,logicalused,referenced,used,usedbydataset,volsize,written"
Properties to include for the dataset-volume collector, comma-separated.
--[no-]collector.pool Enable the pool collector (default: enabled)
--properties.pool="allocated,dedupratio,fragmentation,free,freeing,health,leaked,readonly,size"
Properties to include for the pool collector, comma-separated.
--web.telemetry-path="/metrics"
Path under which to expose metrics.
--[no-]web.disable-exporter-metrics
Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).
--deadline=8s Maximum duration that a collection should run before returning cached data. Should be set to a value shorter than your scrape timeout duration. The current collection run will continue and update the cache when
complete (default: 8s)
--pool=POOL ... Name of the pool(s) to collect, repeat for multiple pools (default: all pools).
--exclude=EXCLUDE ... Exclude datasets/snapshots/volumes that match the provided regex (e.g. '^rpool/docker/'), may be specified multiple times.
--[no-]web.systemd-socket Use systemd socket activation listeners instead of port listeners (Linux only).
--web.listen-address=:9134 ...
Addresses on which to expose metrics and web interface. Repeatable for multiple addresses. Examples: `:9100` or `[::1]:9100` for http, `vsock://:9100` for vsock
--web.config.file="" Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--[no-]version Show application version.
```

Collectors that are enabled by default can be negated by prefixing the flag with `--no-*`, ie:
Expand Down
4 changes: 2 additions & 2 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package collector
import (
"errors"
"fmt"
"log/slog"
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/pdf/zfs_exporter/v2/zfs"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -46,7 +46,7 @@ var (
errUnsupportedProperty = errors.New(`unsupported property`)
)

type factoryFunc func(l log.Logger, c zfs.Client, properties []string) (Collector, error)
type factoryFunc func(l *slog.Logger, c zfs.Client, properties []string) (Collector, error)

type transformFunc func(string) (float64, error)

Expand Down
8 changes: 3 additions & 5 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ package collector
import (
"bytes"
"context"
"io"
"log/slog"
"time"

"github.com/go-kit/log"
"github.com/pdf/zfs_exporter/v2/zfs"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)

var (
logger = log.NewNopLogger()
//logger = log.NewLogfmtLogger(os.Stderr)
)
var logger = slog.New(slog.NewTextHandler(io.Discard, nil))

func callCollector(ctx context.Context, collector prometheus.Collector, metricResults []byte, metricNames []string) error {
result := make(chan error)
Expand Down
17 changes: 8 additions & 9 deletions collector/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package collector

import (
"fmt"
"log/slog"
"sync"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pdf/zfs_exporter/v2/zfs"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -167,7 +166,7 @@ func init() {

type datasetCollector struct {
kind zfs.DatasetKind
log log.Logger
log *slog.Logger
client zfs.Client
props []string
}
Expand All @@ -176,7 +175,7 @@ func (c *datasetCollector) describe(ch chan<- *prometheus.Desc) {
for _, k := range c.props {
prop, err := datasetProperties.find(k)
if err != nil {
_ = level.Warn(c.log).Log(`msg`, propertyUnsupportedMsg, `help`, helpIssue, `collector`, c.kind, `property`, k, `err`, err)
c.log.Warn(propertyUnsupportedMsg, `help`, helpIssue, `collector`, c.kind, `property`, k, `err`, err)
continue
}
ch <- prop.desc
Expand Down Expand Up @@ -230,7 +229,7 @@ func (c *datasetCollector) updateDatasetMetrics(ch chan<- metric, pool string, d
for k, v := range dataset.Properties() {
prop, err := datasetProperties.find(k)
if err != nil {
_ = level.Warn(c.log).Log(`msg`, propertyUnsupportedMsg, `help`, helpIssue, `collector`, c.kind, `property`, k, `err`, err)
c.log.Warn(propertyUnsupportedMsg, `help`, helpIssue, `collector`, c.kind, `property`, k, `err`, err)
}
if err = prop.push(ch, v, labelValues...); err != nil {
return err
Expand All @@ -240,7 +239,7 @@ func (c *datasetCollector) updateDatasetMetrics(ch chan<- metric, pool string, d
return nil
}

func newDatasetCollector(kind zfs.DatasetKind, l log.Logger, c zfs.Client, props []string) (Collector, error) {
func newDatasetCollector(kind zfs.DatasetKind, l *slog.Logger, c zfs.Client, props []string) (Collector, error) {
switch kind {
case zfs.DatasetFilesystem, zfs.DatasetSnapshot, zfs.DatasetVolume:
default:
Expand All @@ -250,14 +249,14 @@ func newDatasetCollector(kind zfs.DatasetKind, l log.Logger, c zfs.Client, props
return &datasetCollector{kind: kind, log: l, client: c, props: props}, nil
}

func newFilesystemCollector(l log.Logger, c zfs.Client, props []string) (Collector, error) {
func newFilesystemCollector(l *slog.Logger, c zfs.Client, props []string) (Collector, error) {
return newDatasetCollector(zfs.DatasetFilesystem, l, c, props)
}

func newSnapshotCollector(l log.Logger, c zfs.Client, props []string) (Collector, error) {
func newSnapshotCollector(l *slog.Logger, c zfs.Client, props []string) (Collector, error) {
return newDatasetCollector(zfs.DatasetSnapshot, l, c, props)
}

func newVolumeCollector(l log.Logger, c zfs.Client, props []string) (Collector, error) {
func newVolumeCollector(l *slog.Logger, c zfs.Client, props []string) (Collector, error) {
return newDatasetCollector(zfs.DatasetVolume, l, c, props)
}
11 changes: 5 additions & 6 deletions collector/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package collector

import (
"fmt"
"log/slog"
"sync"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pdf/zfs_exporter/v2/zfs"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -114,7 +113,7 @@ func init() {
}

type poolCollector struct {
log log.Logger
log *slog.Logger
client zfs.Client
props []string
}
Expand All @@ -123,7 +122,7 @@ func (c *poolCollector) describe(ch chan<- *prometheus.Desc) {
for _, k := range c.props {
prop, err := poolProperties.find(k)
if err != nil {
_ = level.Warn(c.log).Log(`msg`, propertyUnsupportedMsg, `help`, helpIssue, `collector`, `pool`, `property`, k, `err`, err)
c.log.Warn(propertyUnsupportedMsg, `help`, helpIssue, `collector`, `pool`, `property`, k, `err`, err)
continue
}
ch <- prop.desc
Expand Down Expand Up @@ -163,7 +162,7 @@ func (c *poolCollector) updatePoolMetrics(ch chan<- metric, pool string) error {
for k, v := range props.Properties() {
prop, err := poolProperties.find(k)
if err != nil {
_ = level.Warn(c.log).Log(`msg`, propertyUnsupportedMsg, `help`, helpIssue, `collector`, `pool`, `property`, k, `err`, err)
c.log.Warn(propertyUnsupportedMsg, `help`, helpIssue, `collector`, `pool`, `property`, k, `err`, err)
}
if err = prop.push(ch, v, labelValues...); err != nil {
return err
Expand All @@ -173,6 +172,6 @@ func (c *poolCollector) updatePoolMetrics(ch chan<- metric, pool string) error {
return nil
}

func newPoolCollector(l log.Logger, c zfs.Client, props []string) (Collector, error) {
func newPoolCollector(l *slog.Logger, c zfs.Client, props []string) (Collector, error) {
return &poolCollector{log: l, client: c, props: props}, nil
}
Loading

0 comments on commit ccc2b21

Please sign in to comment.