@@ -619,9 +619,21 @@ func TestPlanCachePollution(t *testing.T) {
619
619
}
620
620
621
621
func TestAddQueryStats (t * testing.T ) {
622
+ fakeSelectPlan := & TabletPlan {
623
+ Plan : & planbuilder.Plan {
624
+ PlanID : planbuilder .PlanSelect ,
625
+ FullQuery : & sqlparser.ParsedQuery {Query : `select * from something where something=123` }, // 43 length
626
+ },
627
+ }
628
+ fakeInsertPlan := & TabletPlan {
629
+ Plan : & planbuilder.Plan {
630
+ PlanID : planbuilder .PlanInsert ,
631
+ FullQuery : & sqlparser.ParsedQuery {Query : `insert into something (id, msg) values(123, 'hello world!')` }, // 59 length
632
+ },
633
+ }
622
634
testcases := []struct {
623
635
name string
624
- planType planbuilder. PlanType
636
+ plan * TabletPlan
625
637
tableName string
626
638
tabletType topodata.TabletType
627
639
queryCount int64
@@ -638,12 +650,13 @@ func TestAddQueryStats(t *testing.T) {
638
650
expectedQueryTimes string
639
651
expectedQueryRowsAffected string
640
652
expectedQueryRowsReturned string
653
+ expectedQueryTextCharsProcessed string
641
654
expectedQueryErrorCounts string
642
655
expectedQueryErrorCountsWithCode string
643
656
}{
644
657
{
645
658
name : "select query" ,
646
- planType : planbuilder . PlanSelect ,
659
+ plan : fakeSelectPlan ,
647
660
tableName : "A" ,
648
661
tabletType : topodata .TabletType_PRIMARY ,
649
662
queryCount : 1 ,
@@ -658,12 +671,13 @@ func TestAddQueryStats(t *testing.T) {
658
671
expectedQueryTimes : `{"A.Select": 10}` ,
659
672
expectedQueryRowsAffected : `{}` ,
660
673
expectedQueryRowsReturned : `{"A.Select": 15}` ,
674
+ expectedQueryTextCharsProcessed : `{"A.Select": 43}` ,
661
675
expectedQueryErrorCounts : `{"A.Select": 0}` ,
662
676
expectedQueryErrorCountsWithCode : `{}` ,
663
677
expectedQueryCountsWithTableType : `{"A.Select.PRIMARY": 1}` ,
664
678
}, {
665
679
name : "select query against a replica" ,
666
- planType : planbuilder . PlanSelect ,
680
+ plan : fakeSelectPlan ,
667
681
tableName : "A" ,
668
682
tabletType : topodata .TabletType_REPLICA ,
669
683
queryCount : 1 ,
@@ -678,12 +692,13 @@ func TestAddQueryStats(t *testing.T) {
678
692
expectedQueryTimes : `{"A.Select": 10}` ,
679
693
expectedQueryRowsAffected : `{}` ,
680
694
expectedQueryRowsReturned : `{"A.Select": 15}` ,
695
+ expectedQueryTextCharsProcessed : `{"A.Select": 43}` ,
681
696
expectedQueryErrorCounts : `{"A.Select": 0}` ,
682
697
expectedQueryErrorCountsWithCode : `{}` ,
683
698
expectedQueryCountsWithTableType : `{"A.Select.REPLICA": 1}` ,
684
699
}, {
685
700
name : "select into query" ,
686
- planType : planbuilder . PlanSelect ,
701
+ plan : fakeSelectPlan ,
687
702
tableName : "A" ,
688
703
tabletType : topodata .TabletType_PRIMARY ,
689
704
queryCount : 1 ,
@@ -698,12 +713,13 @@ func TestAddQueryStats(t *testing.T) {
698
713
expectedQueryTimes : `{"A.Select": 10}` ,
699
714
expectedQueryRowsAffected : `{"A.Select": 15}` ,
700
715
expectedQueryRowsReturned : `{"A.Select": 0}` ,
716
+ expectedQueryTextCharsProcessed : `{"A.Select": 43}` ,
701
717
expectedQueryErrorCounts : `{"A.Select": 0}` ,
702
718
expectedQueryErrorCountsWithCode : `{}` ,
703
719
expectedQueryCountsWithTableType : `{"A.Select.PRIMARY": 1}` ,
704
720
}, {
705
721
name : "error" ,
706
- planType : planbuilder . PlanSelect ,
722
+ plan : fakeSelectPlan ,
707
723
tableName : "A" ,
708
724
tabletType : topodata .TabletType_PRIMARY ,
709
725
queryCount : 1 ,
@@ -718,12 +734,13 @@ func TestAddQueryStats(t *testing.T) {
718
734
expectedQueryTimes : `{"A.Select": 10}` ,
719
735
expectedQueryRowsAffected : `{}` ,
720
736
expectedQueryRowsReturned : `{"A.Select": 0}` ,
737
+ expectedQueryTextCharsProcessed : `{"A.Select": 43}` ,
721
738
expectedQueryErrorCounts : `{"A.Select": 1}` ,
722
739
expectedQueryErrorCountsWithCode : `{"A.Select.RESOURCE_EXHAUSTED": 1}` ,
723
740
expectedQueryCountsWithTableType : `{"A.Select.PRIMARY": 1}` ,
724
741
}, {
725
742
name : "insert query" ,
726
- planType : planbuilder . PlanInsert ,
743
+ plan : fakeInsertPlan ,
727
744
tableName : "A" ,
728
745
tabletType : topodata .TabletType_PRIMARY ,
729
746
queryCount : 1 ,
@@ -738,12 +755,13 @@ func TestAddQueryStats(t *testing.T) {
738
755
expectedQueryTimes : `{"A.Insert": 10}` ,
739
756
expectedQueryRowsAffected : `{"A.Insert": 15}` ,
740
757
expectedQueryRowsReturned : `{}` ,
758
+ expectedQueryTextCharsProcessed : `{"A.Insert": 59}` ,
741
759
expectedQueryErrorCounts : `{"A.Insert": 0}` ,
742
760
expectedQueryErrorCountsWithCode : `{}` ,
743
761
expectedQueryCountsWithTableType : `{"A.Insert.PRIMARY": 1}` ,
744
762
}, {
745
763
name : "select query with per workload metrics" ,
746
- planType : planbuilder . PlanSelect ,
764
+ plan : fakeSelectPlan ,
747
765
tableName : "A" ,
748
766
tabletType : topodata .TabletType_PRIMARY ,
749
767
queryCount : 1 ,
@@ -758,12 +776,13 @@ func TestAddQueryStats(t *testing.T) {
758
776
expectedQueryTimes : `{"A.Select.some-workload": 10}` ,
759
777
expectedQueryRowsAffected : `{}` ,
760
778
expectedQueryRowsReturned : `{"A.Select.some-workload": 15}` ,
779
+ expectedQueryTextCharsProcessed : `{"A.Select.some-workload": 43}` ,
761
780
expectedQueryErrorCounts : `{"A.Select.some-workload": 0}` ,
762
781
expectedQueryErrorCountsWithCode : `{}` ,
763
782
expectedQueryCountsWithTableType : `{"A.Select.PRIMARY": 1}` ,
764
783
}, {
765
784
name : "select into query with per workload metrics" ,
766
- planType : planbuilder . PlanSelect ,
785
+ plan : fakeSelectPlan ,
767
786
tableName : "A" ,
768
787
tabletType : topodata .TabletType_PRIMARY ,
769
788
queryCount : 1 ,
@@ -778,12 +797,13 @@ func TestAddQueryStats(t *testing.T) {
778
797
expectedQueryTimes : `{"A.Select.some-workload": 10}` ,
779
798
expectedQueryRowsAffected : `{"A.Select.some-workload": 15}` ,
780
799
expectedQueryRowsReturned : `{"A.Select.some-workload": 0}` ,
800
+ expectedQueryTextCharsProcessed : `{"A.Select.some-workload": 43}` ,
781
801
expectedQueryErrorCounts : `{"A.Select.some-workload": 0}` ,
782
802
expectedQueryErrorCountsWithCode : `{}` ,
783
803
expectedQueryCountsWithTableType : `{"A.Select.PRIMARY": 1}` ,
784
804
}, {
785
805
name : "error with per workload metrics" ,
786
- planType : planbuilder . PlanSelect ,
806
+ plan : fakeSelectPlan ,
787
807
tableName : "A" ,
788
808
tabletType : topodata .TabletType_PRIMARY ,
789
809
queryCount : 1 ,
@@ -798,12 +818,13 @@ func TestAddQueryStats(t *testing.T) {
798
818
expectedQueryTimes : `{"A.Select.some-workload": 10}` ,
799
819
expectedQueryRowsAffected : `{}` ,
800
820
expectedQueryRowsReturned : `{"A.Select.some-workload": 0}` ,
821
+ expectedQueryTextCharsProcessed : `{"A.Select.some-workload": 43}` ,
801
822
expectedQueryErrorCounts : `{"A.Select.some-workload": 1}` ,
802
823
expectedQueryErrorCountsWithCode : `{"A.Select.RESOURCE_EXHAUSTED": 1}` ,
803
824
expectedQueryCountsWithTableType : `{"A.Select.PRIMARY": 1}` ,
804
825
}, {
805
826
name : "insert query with per workload metrics" ,
806
- planType : planbuilder . PlanInsert ,
827
+ plan : fakeInsertPlan ,
807
828
tableName : "A" ,
808
829
tabletType : topodata .TabletType_PRIMARY ,
809
830
queryCount : 1 ,
@@ -818,6 +839,7 @@ func TestAddQueryStats(t *testing.T) {
818
839
expectedQueryTimes : `{"A.Insert.some-workload": 10}` ,
819
840
expectedQueryRowsAffected : `{"A.Insert.some-workload": 15}` ,
820
841
expectedQueryRowsReturned : `{}` ,
842
+ expectedQueryTextCharsProcessed : `{"A.Insert.some-workload": 59}` ,
821
843
expectedQueryErrorCounts : `{"A.Insert.some-workload": 0}` ,
822
844
expectedQueryErrorCountsWithCode : `{}` ,
823
845
expectedQueryCountsWithTableType : `{"A.Insert.PRIMARY": 1}` ,
@@ -833,12 +855,13 @@ func TestAddQueryStats(t *testing.T) {
833
855
env := tabletenv .NewEnv (vtenv .NewTestEnv (), cfg , "TestAddQueryStats_" + testcase .name )
834
856
se := schema .NewEngine (env )
835
857
qe := NewQueryEngine (env , se )
836
- qe .AddStats (testcase .planType , testcase .tableName , testcase .workload , testcase .tabletType , testcase .queryCount , testcase .duration , testcase .mysqlTime , testcase .rowsAffected , testcase .rowsReturned , testcase .errorCount , testcase .errorCode )
858
+ qe .AddStats (testcase .plan , testcase .tableName , testcase .workload , testcase .tabletType , testcase .queryCount , testcase .duration , testcase .mysqlTime , testcase .rowsAffected , testcase .rowsReturned , testcase .errorCount , testcase .errorCode )
837
859
assert .Equal (t , testcase .expectedQueryCounts , qe .queryCounts .String ())
838
860
assert .Equal (t , testcase .expectedQueryCountsWithTableType , qe .queryCountsWithTabletType .String ())
839
861
assert .Equal (t , testcase .expectedQueryTimes , qe .queryTimes .String ())
840
862
assert .Equal (t , testcase .expectedQueryRowsAffected , qe .queryRowsAffected .String ())
841
863
assert .Equal (t , testcase .expectedQueryRowsReturned , qe .queryRowsReturned .String ())
864
+ assert .Equal (t , testcase .expectedQueryTextCharsProcessed , qe .queryTextCharsProcessed .String ())
842
865
assert .Equal (t , testcase .expectedQueryErrorCounts , qe .queryErrorCounts .String ())
843
866
assert .Equal (t , testcase .expectedQueryErrorCountsWithCode , qe .queryErrorCountsWithCode .String ())
844
867
})
0 commit comments