Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed revive warning #50

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/pgscv.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main is a pgSCV main package
package main

import (
Expand Down
1 change: 1 addition & 0 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package collector is a pgSCV collectors
package collector

import (
Expand Down
10 changes: 6 additions & 4 deletions internal/collector/collector_common.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Package collector is a pgSCV collectors
package collector

import (
"database/sql"
"github.com/jackc/pgx/v4"
"regexp"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/cherts/pgscv/internal/store"
"github.com/jackc/pgx/v4"
"github.com/prometheus/client_golang/prometheus"
"regexp"
"strconv"
"strings"
)

// labels is a local wrapper over prometheus.Labels which is a simple map[string]string.
Expand Down
1 change: 1 addition & 0 deletions internal/collector/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package collector is a pgSCV collectors
package collector

import (
Expand Down
4 changes: 3 additions & 1 deletion internal/collector/filesystem_common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"fmt"
"github.com/cherts/pgscv/internal/log"
"io"
"os"
"strings"

"github.com/cherts/pgscv/internal/log"
)

// mount describes properties of mounted filesystems
Expand Down
8 changes: 5 additions & 3 deletions internal/collector/linux_cpu.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"bytes"
"fmt"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

type cpuCollector struct {
Expand Down
10 changes: 6 additions & 4 deletions internal/collector/linux_diskstats.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"bytes"
"fmt"
"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

const (
Expand Down
10 changes: 6 additions & 4 deletions internal/collector/linux_filesystem.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Package collector is a pgSCV collectors
package collector

import (
"errors"
"fmt"
"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"syscall"
"time"

"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

var (
Expand Down
8 changes: 5 additions & 3 deletions internal/collector/linux_load_average.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Package collector is a pgSCV collectors
package collector

import (
"fmt"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"os"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

type loadaverageCollector struct {
Expand Down
10 changes: 6 additions & 4 deletions internal/collector/linux_memory.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"fmt"
"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"regexp"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

type meminfoCollector struct {
Expand Down
10 changes: 6 additions & 4 deletions internal/collector/linux_netdev.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"fmt"
"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/filter"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

type netdevCollector struct {
Expand Down
7 changes: 5 additions & 2 deletions internal/collector/linux_network.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// Package collector is a pgSCV collectors
package collector

import (
"fmt"
"net"
"strings"

"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"net"
"strings"
)

type networkCollector struct {
privateAddresses typedDesc
publicAddresses typedDesc
}

// NewNetworkCollector returns a new Collector exposing network interfaces addresses.
func NewNetworkCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) {
return &networkCollector{
publicAddresses: newBuiltinTypedDesc(
Expand Down
10 changes: 6 additions & 4 deletions internal/collector/linux_sysconfig.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"bytes"
"fmt"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

type systemCollector struct {
Expand All @@ -27,7 +29,7 @@ type systemCollector struct {
btime typedDesc
}

// NewSystemCollector returns a new Collector exposing system-wide stats.
// NewSysconfigCollector returns a new Collector exposing system-wide stats.
func NewSysconfigCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) {
return &systemCollector{
sysctlList: []string{
Expand Down
8 changes: 5 additions & 3 deletions internal/collector/linux_sysinfo.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Package collector is a pgSCV collectors
package collector

import (
"bufio"
"fmt"
"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
"io"
"os"
"path/filepath"
"strings"

"github.com/cherts/pgscv/internal/log"
"github.com/cherts/pgscv/internal/model"
"github.com/prometheus/client_golang/prometheus"
)

type sysinfoCollector struct {
Expand Down
32 changes: 17 additions & 15 deletions internal/collector/patroni_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package collector is a pgSCV collectors
package collector

import (
Expand Down Expand Up @@ -222,13 +223,14 @@ func NewPatroniCommonCollector(constLabels labels, settings model.CollectorSetti
}, nil
}

// Update method collects statistics, parse it and produces metrics that are sent to Prometheus.
func (c *patroniCommonCollector) Update(config Config, ch chan<- prometheus.Metric) error {
if strings.HasPrefix(config.BaseURL, "https://") {
c.client.EnableTLSInsecure()
}

// Check liveness.
err := requestApiLiveness(c.client, config.BaseURL)
err := requestAPILiveness(c.client, config.BaseURL)
if err != nil {
ch <- c.up.newConstMetric(0)
return err
Expand All @@ -237,7 +239,7 @@ func (c *patroniCommonCollector) Update(config Config, ch chan<- prometheus.Metr
ch <- c.up.newConstMetric(1)

// Request general info.
respInfo, err := requestApiPatroni(c.client, config.BaseURL)
respInfo, err := requestAPIPatroni(c.client, config.BaseURL)
if err != nil {
return err
}
Expand Down Expand Up @@ -273,7 +275,7 @@ func (c *patroniCommonCollector) Update(config Config, ch chan<- prometheus.Metr
ch <- c.syncStandby.newConstMetric(info.syncStandby, info.scope)

// Request and parse config.
respConfig, err := requestApiPatroniConfig(c.client, config.BaseURL)
respConfig, err := requestAPIPatroniConfig(c.client, config.BaseURL)
if err != nil {
return err
}
Expand All @@ -288,7 +290,7 @@ func (c *patroniCommonCollector) Update(config Config, ch chan<- prometheus.Metr
}

// Request and parse history.
respHist, err := requestApiHistory(c.client, config.BaseURL)
respHist, err := requestAPIHistory(c.client, config.BaseURL)
if err != nil {
return err
}
Expand All @@ -301,8 +303,8 @@ func (c *patroniCommonCollector) Update(config Config, ch chan<- prometheus.Metr
return nil
}

// requestApiLiveness requests to /liveness endpoint of API and returns error if failed.
func requestApiLiveness(c *http.Client, baseurl string) error {
// requestAPILiveness requests to /liveness endpoint of API and returns error if failed.
func requestAPILiveness(c *http.Client, baseurl string) error {
_, err := c.Get(baseurl + "/liveness")
if err != nil {
return err
Expand Down Expand Up @@ -371,13 +373,13 @@ type patroniInfo struct {
syncStandby float64
}

// apiPatroniResponse implements API response returned by '/config' endpoint.
// apiPatroniConfigResponse implements API response returned by '/config' endpoint.
type apiPatroniConfigResponse struct {
FailSafeMode bool `json:"failsafe_mode"`
LoopWait int `json:"loop_wait"`
MaxLagOnFailover int `json:"maximum_lag_on_failover"`
RetryTimeout int `json:"retry_timeout"`
Ttl int `json:"ttl"`
TTL int `json:"ttl"`
}

// patroniConfigInfo implements metrics values extracted from the response of '/config' endpoint.
Expand All @@ -389,8 +391,8 @@ type patroniConfigInfo struct {
ttl float64
}

// requestPatroniConfigInfo requests to /config endpoint of API and returns parsed response.
func requestApiPatroniConfig(c *http.Client, baseurl string) (*apiPatroniConfigResponse, error) {
// requestAPIPatroniConfig requests to /config endpoint of API and returns parsed response.
func requestAPIPatroniConfig(c *http.Client, baseurl string) (*apiPatroniConfigResponse, error) {
resp, err := c.Get(baseurl + "/config")
if err != nil {
return nil, err
Expand Down Expand Up @@ -429,12 +431,12 @@ func parsePatroniConfigResponse(resp *apiPatroniConfigResponse) (*patroniConfigI
loopWait: float64(resp.LoopWait),
maximumLagOnFailover: float64(resp.MaxLagOnFailover),
retryTimeout: float64(resp.RetryTimeout),
ttl: float64(resp.Ttl),
ttl: float64(resp.TTL),
}, nil
}

// requestPatroniInfo requests to /patroni endpoint of API and returns parsed response.
func requestApiPatroni(c *http.Client, baseurl string) (*apiPatroniResponse, error) {
// requestAPIPatroni requests to /patroni endpoint of API and returns parsed response.
func requestAPIPatroni(c *http.Client, baseurl string) (*apiPatroniResponse, error) {
resp, err := c.Get(baseurl + "/patroni")
if err != nil {
return nil, err
Expand Down Expand Up @@ -580,8 +582,8 @@ type patroniHistory struct {
lastTimelineChangeUnix float64
}

// requestApiHistory requests /history endpoint of API and returns parsed response.
func requestApiHistory(c *http.Client, baseurl string) (apiHistoryResponse, error) {
// requestAPIHistory requests /history endpoint of API and returns parsed response.
func requestAPIHistory(c *http.Client, baseurl string) (apiHistoryResponse, error) {
resp, err := c.Get(baseurl + "/history")
if err != nil {
return nil, err
Expand Down
Loading