@@ -4196,3 +4196,62 @@ func TestAnalyzeLogLines(t *testing.T) {
4196
4196
}
4197
4197
}
4198
4198
}
4199
+
4200
+ var testsHeroku = []testpair {{ // Heroku text explain + new line in Query Text (due to the query being too long)
4201
+ []state.LogLine {{
4202
+ Content : "duration: 1681.452 ms plan:\n " +
4203
+ "\t Query Text: UPDATE pgbench_branches SET bbalance = bbalance +\n 2656 WHERE bid = 59;\n " +
4204
+ "\t Update on public.pgbench_branches (cost=0.27..8.29 rows=1 width=370) (actual rows=0 loops=1)\n " +
4205
+ "\t Buffers: shared hit=7\n " +
4206
+ "\t -> Index Scan using pgbench_branches_pkey on public.pgbench_branches (cost=0.27..8.29 rows=1 width=370) (actual rows=1 loops=1)\n " +
4207
+ "\t Output: bid, (bbalance + 2656), filler, ctid\n " +
4208
+ "\t Index Cond: (pgbench_branches.bid = 59)" ,
4209
+ }},
4210
+ []state.LogLine {{
4211
+ Query : "UPDATE pgbench_branches SET bbalance = bbalance +\n 2656 WHERE bid = 59;" ,
4212
+ Classification : pganalyze_collector .LogLineInformation_STATEMENT_AUTO_EXPLAIN ,
4213
+ ReviewedForSecrets : true ,
4214
+ SecretMarkers : []state.LogSecretMarker {{
4215
+ ByteStart : 30 ,
4216
+ ByteEnd : 469 ,
4217
+ Kind : state .StatementTextLogSecret ,
4218
+ }},
4219
+ }},
4220
+ []state.PostgresQuerySample {{
4221
+ Query : "UPDATE pgbench_branches SET bbalance = bbalance +\n 2656 WHERE bid = 59;" ,
4222
+ RuntimeMs : 1681.452 ,
4223
+ HasExplain : true ,
4224
+ ExplainSource : pganalyze_collector .QuerySample_AUTO_EXPLAIN_EXPLAIN_SOURCE ,
4225
+ ExplainFormat : pganalyze_collector .QuerySample_TEXT_EXPLAIN_FORMAT ,
4226
+ ExplainOutputText : "Update on public.pgbench_branches (cost=0.27..8.29 rows=1 width=370) (actual rows=0 loops=1)\n " +
4227
+ "\t Buffers: shared hit=7\n " +
4228
+ "\t -> Index Scan using pgbench_branches_pkey on public.pgbench_branches (cost=0.27..8.29 rows=1 width=370) (actual rows=1 loops=1)\n " +
4229
+ "\t Output: bid, (bbalance + 2656), filler, ctid\n " +
4230
+ "\t Index Cond: (pgbench_branches.bid = 59)" ,
4231
+ }},
4232
+ },
4233
+ }
4234
+
4235
+ func TestAnalyzeLogLinesHeroku (t * testing.T ) {
4236
+ t .Setenv ("DYNO" , "dummy" )
4237
+ t .Setenv ("PORT" , "dummy" )
4238
+ for _ , pair := range testsHeroku {
4239
+ l , s := logs .AnalyzeLogLines (pair .logLinesIn )
4240
+
4241
+ cfg := pretty .CompareConfig
4242
+ cfg .SkipZeroFields = true
4243
+
4244
+ if diff := cfg .Compare (pair .logLinesOut , l ); diff != "" {
4245
+ t .Errorf ("For %v: log lines diff: (-want +got)\n %s" , pair .logLinesIn , diff )
4246
+ }
4247
+ if diff := cfg .Compare (pair .samplesOut , s ); diff != "" {
4248
+ t .Errorf ("For %v: query samples diff: (-want +got)\n %s" , pair .samplesOut , diff )
4249
+ }
4250
+
4251
+ for idx , line := range pair .logLinesOut {
4252
+ if ! line .ReviewedForSecrets && line .LogLevel != pganalyze_collector .LogLineInformation_STATEMENT && line .LogLevel != pganalyze_collector .LogLineInformation_QUERY {
4253
+ t .Errorf ("Missing secret review for:\n %s %s\n " , pair .logLinesIn [idx ].LogLevel , pair .logLinesIn [idx ].Content )
4254
+ }
4255
+ }
4256
+ }
4257
+ }
0 commit comments