MCPcopy Create free account
hub / github.com/deepflowio/deepflow / GetExtTables

Function GetExtTables

server/querier/engine/clickhouse/common/utils.go:214–257  ·  view source on GitHub ↗
(db, where, queryCacheTTL, orgID string, useQueryCache bool, ctx context.Context, DebugInfo *client.DebugInfo)

Source from the content-addressed store, hash-verified

212}
213
214func GetExtTables(db, where, queryCacheTTL, orgID string, useQueryCache bool, ctx context.Context, DebugInfo *client.DebugInfo) (values []interface{}) {
215 chClient := client.Client{
216 Host: config.Cfg.Clickhouse.Host,
217 Port: config.Cfg.Clickhouse.Port,
218 UserName: config.Cfg.Clickhouse.User,
219 Password: config.Cfg.Clickhouse.Password,
220 DB: db,
221 Context: ctx,
222 }
223 sql := ""
224 if slices.Contains([]string{DB_NAME_EXT_METRICS, DB_NAME_DEEPFLOW_ADMIN, DB_NAME_DEEPFLOW_TENANT, DB_NAME_PROMETHEUS}, db) {
225 if where != "" {
226 sql = fmt.Sprintf("SELECT table FROM flow_tag.%s_custom_field ", db) + " WHERE " + strings.Replace(where, " name ", " table ", -1) + " GROUP BY table"
227 } else {
228 sql = fmt.Sprintf("SELECT table FROM flow_tag.%s_custom_field GROUP BY table", db)
229 }
230 chClient.DB = "flow_tag"
231 } else {
232 // there is currently no such scene
233 if where != "" {
234 sql = "SHOW TABLES FROM " + db + " WHERE " + where
235 } else {
236 sql = "SHOW TABLES FROM " + db
237 }
238 }
239 // for debug
240 chClient.Debug = client.NewDebug(sql)
241 rst, err := chClient.DoQuery(&client.QueryParams{Sql: sql, UseQueryCache: useQueryCache, QueryCacheTTL: queryCacheTTL, ORGID: orgID})
242 if err != nil {
243 log.Error(err)
244 return nil
245 }
246 if DebugInfo != nil {
247 DebugInfo.Debug = append(DebugInfo.Debug, *chClient.Debug)
248 }
249 for _, _table := range rst.Values {
250 table := _table.([]interface{})[0].(string)
251 if !strings.HasSuffix(table, "_local") {
252 datasources, _ := GetDatasources(db, table, orgID)
253 values = append(values, []interface{}{table, datasources})
254 }
255 }
256 return values
257}
258
259func GetCustomMetrics(orgID string) (map[string]*simplejson.Json, error) {
260 result := make(map[string]*simplejson.Json)

Callers

nothing calls this directly

Calls 5

DoQueryMethod · 0.95
GetDatasourcesFunction · 0.85
ContainsMethod · 0.80
ReplaceMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected