Skip to content

Commit 1a3fdaf

Browse files
authored
Merge branch 'master' into cleanup/gitlab-exporter-long-xacts
2 parents 1e59dd5 + 4ac5481 commit 1a3fdaf

16 files changed

+214
-53
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
---
2+
# This action is synced from https://github.com/prometheus/prometheus
13
name: golangci-lint
24
on:
35
push:
@@ -27,4 +29,4 @@ jobs:
2729
- name: Lint
2830
uses: golangci/[email protected]
2931
with:
30-
version: v1.51.2
32+
version: v1.53.3

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
linters:
33
enable:
4+
- misspell
45
- revive
56

67
issues:
@@ -14,3 +15,9 @@ linters-settings:
1415
exclude-functions:
1516
# Never check for logger errors.
1617
- (github.com/go-kit/log.Logger).Log
18+
revive:
19+
rules:
20+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
21+
- name: unused-parameter
22+
severity: warning
23+
disabled: true

.yamllint

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ rules:
2020
config/testdata/section_key_dup.bad.yml
2121
line-length: disable
2222
truthy:
23-
ignore: |
24-
.github/workflows/*.yml
23+
check-keys: false

Makefile.common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ifneq ($(shell command -v gotestsum > /dev/null),)
5555
endif
5656
endif
5757

58-
PROMU_VERSION ?= 0.14.0
58+
PROMU_VERSION ?= 0.15.0
5959
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
6060

6161
SKIP_GOLANGCI_LINT :=

collector/collector_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ func sanitizeQuery(q string) string {
5050
q = strings.Join(strings.Fields(q), " ")
5151
q = strings.Replace(q, "(", "\\(", -1)
5252
q = strings.Replace(q, ")", "\\)", -1)
53+
q = strings.Replace(q, "[", "\\[", -1)
54+
q = strings.Replace(q, "]", "\\]", -1)
55+
q = strings.Replace(q, "{", "\\{", -1)
56+
q = strings.Replace(q, "}", "\\}", -1)
5357
q = strings.Replace(q, "*", "\\*", -1)
58+
q = strings.Replace(q, "^", "\\^", -1)
5459
q = strings.Replace(q, "$", "\\$", -1)
5560
return q
5661
}

collector/pg_database.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ func (c PGDatabaseCollector) Update(ctx context.Context, instance *instance, ch
115115
prometheus.GaugeValue, sizeMetric, datname,
116116
)
117117
}
118-
if err := rows.Err(); err != nil {
119-
return err
120-
}
121-
return nil
118+
return rows.Err()
122119
}
123120

124121
func sliceContains(slice []string, s string) bool {

collector/pg_process_idle.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"database/sql"
1919

2020
"github.com/go-kit/log"
21+
"github.com/lib/pq"
2122
"github.com/prometheus/client_golang/prometheus"
2223
)
2324

@@ -39,7 +40,7 @@ func NewPGProcessIdleCollector(config collectorConfig) (Collector, error) {
3940
var pgProcessIdleSeconds = prometheus.NewDesc(
4041
prometheus.BuildFQName(namespace, processIdleSubsystem, "seconds"),
4142
"Idle time of server processes",
42-
[]string{"application_name"},
43+
[]string{"state", "application_name"},
4344
prometheus.Labels{},
4445
)
4546

@@ -49,15 +50,17 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
4950
`WITH
5051
metrics AS (
5152
SELECT
53+
state,
5254
application_name,
5355
SUM(EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change))::bigint)::float AS process_idle_seconds_sum,
5456
COUNT(*) AS process_idle_seconds_count
5557
FROM pg_stat_activity
56-
WHERE state = 'idle'
57-
GROUP BY application_name
58+
WHERE state ~ '^idle'
59+
GROUP BY state, application_name
5860
),
5961
buckets AS (
6062
SELECT
63+
state,
6164
application_name,
6265
le,
6366
SUM(
@@ -69,35 +72,42 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
6972
FROM
7073
pg_stat_activity,
7174
UNNEST(ARRAY[1, 2, 5, 15, 30, 60, 90, 120, 300]) AS le
72-
GROUP BY application_name, le
73-
ORDER BY application_name, le
75+
GROUP BY state, application_name, le
76+
ORDER BY state, application_name, le
7477
)
7578
SELECT
79+
state,
7680
application_name,
7781
process_idle_seconds_sum as seconds_sum,
7882
process_idle_seconds_count as seconds_count,
7983
ARRAY_AGG(le) AS seconds,
8084
ARRAY_AGG(bucket) AS seconds_bucket
81-
FROM metrics JOIN buckets USING (application_name)
82-
GROUP BY 1, 2, 3;`)
85+
FROM metrics JOIN buckets USING (state, application_name)
86+
GROUP BY 1, 2, 3, 4;`)
8387

88+
var state sql.NullString
8489
var applicationName sql.NullString
85-
var secondsSum sql.NullInt64
90+
var secondsSum sql.NullFloat64
8691
var secondsCount sql.NullInt64
87-
var seconds []uint64
88-
var secondsBucket []uint64
92+
var seconds []float64
93+
var secondsBucket []int64
8994

90-
err := row.Scan(&applicationName, &secondsSum, &secondsCount, &seconds, &secondsBucket)
95+
err := row.Scan(&state, &applicationName, &secondsSum, &secondsCount, pq.Array(&seconds), pq.Array(&secondsBucket))
96+
if err != nil {
97+
return err
98+
}
9199

92100
var buckets = make(map[float64]uint64, len(seconds))
93101
for i, second := range seconds {
94102
if i >= len(secondsBucket) {
95103
break
96104
}
97-
buckets[float64(second)] = secondsBucket[i]
105+
buckets[second] = uint64(secondsBucket[i])
98106
}
99-
if err != nil {
100-
return err
107+
108+
stateLabel := "unknown"
109+
if state.Valid {
110+
stateLabel = state.String
101111
}
102112

103113
applicationNameLabel := "unknown"
@@ -111,12 +121,12 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
111121
}
112122
secondsSumMetric := 0.0
113123
if secondsSum.Valid {
114-
secondsSumMetric = float64(secondsSum.Int64)
124+
secondsSumMetric = secondsSum.Float64
115125
}
116126
ch <- prometheus.MustNewConstHistogram(
117127
pgProcessIdleSeconds,
118128
secondsCountMetric, secondsSumMetric, buckets,
119-
applicationNameLabel,
129+
stateLabel, applicationNameLabel,
120130
)
121131
return nil
122132
}

collector/pg_replication.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type PGReplicationCollector struct {
2929
}
3030

3131
func NewPGReplicationCollector(collectorConfig) (Collector, error) {
32-
return &PGPostmasterCollector{}, nil
32+
return &PGReplicationCollector{}, nil
3333
}
3434

3535
var (

collector/pg_replication_slot.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,5 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
126126
prometheus.GaugeValue, isActiveValue, slotNameLabel,
127127
)
128128
}
129-
if err := rows.Err(); err != nil {
130-
return err
131-
}
132-
return nil
129+
return rows.Err()
133130
}

collector/pg_stat_bgwriter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestPGStatBGWriterCollector(t *testing.T) {
5151
}
5252

5353
rows := sqlmock.NewRows(columns).
54-
AddRow(354, 4945, 289097744, 1242257, 3275602074, 89320867, 450139, 2034563757, 0, 2725688749, srT)
54+
AddRow(354, 4945, 289097744, 1242257, int64(3275602074), 89320867, 450139, 2034563757, 0, int64(2725688749), srT)
5555
mock.ExpectQuery(sanitizeQuery(statBGWriterQuery)).WillReturnRows(rows)
5656

5757
ch := make(chan prometheus.Metric)

0 commit comments

Comments
 (0)