Skip to content

Commit 5883d0d

Browse files
authored
Aggr statements with same error msg to keep error msg in 1.2-dev (#18588)
changes: - aggr erorr statement filter with same error msg. Approved by: @heni02, @qingxinhome, @sukki37
1 parent f458b0a commit 5883d0d

File tree

6 files changed

+198
-4
lines changed

6 files changed

+198
-4
lines changed

pkg/util/trace/impl/motrace/report_statement.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func StatementInfoUpdate(ctx context.Context, existing, new Item) {
100100
windowSize, _ := ctx.Value(DurationKey).(time.Duration)
101101
e.StatementTag = ""
102102
e.StatementFingerprint = ""
103-
e.Error = nil
103+
//e.Error = nil /* keep the Error msg */
104104
e.Database = ""
105105
duration := e.Duration
106106
e.AggrMemoryTime = mustDecimal128(convertFloat64ToDecimal128(e.statsArray.GetMemorySize() * float64(duration)))
@@ -239,6 +239,7 @@ type Key struct {
239239
Window time.Time
240240
Status StatementInfoStatus
241241
SqlSourceType string
242+
Error string
242243
}
243244

244245
var stmtPool = sync.Pool{
@@ -259,8 +260,22 @@ type Statistic struct {
259260
BytesScan int64
260261
}
261262

262-
func (s *StatementInfo) Key(duration time.Duration) interface{} {
263-
return Key{SessionID: s.SessionID, StatementType: s.StatementType, Window: s.ResponseAt.Truncate(duration), Status: s.Status, SqlSourceType: s.SqlSourceType}
263+
func getErrorString(err error) string {
264+
if err == nil {
265+
return ""
266+
}
267+
return err.Error()
268+
}
269+
270+
func (s *StatementInfo) Key(duration time.Duration) any {
271+
return Key{
272+
SessionID: s.SessionID,
273+
StatementType: s.StatementType,
274+
Window: s.ResponseAt.Truncate(duration),
275+
Status: s.Status,
276+
SqlSourceType: s.SqlSourceType,
277+
Error: getErrorString(s.Error),
278+
}
264279
}
265280

266281
func (s *StatementInfo) GetName() string {

pkg/util/trace/impl/motrace/report_statement_test.go

+104-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/stretchr/testify/assert"
25+
26+
"github.com/matrixorigin/matrixone/pkg/common/moerr"
2427
"github.com/matrixorigin/matrixone/pkg/util/trace/impl/motrace/statistic"
2528

2629
"github.com/google/uuid"
27-
"github.com/matrixorigin/matrixone/pkg/common/util"
2830
"github.com/prashantv/gostub"
2931
"github.com/stretchr/testify/require"
32+
33+
"github.com/matrixorigin/matrixone/pkg/common/util"
3034
)
3135

3236
func TestStatementInfo_Report_EndStatement(t *testing.T) {
@@ -375,3 +379,102 @@ func TestCalculateAggrMemoryBytes(t *testing.T) {
375379
})
376380
}
377381
}
382+
383+
func TestStatementInfo_Key(t *testing.T) {
384+
385+
now := time.Now()
386+
nowSub5sec := now.Add(-5 * time.Second)
387+
dummyError := moerr.NewInternalError(context.TODO(), "dummy test errmsg")
388+
type fields struct {
389+
SessionID [16]byte
390+
SqlSourceType string
391+
StatementType string
392+
Status StatementInfoStatus
393+
Error error
394+
ResponseAt time.Time
395+
}
396+
type args struct {
397+
duration time.Duration
398+
}
399+
tests := []struct {
400+
name string
401+
fields fields
402+
args args
403+
want any
404+
}{
405+
{
406+
name: "normal",
407+
fields: fields{
408+
SessionID: NilSesID,
409+
SqlSourceType: "source_01",
410+
StatementType: "stmt_type_01",
411+
Status: StatementStatusSuccess,
412+
Error: nil,
413+
ResponseAt: now,
414+
},
415+
args: args{duration: 5 * time.Second},
416+
want: Key{
417+
SessionID: NilSesID,
418+
StatementType: "stmt_type_01",
419+
Window: now.Truncate(5 * time.Second),
420+
Status: StatementStatusSuccess,
421+
SqlSourceType: "source_01",
422+
Error: "",
423+
},
424+
},
425+
{
426+
name: "error",
427+
fields: fields{
428+
SessionID: NilSesID,
429+
SqlSourceType: "source_01",
430+
StatementType: "stmt_type_01",
431+
Status: StatementStatusFailed,
432+
Error: moerr.GetOkExpectedEOF(),
433+
ResponseAt: nowSub5sec,
434+
},
435+
args: args{duration: 5 * time.Second},
436+
want: Key{
437+
SessionID: NilSesID,
438+
StatementType: "stmt_type_01",
439+
Window: nowSub5sec.Truncate(5 * time.Second),
440+
Status: StatementStatusFailed,
441+
SqlSourceType: "source_01",
442+
Error: moerr.GetOkExpectedEOF().Error(),
443+
},
444+
},
445+
{
446+
name: "error_InternalError",
447+
fields: fields{
448+
SessionID: NilSesID,
449+
SqlSourceType: "source_01",
450+
StatementType: "stmt_type_01",
451+
Status: StatementStatusFailed,
452+
Error: dummyError,
453+
ResponseAt: nowSub5sec,
454+
},
455+
args: args{duration: 5 * time.Second},
456+
want: Key{
457+
SessionID: NilSesID,
458+
StatementType: "stmt_type_01",
459+
Window: nowSub5sec.Truncate(5 * time.Second),
460+
Status: StatementStatusFailed,
461+
SqlSourceType: "source_01",
462+
Error: dummyError.Error(),
463+
},
464+
},
465+
}
466+
for _, tt := range tests {
467+
t.Run(tt.name, func(t *testing.T) {
468+
s := &StatementInfo{
469+
SessionID: tt.fields.SessionID,
470+
SqlSourceType: tt.fields.SqlSourceType,
471+
StatementType: tt.fields.StatementType,
472+
Status: tt.fields.Status,
473+
Error: tt.fields.Error,
474+
ResponseAt: tt.fields.ResponseAt,
475+
}
476+
assert.Equalf(t, tt.want, s.Key(tt.args.duration), "Key(%v)", tt.args.duration)
477+
t.Logf("error: %v", tt.want.(Key).Error)
478+
})
479+
}
480+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
drop account if exists bvt_aggr_error_stmt;
2+
create account if not exists `bvt_aggr_error_stmt` ADMIN_NAME 'admin' IDENTIFIED BY '123456';
3+
/* cloud_nonuser */ select * from system.statement_not_exist;
4+
SQL parser error: table "statement_not_exist" does not exist
5+
/* cloud_nonuser */ select * from system.statement_not_exist;
6+
SQL parser error: table "statement_not_exist" does not exist
7+
/* cloud_nonuser */ select * from system.statement_not_exist;
8+
SQL parser error: table "statement_not_exist" does not exist
9+
/* cloud_nonuser */ select * from system.statement_not_exist_2;
10+
SQL parser error: table "statement_not_exist_2" does not exist
11+
/* cloud_nonuser */ select * from system.statement_not_exist_2;
12+
SQL parser error: table "statement_not_exist_2" does not exist
13+
/* cloud_nonuser */ select * from system.statement_not_exist_2;
14+
SQL parser error: table "statement_not_exist_2" does not exist
15+
/* cloud_nonuser */ select * from system.statement_not_exist;
16+
SQL parser error: table "statement_not_exist" does not exist
17+
/* cloud_nonuser */ select * from system.statement_not_exist;
18+
SQL parser error: table "statement_not_exist" does not exist
19+
/* cloud_nonuser */ select * from system.statement_not_exist;
20+
SQL parser error: table "statement_not_exist" does not exist
21+
/* cloud_nonuser */ select * from system.statement_not_exist_3;
22+
SQL parser error: table "statement_not_exist_3" does not exist
23+
/* cloud_nonuser */ select * from system.statement_not_exist_3;
24+
SQL parser error: table "statement_not_exist_3" does not exist
25+
/* cloud_nonuser */ select * from system.statement_not_exist_3;
26+
SQL parser error: table "statement_not_exist_3" does not exist
27+
/* cloud_nonuser */ select * from system.statement_not_exist;
28+
SQL parser error: table "statement_not_exist" does not exist
29+
/* cloud_nonuser */ select * from system.statement_not_exist;
30+
SQL parser error: table "statement_not_exist" does not exist
31+
/* cloud_nonuser */ select * from system.statement_not_exist;
32+
SQL parser error: table "statement_not_exist" does not exist
33+
drop account if exists bvt_aggr_error_stmt;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- prepare
2+
drop account if exists bvt_aggr_error_stmt;
3+
create account if not exists `bvt_aggr_error_stmt` ADMIN_NAME 'admin' IDENTIFIED BY '123456';
4+
5+
-- Login bvt_aggr_error_stmt account
6+
-- @session:id=1&user=bvt_aggr_error_stmt:admin:accountadmin&password=123456
7+
8+
/* cloud_nonuser */ select * from system.statement_not_exist;
9+
/* cloud_nonuser */ select * from system.statement_not_exist;
10+
/* cloud_nonuser */ select * from system.statement_not_exist;
11+
12+
/* cloud_nonuser */ select * from system.statement_not_exist_2;
13+
/* cloud_nonuser */ select * from system.statement_not_exist_2;
14+
/* cloud_nonuser */ select * from system.statement_not_exist_2;
15+
16+
/* cloud_nonuser */ select * from system.statement_not_exist;
17+
/* cloud_nonuser */ select * from system.statement_not_exist;
18+
/* cloud_nonuser */ select * from system.statement_not_exist;
19+
20+
/* cloud_nonuser */ select * from system.statement_not_exist_3;
21+
/* cloud_nonuser */ select * from system.statement_not_exist_3;
22+
/* cloud_nonuser */ select * from system.statement_not_exist_3;
23+
24+
/* cloud_nonuser */ select * from system.statement_not_exist;
25+
/* cloud_nonuser */ select * from system.statement_not_exist;
26+
/* cloud_nonuser */ select * from system.statement_not_exist;
27+
28+
-- @session
29+
-- END
30+
31+
-- cleanup
32+
drop account if exists bvt_aggr_error_stmt;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
select error, count(1) < sum(aggr_count) check_result, count(1) cnt, sum(aggr_count) sum, statement from system.statement_info where account="bvt_aggr_error_stmt" and sql_source_type="cloud_nonuser_sql" group by `statement`, error;
2+
error check_result cnt sum statement
3+
SQL parser error: table "statement_not_exist_2" does not exist true 1 3 select * from system.statement_not_exist_2
4+
SQL parser error: table "statement_not_exist_3" does not exist true 1 3 select * from system.statement_not_exist_3
5+
SQL parser error: table "statement_not_exist" does not exist true 1 9 select * from system.statement_not_exist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- check result at the end of bvt.
2+
-- check result of statement_query_type/aggr_error_stmt.sql
3+
4+
-- Tips: cnt +1000, sum + 1000 both make sure result format is current.
5+
-- @ignore:2,3,4
6+
select error, count(1) < sum(aggr_count) check_result, count(1) cnt, sum(aggr_count) sum, statement from system.statement_info where account="bvt_aggr_error_stmt" and sql_source_type="cloud_nonuser_sql" group by `statement`, error;

0 commit comments

Comments
 (0)