@@ -33,9 +33,9 @@ func TestPGStateStatementsCollector(t *testing.T) {
33
33
34
34
inst := & instance {db : db , version : semver .MustParse ("12.0.0" )}
35
35
36
- columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
36
+ columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
37
37
rows := sqlmock .NewRows (columns ).
38
- AddRow ("postgres" , "postgres" , 1500 , 5 , 0.4 , 100 , 0.1 , 0.2 )
38
+ AddRow ("postgres" , "postgres" , 1500 , 5 , 0.4 , 100 , 0.1 , 0.2 , 0.8 , 0.08 , 0.05 )
39
39
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery , "" ))).WillReturnRows (rows )
40
40
41
41
ch := make (chan prometheus.Metric )
@@ -76,9 +76,9 @@ func TestPGStateStatementsCollectorWithStatement(t *testing.T) {
76
76
77
77
inst := & instance {db : db , version : semver .MustParse ("12.0.0" )}
78
78
79
- columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 100) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
79
+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 100) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
80
80
rows := sqlmock .NewRows (columns ).
81
- AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
81
+ AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 , 0.8 , 0.08 , 0.05 )
82
82
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery , fmt .Sprintf (pgStatStatementQuerySelect , 100 )))).WillReturnRows (rows )
83
83
84
84
ch := make (chan prometheus.Metric )
@@ -97,6 +97,9 @@ func TestPGStateStatementsCollectorWithStatement(t *testing.T) {
97
97
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 100 },
98
98
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 0.1 },
99
99
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 0.2 },
100
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.8 },
101
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.08 },
102
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.05 },
100
103
{labels : labelMap {"queryid" : "1500" , "query" : "select 1 from foo" }, metricType : dto .MetricType_COUNTER , value : 1 },
101
104
}
102
105
@@ -120,9 +123,9 @@ func TestPGStateStatementsCollectorNull(t *testing.T) {
120
123
121
124
inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
122
125
123
- columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
126
+ columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
124
127
rows := sqlmock .NewRows (columns ).
125
- AddRow (nil , nil , nil , nil , nil , nil , nil , nil )
128
+ AddRow (nil , nil , nil , nil , nil , nil , nil , nil , nil , nil , nil )
126
129
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , "" ))).WillReturnRows (rows )
127
130
128
131
ch := make (chan prometheus.Metric )
@@ -163,9 +166,9 @@ func TestPGStateStatementsCollectorNullWithStatement(t *testing.T) {
163
166
164
167
inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
165
168
166
- columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 200) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
169
+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 200) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
167
170
rows := sqlmock .NewRows (columns ).
168
- AddRow (nil , nil , nil , nil , nil , nil , nil , nil , nil )
171
+ AddRow (nil , nil , nil , nil , nil , nil , nil , nil , nil , nil , nil , nil )
169
172
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , fmt .Sprintf (pgStatStatementQuerySelect , 200 )))).WillReturnRows (rows )
170
173
171
174
ch := make (chan prometheus.Metric )
@@ -184,6 +187,9 @@ func TestPGStateStatementsCollectorNullWithStatement(t *testing.T) {
184
187
{labels : labelMap {"user" : "unknown" , "datname" : "unknown" , "queryid" : "unknown" }, metricType : dto .MetricType_COUNTER , value : 0 },
185
188
{labels : labelMap {"user" : "unknown" , "datname" : "unknown" , "queryid" : "unknown" }, metricType : dto .MetricType_COUNTER , value : 0 },
186
189
{labels : labelMap {"user" : "unknown" , "datname" : "unknown" , "queryid" : "unknown" }, metricType : dto .MetricType_COUNTER , value : 0 },
190
+ {labels : labelMap {"user" : "unknown" , "datname" : "unknown" , "queryid" : "unknown" }, metricType : dto .MetricType_GAUGE , value : 0 },
191
+ {labels : labelMap {"user" : "unknown" , "datname" : "unknown" , "queryid" : "unknown" }, metricType : dto .MetricType_GAUGE , value : 0 },
192
+ {labels : labelMap {"user" : "unknown" , "datname" : "unknown" , "queryid" : "unknown" }, metricType : dto .MetricType_GAUGE , value : 0 },
187
193
{labels : labelMap {"queryid" : "unknown" , "query" : "unknown" }, metricType : dto .MetricType_COUNTER , value : 1 },
188
194
}
189
195
@@ -207,9 +213,9 @@ func TestPGStateStatementsCollectorNewPG(t *testing.T) {
207
213
208
214
inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
209
215
210
- columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
216
+ columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
211
217
rows := sqlmock .NewRows (columns ).
212
- AddRow ("postgres" , "postgres" , 1500 , 5 , 0.4 , 100 , 0.1 , 0.2 )
218
+ AddRow ("postgres" , "postgres" , 1500 , 5 , 0.4 , 100 , 0.1 , 0.2 , 0.8 , 0.08 , 0.05 )
213
219
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , "" ))).WillReturnRows (rows )
214
220
215
221
ch := make (chan prometheus.Metric )
@@ -250,9 +256,9 @@ func TestPGStateStatementsCollectorNewPGWithStatement(t *testing.T) {
250
256
251
257
inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
252
258
253
- columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 300) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
259
+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 300) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
254
260
rows := sqlmock .NewRows (columns ).
255
- AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
261
+ AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 , 0.8 , 0.08 , 0.05 )
256
262
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , fmt .Sprintf (pgStatStatementQuerySelect , 300 )))).WillReturnRows (rows )
257
263
258
264
ch := make (chan prometheus.Metric )
@@ -271,6 +277,9 @@ func TestPGStateStatementsCollectorNewPGWithStatement(t *testing.T) {
271
277
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 100 },
272
278
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 0.1 },
273
279
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 0.2 },
280
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.8 },
281
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.08 },
282
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.05 },
274
283
{labels : labelMap {"queryid" : "1500" , "query" : "select 1 from foo" }, metricType : dto .MetricType_COUNTER , value : 1 },
275
284
}
276
285
@@ -294,9 +303,9 @@ func TestPGStateStatementsCollector_PG17(t *testing.T) {
294
303
295
304
inst := & instance {db : db , version : semver .MustParse ("17.0.0" )}
296
305
297
- columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
306
+ columns := []string {"user" , "datname" , "queryid" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
298
307
rows := sqlmock .NewRows (columns ).
299
- AddRow ("postgres" , "postgres" , 1500 , 5 , 0.4 , 100 , 0.1 , 0.2 )
308
+ AddRow ("postgres" , "postgres" , 1500 , 5 , 0.4 , 100 , 0.1 , 0.2 , 0.8 , 0.08 , 0.05 )
300
309
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery_PG17 , "" ))).WillReturnRows (rows )
301
310
302
311
ch := make (chan prometheus.Metric )
@@ -337,9 +346,9 @@ func TestPGStateStatementsCollector_PG17_WithStatement(t *testing.T) {
337
346
338
347
inst := & instance {db : db , version : semver .MustParse ("17.0.0" )}
339
348
340
- columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 300) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
349
+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 300) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" , "max_seconds" , "mean_seconds" , "stddev_seconds" }
341
350
rows := sqlmock .NewRows (columns ).
342
- AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
351
+ AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 , 0.8 , 0.08 , 0.05 )
343
352
mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery_PG17 , fmt .Sprintf (pgStatStatementQuerySelect , 300 )))).WillReturnRows (rows )
344
353
345
354
ch := make (chan prometheus.Metric )
@@ -358,6 +367,9 @@ func TestPGStateStatementsCollector_PG17_WithStatement(t *testing.T) {
358
367
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 100 },
359
368
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 0.1 },
360
369
{labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_COUNTER , value : 0.2 },
370
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.8 },
371
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.08 },
372
+ {labels : labelMap {"user" : "postgres" , "datname" : "postgres" , "queryid" : "1500" }, metricType : dto .MetricType_GAUGE , value : 0.05 },
361
373
{labels : labelMap {"queryid" : "1500" , "query" : "select 1 from foo" }, metricType : dto .MetricType_COUNTER , value : 1 },
362
374
}
363
375
0 commit comments