@@ -45,22 +45,72 @@ const (
45
45
initNodeCapacity = 8192
46
46
)
47
47
48
- func Profile (args model.Profile , cfg * config.QuerierConfig ) (result model.ProfileTree , debug interface {}, err error ) {
48
+ func GetAppService (args model.Profile , where string , debugs model.ProfileDebug ) ([]string , model.ProfileDebug , error ) {
49
+ sql := fmt .Sprintf (
50
+ "SELECT app_service FROM %s WHERE %s GROUP BY app_service LIMIT 11" ,
51
+ common .TABLE_PROFILE , where ,
52
+ )
53
+ ckEngine := & clickhouse.CHEngine {DB : common .DATABASE_PROFILE }
54
+ ckEngine .Init ()
55
+ querierArgs := querier_common.QuerierParams {
56
+ DB : common .DATABASE_PROFILE ,
57
+ Sql : sql ,
58
+ Debug : strconv .FormatBool (args .Debug ),
59
+ Context : args .Context ,
60
+ ORGID : args .OrgID ,
61
+ }
62
+
63
+ querierResult , querierDebug , err := ckEngine .ExecuteQuery (& querierArgs )
64
+ profileDebug := NewProfileDebug (sql , querierDebug )
65
+ debugs .QuerierDebug = append (debugs .QuerierDebug , profileDebug )
66
+ appServices := []string {}
67
+ if err != nil {
68
+ log .Errorf ("ExecuteQuery failed: %v" , querierDebug , err )
69
+ return appServices , debugs , err
70
+ }
71
+ values := querierResult .Values
72
+ for _ , value := range values {
73
+ switch valueSlice := value .(type ) {
74
+ case []interface {}:
75
+ appService , ok := valueSlice [0 ].(string )
76
+ if ok {
77
+ appServices = append (appServices , appService )
78
+ }
79
+ }
80
+ }
81
+ return appServices , debugs , nil
82
+ }
83
+
84
+ func Profile (args model.Profile , cfg * config.QuerierConfig ) (model.ProfileTree , interface {}, error ) {
49
85
whereSlice := []string {}
50
86
whereSlice = append (whereSlice , fmt .Sprintf (" time>=%d" , args .TimeStart ))
51
87
whereSlice = append (whereSlice , fmt .Sprintf (" time<=%d" , args .TimeEnd ))
52
- whereSlice = append (whereSlice , fmt .Sprintf (" app_service='%s'" , args .AppService ))
88
+ if args .AppService != "" {
89
+ whereSlice = append (whereSlice , fmt .Sprintf (" app_service='%s'" , args .AppService ))
90
+ }
53
91
whereSlice = append (whereSlice , fmt .Sprintf (" profile_language_type='%s'" , args .ProfileLanguageType ))
54
92
whereSlice = append (whereSlice , fmt .Sprintf (" profile_event_type='%s'" , args .ProfileEventType ))
55
93
if args .TagFilter != "" {
56
94
whereSlice = append (whereSlice , " (" + args .TagFilter + ")" )
57
95
}
58
96
whereSql := strings .Join (whereSlice , " AND" )
59
- return GenerateProfile (args , cfg , whereSql )
97
+ debugs := model.ProfileDebug {}
98
+ if args .AppService == "" {
99
+ appServices , appDebugs , err := GetAppService (args , whereSql , debugs )
100
+ debugs = appDebugs
101
+ if err != nil {
102
+ log .Errorf ("GetAppService failed: %v" , err )
103
+ return model.ProfileTree {}, debugs , err
104
+ }
105
+ if len (appServices ) < 1 || len (appServices ) > 10 {
106
+ return model.ProfileTree {}, debugs , fmt .Errorf ("app_service count %d is invalid" , len (appServices ))
107
+ }
108
+ args .AppService = strings .Join (appServices , ", " )
109
+ }
110
+ return GenerateProfile (args , cfg , whereSql , debugs )
60
111
}
61
112
62
- func GenerateProfile (args model.Profile , cfg * config.QuerierConfig , where string ) (result model.ProfileTree , debug interface {}, err error ) {
63
- debugs := model.ProfileDebug {}
113
+ func GenerateProfile (args model.Profile , cfg * config.QuerierConfig , where string , debugs model.ProfileDebug ) (result model.ProfileTree , debug interface {}, err error ) {
64
114
limitSql := cfg .Profile .FlameQueryLimit
65
115
sql := fmt .Sprintf (
66
116
"SELECT %s, %s FROM %s WHERE %s LIMIT %d" ,
0 commit comments