@@ -309,6 +309,140 @@ def s4_ts6191_check_dual_replica(self):
309309 self .clearEnv ()
310310 raise Exception (repr (e ))
311311
312+ def s5_check_timeseries_exclude_systable (self ):
313+ """
314+ 测试计算测点时排除系统表的功能
315+
316+ 排除的系统表为超级表:
317+ 1. log 库中的超级表 (tkLogStb)
318+ 2. audit 库中的超级表 (tkAuditStb),audit 库的判断条件:
319+ - 数据库名为 audit
320+ - 或者建库语句中指明 is_audit 1
321+ """
322+ # log 库的系统表超级表列表
323+ tkLogStb = [
324+ "cluster_info" , "data_dir" , "dnodes_info" , "d_info" , "grants_info" ,
325+ "keeper_monitor" , "logs" , "log_dir" , "log_summary" , "m_info" ,
326+ "taosadapter_restful_http_request_fail" , "taosadapter_restful_http_request_in_flight" ,
327+ "taosadapter_restful_http_request_summary_milliseconds" , "taosadapter_restful_http_request_total" ,
328+ "taosadapter_system_cpu_percent" , "taosadapter_system_mem_percent" , "temp_dir" , "vgroups_info" ,
329+ "vnodes_role" , "taosd_dnodes_status" , "adapter_conn_pool" , "taosd_vnodes_info" , "taosd_dnodes_metrics" ,
330+ "taosd_vgroups_info" , "taos_sql_req" , "taosd_mnodes_info" , "adapter_c_interface" , "taosd_cluster_info" ,
331+ "taosd_sql_req" , "taosd_dnodes_info" , "adapter_requests" , "taosd_write_metrics" , "adapter_status" ,
332+ "taos_slow_sql" , "taos_slow_sql_detail" , "taosd_cluster_basic" , "taosd_dnodes_data_dirs" ,
333+ "taosd_dnodes_log_dirs" , "xnode_agent_activities" , "xnode_task_activities" , "xnode_task_metrics" ,
334+ "taosx_task_csv" , "taosx_task_progress" , "taosx_task_kinghist" , "taosx_task_tdengine2" ,
335+ "taosx_task_tdengine3" , "taosx_task_opc_da" , "taosx_task_opc_ua" , "taosx_task_kafka" ,
336+ "taosx_task_influxdb" , "taosx_task_mqtt" , "taosx_task_avevahistorian" , "taosx_task_opentsdb" ,
337+ "taosx_task_mysql" , "taosx_task_postgres" , "taosx_task_oracle" , "taosx_task_mssql" ,
338+ "taosx_task_mongodb" , "taosx_task_sparkplugb" , "taosx_task_orc" , "taosx_task_pulsar" , "taosx_task_pspace"
339+ ]
340+
341+ # audit 库的系统表超级表列表
342+ tkAuditStb = ["operations" ]
343+
344+ tdLog .printNoPrefix ("======== test timeseries exclude systable: " )
345+ try :
346+ # 获取当前的 timeseries 数量作为基准
347+ tss_grant_base = self .getShowGrantsTimeSeries ()
348+ tdLog .info (f"Base timeseries count: { tss_grant_base } " )
349+
350+ # ========== 测试1: 验证 audit 库中的 operations 表不计入 timeseries ==========
351+ tdLog .printNoPrefix ("======== test1: audit db operations table should be excluded" )
352+ # audit 库已在 s0_five_dnode_one_mnode 中创建,包含 operations 超级表
353+ # 验证 audit 库中的 operations 子表不计入 timeseries
354+ tdSql .execute ("use audit" )
355+ tdSql .execute ("insert into t_operations_abc values(now, 1, 100, 10, 1.0, 2.0)" )
356+ tdSql .execute ("create table t_operations_def using operations tags(2)" )
357+ tdSql .execute ("insert into t_operations_def values(now, 2, 200, 20, 2.0, 3.0)" )
358+
359+ # 验证 timeseries 数量不变(audit 库的 operations 表应被排除)
360+ self .checkGrantsTimeSeries ("audit db operations should be excluded" , tss_grant_base )
361+ tdLog .info ("test1 passed: audit db operations table excluded from timeseries count" )
362+
363+ # ========== 测试2: 验证 is_audit 标记的库中的 operations 表不计入 timeseries ==========
364+ tdLog .printNoPrefix ("======== test2: is_audit db operations table should be excluded" )
365+ tdSql .execute ("drop database if exists audit_test" )
366+ tdSql .execute ("create database audit_test is_audit 1 keep 36500d" )
367+ tdSql .execute ("use audit_test" )
368+ # 在 is_audit 库中创建 operations 超级表和子表
369+ tdSql .execute ("create table operations(ts timestamp, c0 int primary key, c1 bigint, c2 int, c3 float, c4 double) tags(t0 bigint unsigned)" )
370+ tdSql .execute ("create table t_ops_1 using operations tags(1)" )
371+ tdSql .execute ("insert into t_ops_1 values(now, 1, 100, 10, 1.0, 2.0)" )
372+ tdSql .execute ("create table t_ops_2 using operations tags(2)" )
373+ tdSql .execute ("insert into t_ops_2 values(now, 2, 200, 20, 2.0, 3.0)" )
374+
375+ # 验证 timeseries 数量不变(is_audit 库的 operations 表应被排除)
376+ self .checkGrantsTimeSeries ("is_audit db operations should be excluded" , tss_grant_base )
377+ tdLog .info ("test2 passed: is_audit db operations table excluded from timeseries count" )
378+
379+ # ========== 测试3: 验证 is_audit 库中的非 operations 表正常计入 timeseries ==========
380+ tdLog .printNoPrefix ("======== test3: is_audit db non-operations table should be counted" )
381+ tdSql .execute ("use audit_test" )
382+ # 在 is_audit 库中创建非 operations 的普通表
383+ tdSql .execute ("create table normal_stb(ts timestamp, c0 int, c1 bigint, c2 int) tags(t0 int)" )
384+ tdSql .execute ("create table t_normal_1 using normal_stb tags(1)" )
385+ tdSql .execute ("insert into t_normal_1 values(now, 1, 100, 10)" )
386+ tss_grant_expected = tss_grant_base + 3 # 3 columns (excluding ts)
387+ self .checkGrantsTimeSeries ("is_audit db non-operations table should be counted" , tss_grant_expected )
388+ tdLog .info ("test3 passed: is_audit db non-operations table counted in timeseries" )
389+
390+ # ========== 测试4: 验证普通库中的 operations 表正常计入 timeseries ==========
391+ tdLog .printNoPrefix ("======== test4: normal db operations table should be counted" )
392+ tdSql .execute ("drop database if exists normal_test" )
393+ tdSql .execute ("create database normal_test keep 36500d" )
394+ tdSql .execute ("use normal_test" )
395+ # 在普通库中创建同名的 operations 超级表和子表
396+ tdSql .execute ("create table operations(ts timestamp, c0 int primary key, c1 bigint, c2 int, c3 float, c4 double) tags(t0 bigint unsigned)" )
397+ tdSql .execute ("create table t_ops_normal_1 using operations tags(1)" )
398+ tdSql .execute ("insert into t_ops_normal_1 values(now, 1, 100, 10, 1.0, 2.0)" )
399+ tss_grant_expected += 5 # 5 columns (excluding ts)
400+ self .checkGrantsTimeSeries ("normal db operations table should be counted" , tss_grant_expected )
401+ tdLog .info ("test4 passed: normal db operations table counted in timeseries" )
402+
403+ # ========== 测试5: 验证 log 库中的系统表不计入 timeseries ==========
404+ tdLog .printNoPrefix ("======== test5: log db system tables should be excluded" )
405+ tdSql .execute ("drop database if exists log" )
406+ tdSql .execute ("create database log keep 36500d" )
407+ tdSql .execute ("use log" )
408+ # 在 log 库中创建部分系统表超级表和子表
409+ test_log_stbs = ["cluster_info" , "dnodes_info" , "grants_info" , "logs" ]
410+ for stb_name in test_log_stbs :
411+ tdSql .execute (f"create table { stb_name } (ts timestamp, c0 int, c1 bigint, c2 int, c3 float, c4 double) tags(t0 bigint unsigned)" )
412+ tdSql .execute (f"create table t_{ stb_name } _1 using { stb_name } tags(1)" )
413+ tdSql .execute (f"insert into t_{ stb_name } _1 values(now, 1, 100, 10, 1.0, 2.0)" )
414+
415+ # 验证 timeseries 数量不变(log 库的系统表应被排除)
416+ self .checkGrantsTimeSeries ("log db system tables should be excluded" , tss_grant_expected )
417+ tdLog .info ("test5 passed: log db system tables excluded from timeseries count" )
418+
419+ # ========== 测试6: 验证 log 库中的非系统表正常计入 timeseries ==========
420+ tdLog .printNoPrefix ("======== test6: log db non-system table should be counted" )
421+ tdSql .execute ("use log" )
422+ # 在 log 库中创建非系统表的普通表
423+ tdSql .execute ("create table user_defined_stb(ts timestamp, c0 int, c1 bigint, c2 int) tags(t0 int)" )
424+ tdSql .execute ("create table t_user_1 using user_defined_stb tags(1)" )
425+ tdSql .execute ("insert into t_user_1 values(now, 1, 100, 10)" )
426+ tss_grant_expected += 3 # 3 columns (excluding ts)
427+ self .checkGrantsTimeSeries ("log db non-system table should be counted" , tss_grant_expected )
428+ tdLog .info ("test6 passed: log db non-system table counted in timeseries" )
429+
430+ # ========== 清理测试数据 ==========
431+ tdLog .printNoPrefix ("======== cleanup test databases" )
432+ tdSql .execute ("drop database if exists audit_test" )
433+ tdSql .execute ("drop database if exists normal_test" )
434+ tdSql .execute ("drop database if exists log" )
435+
436+ # 验证清理后 timeseries 恢复到基准值
437+ self .checkGrantsTimeSeries ("cleanup and verify base timeseries" , tss_grant_base )
438+ tdLog .info ("cleanup completed, timeseries restored to base count" )
439+
440+ tdLog .printNoPrefix ("======== all s5_check_timeseries_exclude_systable tests passed!" )
441+
442+ except Exception as e :
443+ self .clearEnv ()
444+ raise Exception (repr (e ))
445+
312446 def test_grant (self ):
313447 """summary: xxx
314448
@@ -343,6 +477,7 @@ def test_grant(self):
343477 self .s2_check_show_grants_ungranted ()
344478 self .s3_check_show_grants_granted ()
345479 self .s4_ts6191_check_dual_replica ()
480+ self .s5_check_timeseries_exclude_systable ()
346481
347482 self .clearEnv ()
348483
0 commit comments