@@ -76,15 +76,15 @@ 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" , "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" }
80
80
rows := sqlmock .NewRows (columns ).
81
81
AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
82
- mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery , pgStatStatementQuerySelect ))).WillReturnRows (rows )
82
+ mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery , fmt . Sprintf ( pgStatStatementQuerySelect , 100 ) ))).WillReturnRows (rows )
83
83
84
84
ch := make (chan prometheus.Metric )
85
85
go func () {
86
86
defer close (ch )
87
- c := PGStatStatementsCollector {includeQueryStatement : true }
87
+ c := PGStatStatementsCollector {includeQueryStatement : true , statementLength : 100 }
88
88
89
89
if err := c .Update (context .Background (), inst , ch ); err != nil {
90
90
t .Errorf ("Error calling PGStatStatementsCollector.Update: %s" , err )
@@ -163,15 +163,15 @@ func TestPGStateStatementsCollectorNullWithStatement(t *testing.T) {
163
163
164
164
inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
165
165
166
- columns := []string {"user" , "datname" , "queryid" , "query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
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" }
167
167
rows := sqlmock .NewRows (columns ).
168
168
AddRow (nil , nil , nil , nil , nil , nil , nil , nil , nil )
169
- mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , pgStatStatementQuerySelect ))).WillReturnRows (rows )
169
+ mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , fmt . Sprintf ( pgStatStatementQuerySelect , 200 ) ))).WillReturnRows (rows )
170
170
171
171
ch := make (chan prometheus.Metric )
172
172
go func () {
173
173
defer close (ch )
174
- c := PGStatStatementsCollector {includeQueryStatement : true }
174
+ c := PGStatStatementsCollector {includeQueryStatement : true , statementLength : 200 }
175
175
176
176
if err := c .Update (context .Background (), inst , ch ); err != nil {
177
177
t .Errorf ("Error calling PGStatStatementsCollector.Update: %s" , err )
@@ -250,15 +250,15 @@ func TestPGStateStatementsCollectorNewPGWithStatement(t *testing.T) {
250
250
251
251
inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
252
252
253
- columns := []string {"user" , "datname" , "queryid" , "query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
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" }
254
254
rows := sqlmock .NewRows (columns ).
255
255
AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
256
- mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , pgStatStatementQuerySelect ))).WillReturnRows (rows )
256
+ mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , fmt . Sprintf ( pgStatStatementQuerySelect , 300 ) ))).WillReturnRows (rows )
257
257
258
258
ch := make (chan prometheus.Metric )
259
259
go func () {
260
260
defer close (ch )
261
- c := PGStatStatementsCollector {includeQueryStatement : true }
261
+ c := PGStatStatementsCollector {includeQueryStatement : true , statementLength : 300 }
262
262
263
263
if err := c .Update (context .Background (), inst , ch ); err != nil {
264
264
t .Errorf ("Error calling PGStatStatementsCollector.Update: %s" , err )
0 commit comments