Merge pull request #892 from mjtrangoni/fix-golanci-lint

Fix and update golanci-lint reported issues
This commit is contained in:
Ben Reedy
2021-12-25 10:34:02 +10:00
committed by GitHub
55 changed files with 79 additions and 37 deletions

View File

@@ -3,11 +3,10 @@ linters:
enable:
- deadcode
- errcheck
- golint
- revive
- govet
- gofmt
- ineffassign
- interfacer
- structcheck
- unconvert
- varcheck
@@ -20,4 +19,7 @@ issues:
- # Golint has many capitalisation complaints on WMI class names
text: "`?\\w+`? should be `?\\w+`?"
linters:
- golint
- revive
- text: "don't use ALL_CAPS in Go names; use CamelCase"
linters:
- revive

View File

@@ -15,9 +15,9 @@ install:
- set PATH=%PATH%;C:\msys64\mingw64\bin
- choco install gitversion.portable make -y
- ps: |
appveyor DownloadFile https://github.com/golangci/golangci-lint/releases/download/v1.21.0/golangci-lint-1.21.0-windows-amd64.zip
Expand-Archive golangci-lint-1.21.0-windows-amd64.zip
Move-Item golangci-lint-1.21.0-windows-amd64\golangci-lint-1.21.0-windows-amd64\golangci-lint.exe $env:GOPATH\bin\golangci-lint.exe
appveyor DownloadFile https://github.com/golangci/golangci-lint/releases/download/v1.43.0/golangci-lint-1.43.0-windows-amd64.zip
Expand-Archive golangci-lint-1.43.0-windows-amd64.zip
Move-Item golangci-lint-1.43.0-windows-amd64\golangci-lint-1.43.0-windows-amd64\golangci-lint.exe $env:GOPATH\bin\golangci-lint.exe
- go install github.com/prometheus/promu@v0.11.1
- go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.2.0

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -55,6 +55,6 @@ func benchmarkCollector(b *testing.B, name string, collectFunc func() (Collector
}()
for i := 0; i < b.N; i++ {
c.Collect(scrapeContext, metrics)
c.Collect(scrapeContext, metrics) //nolint:errcheck
}
}

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -128,7 +129,7 @@ func NewDFSRCollector() (Collector, error) {
ConnectionFilesReceivedTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "connection_received_files_total"),
"Total number of files receieved for connection",
"Total number of files received for connection",
[]string{"name"},
nil,
),

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -136,7 +137,7 @@ func NewDNSCollector() (Collector, error) {
),
Responses: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "responses_total"),
"Number of reponses sent by DNS server",
"Number of responses sent by DNS server",
[]string{"protocol"},
nil,
),

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -234,7 +235,7 @@ func (c *exchangeCollector) collectADAccessProcesses(ctx *ScrapeContext, ch chan
}
// since we're not including the PID suffix from the instance names in the label names,
// we get an occational duplicate. This seems to affect about 4 instances only on this object.
// we get an occasional duplicate. This seems to affect about 4 instances only on this object.
labelUseCount[labelName]++
if labelUseCount[labelName] > 1 {
labelName = fmt.Sprintf("%s_%d", labelName, labelUseCount[labelName])

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -1274,13 +1275,13 @@ type perflibW3SVC_W3WP struct {
URICacheFlushesTotal float64 `perflib:"Total Flushed URIs"`
URICacheFlushesTotalKernel float64 `perflib:"Total Flushed URIs"`
URIsFlushedTotalKernel float64 `perflib:"Kernel\: Total Flushed URIs"`
URIsFlushedTotalKernel float64 `perflib:"Kernel\: Total Flushed URIs"` //nolint:govet
URICacheHitsTotal float64 `perflib:"URI Cache Hits"`
URICacheHitsTotalKernel float64 `perflib:"Kernel\: URI Cache Hits"`
URICacheHitsTotalKernel float64 `perflib:"Kernel\: URI Cache Hits"` //nolint:govet
URICacheMissesTotal float64 `perflib:"URI Cache Misses"`
URICacheMissesTotalKernel float64 `perflib:"Kernel\: URI Cache Misses"`
URICacheMissesTotalKernel float64 `perflib:"Kernel\: URI Cache Misses"` //nolint:govet
URIsCached float64 `perflib:"Current URIs Cached"`
URIsCachedKernel float64 `perflib:"Kernel\: Current URIs Cached"`
URIsCachedKernel float64 `perflib:"Kernel\: Current URIs Cached"` //nolint:govet
URIsCachedTotal float64 `perflib:"Total URIs Cached"`
URIsCachedTotalKernel float64 `perflib:"Total URIs Cached"`
URIsFlushedTotal float64 `perflib:"Total Flushed URIs"`

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,6 +1,7 @@
// returns data points from Win32_PerfRawData_PerfOS_Memory
// <add link to documentation here> - Win32_PerfRawData_PerfOS_Memory class
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -1957,7 +1958,7 @@ func (c *MSSQLCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric
}
wg.Wait()
// this shoud return an error if any? some? children errord.
// this should return an error if any? some? children errord.
if c.mssqlChildCollectorFailure > 0 {
return errors.New("at least one child collector failed")
}

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -201,7 +202,7 @@ func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (
return nil, err
}
var fsipf float64 = 0
var fsipf float64
for _, pagingFile := range pagingFiles {
fileString := strings.ReplaceAll(pagingFile, `\??\`, "")
file, err := os.Stat(fileString)
@@ -222,7 +223,7 @@ func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (
}
// Get current page file usage.
var pfbRaw float64 = 0
var pfbRaw float64
for _, pageFile := range pfc {
if strings.Contains(strings.ToLower(pageFile.Name), "_total") {
continue
@@ -302,7 +303,7 @@ func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (
ch <- prometheus.MustNewConstMetric(
c.PagingLimitBytes,
prometheus.GaugeValue,
float64(fsipf),
fsipf,
)
ch <- prometheus.MustNewConstMetric(

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -133,7 +134,7 @@ func newProcessCollector() (Collector, error) {
),
WorkingSetPrivate: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "working_set_private_bytes"),
"Size of the working set, in bytes, that is use for this process only and not shared nor sharable by other processes.",
"Size of the working set, in bytes, that is use for this process only and not shared nor shareable by other processes.",
[]string{"process", "process_id", "creating_process_id"},
nil,
),

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -60,7 +61,7 @@ func NewRemoteFx() (Collector, error) {
),
CurrentTCPBandwidth: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "net_current_tcp_bandwidth"),
"TCP Bandwidth detected in bytes per seccond.",
"TCP Bandwidth detected in bytes per second.",
[]string{"session_name"},
nil,
),

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector
@@ -231,7 +232,7 @@ func (c *serviceCollector) collectAPI(ch chan<- prometheus.Metric) error {
if err != nil {
return err
}
defer svcmgrConnection.Disconnect()
defer svcmgrConnection.Disconnect() //nolint:errcheck
// List All Services from the Services Manager
serviceList, err := svcmgrConnection.ListServices()

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !notextfile
// +build !notextfile
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package collector

View File

@@ -44,7 +44,7 @@ Name | Description | Type | Labels
`windows_dfsr_folder_deleted_bytes_cleaned_up_total` | Total size (in bytes) of replicating deleted files and folders that were cleaned up from the Conflict and Deleted folder. | gauge | name
`windows_dfsr_folder_deleted_bytes_generated_total` | Total size (in bytes) of replicated deleted files and folders that were moved to the Conflict and Deleted folder after they were deleted from a replicated folder on a sending member. | counter | name
`windows_dfsr_folder_deleted_files_cleaned_up_total` | Number of files and folders that were cleaned up from the Conflict and Deleted folder. | counter | name
`windows_dfsr_folder_deleted_files_generated_total` | Number of deleted fils and folders that were moved to the Conflict and Deleted folder. | counter | name
`windows_dfsr_folder_deleted_files_generated_total` | Number of deleted files and folders that were moved to the Conflict and Deleted folder. | counter | name
`windows_dfsr_folder_file_installs_retried_total` | Total number of file installs that are being retried due to sharing violations or other errors encountered when installing the files. The DFS Replication service replicates staged files into a staging folder, uncompresses them in the Installing folder, and renames them to the target location. The second and third steps of this process are known as installing the file. | counter | name
`windows_dfsr_folder_file_installs_succeeded_total` | Total number of files that were successfully received from sending members and installed locally on this server. The DFS Replication service replicates staged files into a staging folder, uncompresses them in the Installing folder, and renames them to the target location. The second and third steps of this process are known as installing the file. | counter | name
`windows_dfsr_folder_files_received_total` | Total number of files received. | counter | name

View File

@@ -36,7 +36,7 @@ Name | Description
`windows_exchange_transport_queues_internal_active_remote_delivery` | Internal Active Remote Delivery Queue length
`windows_exchange_transport_queues_active_mailbox_delivery` | Active Mailbox Delivery Queue length
`windows_exchange_transport_queues_retry_mailbox_delivery` | Retry Mailbox Delivery Queue length
`windows_exchange_transport_queues_unreachable` | Unreachable Queue lengt
`windows_exchange_transport_queues_unreachable` | Unreachable Queue length
`windows_exchange_transport_queues_external_largest_delivery` | External Largest Delivery Queue length
`windows_exchange_transport_queues_internal_largest_delivery` | Internal Largest Delivery Queue length
`windows_exchange_transport_queues_poison` | Poison Queue length

View File

@@ -1,6 +1,6 @@
# Microsoft File Server Resource Manager (FSRM) Quotas collector
The fsrmquota collector exposes metrics about File Server Ressource Manager Quotas. Note that this collector has only been tested against Windows server 2012R2.
The fsrmquota collector exposes metrics about File Server Resource Manager Quotas. Note that this collector has only been tested against Windows server 2012R2.
Other FSRM versions may work but are not tested.
|||
@@ -48,5 +48,5 @@ rate(windows_fsrmquota_usage_bytes)[1d]
severity: "high"
annotations:
summary: "High Quotas Usage"
description: "High use of File Ressource.\n Quotas: {{ $labels.path }}\n Current use : {{ $value }}"
description: "High use of File Resource.\n Quotas: {{ $labels.path }}\n Current use : {{ $value }}"
```

View File

@@ -17,7 +17,7 @@ None
Name | Description | Type | Labels
-----|-------------|------|-------
`windows_os_info` | Contains full product name & version in labels | gauge | `product`, `version`
`windows_os_paging_limit_bytes` | Total number of bytes that can be sotred in the operating system paging files. 0 (zero) indicates that there are no paging files | gauge | None
`windows_os_paging_limit_bytes` | Total number of bytes that can be stored in the operating system paging files. 0 (zero) indicates that there are no paging files | gauge | None
`windows_os_paging_free_bytes` | Number of bytes that can be mapped into the operating system paging files without causing any other pages to be swapped out | gauge | None
`windows_os_physical_memory_free_bytes` | Bytes of physical memory currently unused and available | gauge | None
`windows_os_time` | Current time as reported by the operating system, in [Unix time](https://en.wikipedia.org/wiki/Unix_time). See [time.Unix()](https://golang.org/pkg/time/#Unix) for details | gauge | None

View File

@@ -53,7 +53,7 @@ Name | Description | Type | Labels
`windows_process_private_bytes` | Current number of bytes this process has allocated that cannot be shared with other processes. | gauge | `process`, `process_id`, `creating_process_id`
`windows_process_thread_count` | Number of threads currently active in this process. An instruction is the basic unit of execution in a processor, and a thread is the object that executes instructions. Every running process has at least one thread. | gauge | `process`, `process_id`, `creating_process_id`
`windows_process_virtual_bytes` | Current size, in bytes, of the virtual address space that the process is using. Use of virtual address space does not necessarily imply corresponding use of either disk or main memory pages. Virtual space is finite and, by using too much, the process can limit its ability to load libraries. | gauge | `process`, `process_id`, `creating_process_id`
`windows_process_working_set_private_bytes` | Size of the working set, in bytes, that is use for this process only and not shared nor sharable by other processes. | gauge | `process`, `process_id`, `creating_process_id`
`windows_process_working_set_private_bytes` | Size of the working set, in bytes, that is use for this process only and not shared nor shareable by other processes. | gauge | `process`, `process_id`, `creating_process_id`
`windows_process_working_set_peak_bytes` | Maximum size, in bytes, of the Working Set of this process at any point in time. The Working Set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the Working Set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from Working Sets. If they are needed they will then be soft-faulted back into the Working Set before they leave main memory. | gauge | `process`, `process_id`, `creating_process_id`
`windows_process_working_set_bytes` | Maximum number of bytes in the working set of this process at any point in time. The working set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the working set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from working sets. If they are needed, they are then soft-faulted back into the working set before they leave main memory. | gauge | `process`, `process_id`, `creating_process_id`

View File

@@ -24,7 +24,7 @@ If given, a virtual SMTP server needs to *not* match the blacklist regexp in ord
Name | Description | Type | Labels
-----|-------------|------|-------
`windows_smtp_badmailed_messages_bad_pickup_file_total` | Total number of mailformed pickup messages sent to badmail | counter | `server`
`windows_smtp_badmailed_messages_bad_pickup_file_total` | Total number of malformed pickup messages sent to badmail | counter | `server`
`windows_smtp_badmailed_messages_general_failure_total` | Total number of messages sent to badmail for reasons not associated with a specific counter | counter | `server`
`windows_smtp_badmailed_messages_hop_count_exceeded_total` | Total number of messages sent to badmail because they had exceeded the maximum hop count | counter | `server`
`windows_smtp_badmailed_messages_ndr_of_dns_total` | Total number of Delivery Status Notifications sent to badmail because they could not be delivered | counter | `server`

View File

@@ -259,7 +259,7 @@ func main() {
var (
configFile = kingpin.Flag(
"config.file",
"YAML configuration file to use. Values set in this file will be overriden by CLI flags.",
"YAML configuration file to use. Values set in this file will be overridden by CLI flags.",
).String()
webConfig = webflag.AddFlags(kingpin.CommandLine)
listenAddress = kingpin.Flag(
@@ -504,7 +504,7 @@ func (mh *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Warnln("Couldn't create filtered metrics handler: ", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err)))
w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) //nolint:errcheck
return
}
reg.MustRegister(wc)

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package main

View File

@@ -69,7 +69,7 @@ var NetApiStatus = map[uint32]string{
// NetApiBufferFree frees the memory other network management functions use internally to return information.
// https://docs.microsoft.com/en-us/windows/win32/api/lmapibuf/nf-lmapibuf-netapibufferfree
func netApiBufferFree(buffer *wKSTAInfo102) {
procNetApiBufferFree.Call(uintptr(unsafe.Pointer(buffer)))
procNetApiBufferFree.Call(uintptr(unsafe.Pointer(buffer))) //nolint:errcheck
}
// NetWkstaGetInfo returns information about the configuration of a workstation.

View File

@@ -132,7 +132,7 @@ func GlobalMemoryStatusEx() (MemoryStatus, error) {
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo
func GetSystemInfo() SystemInfo {
var info lpSystemInfo
procGetSystemInfo.Call(uintptr(unsafe.Pointer(&info)))
procGetSystemInfo.Call(uintptr(unsafe.Pointer(&info))) //nolint:errcheck
return SystemInfo{
Arch: ProcessorArchitecture(info.Arch.WProcessorArchitecture),
PageSize: info.DwPageSize,

View File

@@ -13,6 +13,7 @@
//
// Implementation forked from github.com/prometheus/common
//
//go:build windows
// +build windows
package log

View File

@@ -6,13 +6,13 @@ import (
// Returns an adapter implementing the go-kit/kit/log.Logger interface on our
// logrus logger
func NewToolkitAdapter() *logAdapter {
return &logAdapter{}
func NewToolkitAdapter() *Adapter {
return &Adapter{}
}
type logAdapter struct{}
type Adapter struct{}
func (*logAdapter) Log(keyvals ...interface{}) error {
func (*Adapter) Log(keyvals ...interface{}) error {
var lvl level.Value
var msg string
for i := 0; i < len(keyvals); i += 2 {

View File

@@ -13,7 +13,6 @@
// Package log implements logging via logrus.
// Implementation forked from github.com/prometheus/common
package log
import (