from os import path import sys pa = path.abspath(path.join(path.dirname(__file__), '../..')) sys.path.append(pa) from datasdk.config import config from datasdk.utils import o11y,utils from datasdk.sources import metrics,slowlog import unittest class TestUtilsMethods(unittest.TestCase): def test_evn2Ty(self): self.assertEqual(utils.env2BizType(config.Env.prod,False), 'tidbcloud') def test_getO11yClusterInfo(self): cfg = config.Config(config.Env.prod,"Sd4aekPCa5nMUSQBIvf8eGSL895WtV4o","-SLP5UvxJdwGbVaKupxgv53T6otXguApPoG0fBsWCIqDG8_TuvlYnlkhPQHcWaKT") # metric=metrics.Metrics(cfg) # cluster=metric.getMetrics("1379661944621804065",config.RulesConfig([config.Rule("tidb_executor_statement_total",'sum(rate(tidb_executor_statement_total{type=~"Insert|Delete|Select|Update|Replace"}[2m])) by (type)')]),1680624000,1680710399,120) # metric.writeToCSV(cluster,"./1379661944621804065_tidb_executor_statement_total_405.csv") # cluster=metric.getMetrics("1379661944621804065",config.RulesConfig([config.Rule("tidb_server_query_total",'sum(rate(tidb_server_query_total{type=~"StmtExecute|StmtFetch|StmtClose|StmtPrepare|StmtSendLongData|Query"}[2m])) by (type)')]),1680624000,1680710399,120) # metric.writeToCSV(cluster,"./1379661944621804065_tidb_server_query_total_405.csv") # cluster=metric.getMetrics("1379661944621804065",config.RulesConfig([config.Rule("tidb_server_execute_error_total",'sum(increase(tidb_server_execute_error_total{}[1m])) by (type, instance)')]),1680624000,1680710399,120) # metric.writeToCSV(cluster,"./1379661944621804065_tidb_server_execute_error_total_405.csv") # cluster=metric.getMetrics("1379661944621804065",config.RulesConfig([config.Rule("tidb_server_handle_query_duration_seconds_999",'histogram_quantile(0.999, sum(rate(tidb_server_handle_query_duration_seconds_bucket{}[2m])) by (le))'),config.Rule("tidb_server_handle_query_duration_seconds_99",'histogram_quantile(0.99, sum(rate(tidb_server_handle_query_duration_seconds_bucket{}[2m])) by (le))'),config.Rule("tidb_server_handle_query_duration_seconds_95",'histogram_quantile(0.95, sum(rate(tidb_server_handle_query_duration_seconds_bucket{}[2m])) by (le))'),config.Rule("tidb_server_handle_query_duration_seconds_avg",'sum (rate(tidb_server_handle_query_duration_seconds_sum[2m])/rate(tidb_server_handle_query_duration_seconds_count[2m])) by (sql_type)')]),1680624000,1680710399,120) # metric.writeToCSV(cluster,"./1379661944621804065_tidb_server_handle_query_duration_seconds_405.csv") # cluster=metric.getMetrics("1379661944621804065",config.RulesConfig([config.Rule("tidb_server_connections",'tidb_server_connections')]),1680624000,1680710399,120) # metric.writeToCSV(cluster,"./1379661944621804065_tidb_server_connections_405.csv") # cluster=metric.getMetrics("1379661944621804065",config.RulesConfig([config.Rule("tikv_store_size_bytes",'sum(tikv_store_size_bytes{type="used"}) by (instance)')]),1680624000,1680710399,120) # metric.writeToCSV(cluster,"./1379661944621804065_tikv_store_size_bytes_405.csv") slow=slowlog.SlowLog(cfg) start=1699718400 end=1699804800 cluster=slow.getSlowLog("1379661944642684098",True,start,end) slow.writeToLog(cluster,"./1379661944642684098_slowlog_{}_{}.log".format(start,end)) if __name__ == '__main__': unittest.main()