Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Apr 27, 2024
1 parent ec14d20 commit caa8634
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ issues:
- text: "don't use ALL_CAPS in Go names; use CamelCase"
linters:
- revive
- text: "exported: type name will be used as pdh.Pdh"
linters:
- revive
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export GOOS=windows
export DOCKER_IMAGE_NAME ?= windows-exporter
export DOCKER_REPO ?= ghcr.io/prometheus-community
export DOCKER_REPO ?= docker.io/prometheuscommunity ghcr.io/prometheus-community ghcr.io/prometheus-community

VERSION?=$(shell cat VERSION)
DOCKER?=docker
Expand Down
8 changes: 5 additions & 3 deletions pkg/collector/perfdata/perfdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ package perfdata
import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand All @@ -13,8 +16,6 @@ import (
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v3"
"strconv"
"strings"
)

const (
Expand Down Expand Up @@ -131,7 +132,8 @@ func (c *collector) Build() error {
return fmt.Errorf("failed to initialize perf data: %w", err)
}

perfCounterInfos, err := c.perfCounters.GetInfo()
var perfCounterInfos map[string]pdh.CounterInfos
perfCounterInfos, err = c.perfCounters.GetInfo()

Check failure on line 136 in pkg/collector/perfdata/perfdata.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

counterInfos, ok := perfCounterInfos["localhost"]
if !ok {
Expand Down
3 changes: 2 additions & 1 deletion pkg/pdh/kernel32.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2010 The win Authors. All rights reserved.
// Copyright (c) 2010-2024 The win Authors. All rights reserved.
// Copyright (c) 2024 The prometheus-community Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down
3 changes: 2 additions & 1 deletion pkg/pdh/pdh.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2010 The win Authors. All rights reserved.
// Copyright (c) 2010-2024 The win Authors. All rights reserved.
// Copyright (c) 2024 The prometheus-community Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down
11 changes: 6 additions & 5 deletions pkg/pdh/pdh_386.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2010 The win Authors. All rights reserved.
// Copyright (c) 2010-2024 The win Authors. All rights reserved.
// Copyright (c) 2024 The prometheus-community Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -39,14 +40,14 @@ type PdhFmtCountervalueDouble struct {
DoubleValue float64
}

// PdhFmtCountervalueLarge is a union specialization for 64-bit integer values
// PdhFmtCounterValueLarge is a union specialization for 64-bit integer values
type PdhFmtCountervalueLarge struct {
CStatus uint32
padding [4]byte //nolint:unused // Memory reservation
LargeValue int64
}

// PdhFmtCountervalueLong is a union specialization for long values
// PdhFmtCounterValueLong is a union specialization for long values
type PdhFmtCountervalueLong struct {
CStatus uint32
LongValue int32
Expand All @@ -59,14 +60,14 @@ type PdhFmtCountervalueItemDouble struct {
FmtValue PdhFmtCountervalueDouble
}

// PdhFmtCountervalueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
// PdhFmtCounterValueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
type PdhFmtCountervalueItemLarge struct {
SzName *uint16 // pointer to a string
padding [4]byte //nolint:unused // Memory reservation
FmtValue PdhFmtCountervalueLarge
}

// PdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
// PdhFmtCounterValueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
type PdhFmtCountervalueItemLong struct {
SzName *uint16 // pointer to a string
padding [4]byte //nolint:unused // Memory reservation
Expand Down
24 changes: 13 additions & 11 deletions pkg/pdh/pdh_amd64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2010 The win Authors. All rights reserved.
// Copyright (c) 2010-2024 The win Authors. All rights reserved.
// Copyright (c) 2024 The prometheus-community Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -38,14 +39,14 @@ type PdhFmtCountervalueDouble struct {
DoubleValue float64
}

// PdhFmtCountervalueLarge is a union specialization for 64-bit integer values
type PdhFmtCountervalueLarge struct {
// PdhFmtCounterValueLarge is a union specialization for 64-bit integer values
type PdhFmtCounterValueLarge struct {
CStatus uint32
LargeValue int64
}

// PdhFmtCountervalueLong is a union specialization for long values
type PdhFmtCountervalueLong struct {
// PdhFmtCounterValueLong is a union specialization for long values
type PdhFmtCounterValueLong struct {
CStatus uint32
LongValue int32
padding [4]byte //nolint:unused // Memory reservation
Expand All @@ -57,16 +58,16 @@ type PdhFmtCountervalueItemDouble struct {
FmtValue PdhFmtCountervalueDouble
}

// PdhFmtCountervalueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
type PdhFmtCountervalueItemLarge struct {
// PdhFmtCounterValueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
type PdhFmtCounterValueItemLarge struct {
SzName *uint16 // pointer to a string
FmtValue PdhFmtCountervalueLarge
FmtValue PdhFmtCounterValueLarge
}

// PdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
type PdhFmtCountervalueItemLong struct {
// PdhFmtCounterValueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
type PdhFmtCounterValueItemLong struct {
SzName *uint16 // pointer to a string
FmtValue PdhFmtCountervalueLong
FmtValue PdhFmtCounterValueLong
}

// PdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
Expand Down Expand Up @@ -132,6 +133,7 @@ type PdhRawCounter struct {
MultiCount uint32
}

//nolint:revive // Windows API names are in PascalCase
type PdhRawCounterItem struct {
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
SzName *uint16
Expand Down
11 changes: 6 additions & 5 deletions pkg/pdh/pdh_arm64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2010 The win Authors. All rights reserved.
// Copyright (c) 2010-2024 The win Authors. All rights reserved.
// Copyright (c) 2024 The prometheus-community Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -38,13 +39,13 @@ type PdhFmtCountervalueDouble struct {
DoubleValue float64
}

// PdhFmtCountervalueLarge is a union specialization for 64-bit integer values
// PdhFmtCounterValueLarge is a union specialization for 64-bit integer values
type PdhFmtCountervalueLarge struct {
CStatus uint32
LargeValue int64
}

// PdhFmtCountervalueLong is a union specialization for long values
// PdhFmtCounterValueLong is a union specialization for long values
type PdhFmtCountervalueLong struct {
CStatus uint32
LongValue int32
Expand All @@ -56,13 +57,13 @@ type PdhFmtCountervalueItemDouble struct {
FmtValue PdhFmtCountervalueDouble
}

// PdhFmtCountervalueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
// PdhFmtCounterValueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
type PdhFmtCountervalueItemLarge struct {
SzName *uint16 // pointer to a string
FmtValue PdhFmtCountervalueLarge
}

// PdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
// PdhFmtCounterValueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
type PdhFmtCountervalueItemLong struct {
SzName *uint16 // pointer to a string
FmtValue PdhFmtCountervalueLong
Expand Down
16 changes: 3 additions & 13 deletions pkg/pdh/win_perf_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
_ "embed"
"errors"
"fmt"
"golang.org/x/sys/windows"
"os"
"strings"
"sync"
"time"

"golang.org/x/sys/windows"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
)
Expand Down Expand Up @@ -173,10 +174,6 @@ func newCounter(
includeTotal bool,
useRawValue bool,
) *counter {
newCounterName := counterName
if useRawValue {
newCounterName += "_Raw"
}
return &counter{counterPath, computer, objectName, counterName, instance, measurement,
includeTotal, useRawValue, counterHandle}
}
Expand Down Expand Up @@ -296,10 +293,6 @@ func (m *WinPerfCounters) AddItem(counterPath, computer, objectName, instance, c
}

hostCounter.counters = append(hostCounter.counters, newItem)

if m.PrintValid {
level.Info(m.Log).Log("msg", fmt.Sprintf("Valid: %s", counterPath))
}
}
} else {
newItem := newCounter(
Expand All @@ -314,9 +307,6 @@ func (m *WinPerfCounters) AddItem(counterPath, computer, objectName, instance, c
useRawValue,
)
hostCounter.counters = append(hostCounter.counters, newItem)
if m.PrintValid {
level.Info(m.Log).Log("msg", fmt.Sprintf("Valid: %s", counterPath))
}
}

return nil
Expand Down Expand Up @@ -528,7 +518,7 @@ func (m *WinPerfCounters) gatherComputerCounters(hostCounterInfo *hostCountersIn
if !isKnownCounterDataError(err) {
return Accumulator{}, fmt.Errorf("error while getting value for counter %q: %w", metric.counterPath, err)
}
level.Warn(m.Log).Log("msg", fmt.Sprintf("Error while getting value for counter %q, instance: %s, will skip metric: %v", metric.counterPath, metric.instance, err))
_ = level.Warn(m.Log).Log("msg", fmt.Sprintf("Error while getting value for counter %q, instance: %s, will skip metric: %v", metric.counterPath, metric.instance, err))
continue
}

Expand Down

0 comments on commit caa8634

Please sign in to comment.