summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-01 15:08:46 +0800
committerchenzizhan <[email protected]>2024-07-01 15:08:46 +0800
commitd6535f9695fe987b04fa41045fd74c508b338dad (patch)
tree6e0a41abc0f8d057adb4c2166b594d13fad4846c
parent1f9f281408e905d0fbdddd5002b0a68c934c2347 (diff)
fix ci because hll count change and metric config diff stop merging
-rw-r--r--src/fieldstat.c1
-rw-r--r--test/test_fieldstat_exporter.py5
-rw-r--r--test/test_fuzz_test.cpp2
-rw-r--r--test/test_write_json_file.cpp39
4 files changed, 12 insertions, 35 deletions
diff --git a/src/fieldstat.c b/src/fieldstat.c
index ff75364..15a1eeb 100644
--- a/src/fieldstat.c
+++ b/src/fieldstat.c
@@ -950,6 +950,7 @@ int fieldstat_merge(struct fieldstat *instance, struct fieldstat *src)
if (metric_get_type(metric_src) != metric_get_type(metric_dst) ||
strcmp(metric_get_name(metric_src), metric_get_name(metric_dst)) != 0
) {
+ assert(0);
return FS_ERR_INVALID_PARAM;
}
}
diff --git a/test/test_fieldstat_exporter.py b/test/test_fieldstat_exporter.py
index 47be003..232f4b5 100644
--- a/test/test_fieldstat_exporter.py
+++ b/test/test_fieldstat_exporter.py
@@ -17,6 +17,7 @@ from prettytable import PrettyTable,NONE,HEADER
import os
current_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(current_path + '/../../src/exporter')
+sys.path.append('/home/chenzizhan/heavykeeperczz/FieldStat/src/exporter')
from fieldstat_exporter import FieldstatAPI
@@ -153,7 +154,7 @@ class TestPrometheusExporter(unittest.TestCase):
metric = self.prom._PrometheusExporter__build_type_hll(name, tags, value)
- self.assertEqual(metric, "tsg_master_log{policy_id=\"1\",app_name=\"-\"} 62.61\n")
+ self.assertEqual(metric, "tsg_master_log{policy_id=\"1\",app_name=\"-\"} 93.61\n")
def test__build_metrics(self):
@@ -186,7 +187,7 @@ class TestPrometheusExporter(unittest.TestCase):
"timestamp_ms_delta": 100010
}
metrics = self.prom._PrometheusExporter__build_metrics(hll_dict)
- self.assertEqual(metrics, "external_ip{rule_id=\"1\",app_name=\"-\"} 62.61\n")
+ self.assertEqual(metrics, "external_ip{rule_id=\"1\",app_name=\"-\"} 93.61\n")
hist_dict = {"name": "-",
"tags": {
diff --git a/test/test_fuzz_test.cpp b/test/test_fuzz_test.cpp
index d5add15..ac6cdd2 100644
--- a/test/test_fuzz_test.cpp
+++ b/test/test_fuzz_test.cpp
@@ -377,7 +377,6 @@ TEST(Fuzz_test, simple_one_for_perf)
const int FLOW_NUM = 50000;
const int CELL_MAX = 50;
const int TEST_ROUND = 500000;
- const int OUT_GAP = 10000;
struct fieldstat *master = fieldstat_new();
Fieldstat_tag_list_wrapper *shared_tags[CUBE_NUM];
@@ -402,7 +401,6 @@ TEST(Fuzz_test, simple_one_for_perf)
struct fieldstat *instance = master;
clock_t start = clock();
- int next_shared_tag_value = CUBE_NUM;
printf("press any key to start\n");
getchar();
diff --git a/test/test_write_json_file.cpp b/test/test_write_json_file.cpp
index 6d6131c..f4dd7f8 100644
--- a/test/test_write_json_file.cpp
+++ b/test/test_write_json_file.cpp
@@ -22,7 +22,7 @@ extern "C" {
extern char *fs_easy_output_to_json(struct fieldstat_easy *fs, const struct timeval *timestamp, const struct timeval *timestamp_delta);
}
-static struct fieldstat_easy *get_hist_fieldstat_easy()
+[[gnu::unused]] static struct fieldstat_easy *get_hist_fieldstat_easy()
{
struct fieldstat_tag global_tags[2];
struct fieldstat_tag cell_tags[2];
@@ -58,8 +58,7 @@ static struct fieldstat_easy *get_hist_fieldstat_easy()
return fse;
}
-static struct fieldstat *get_hll_fieldsstat()
-{
+static void write_hll(struct fieldstat *instance) {
struct fieldstat_tag shared_tags[1];
shared_tags[0].key = "rule_id";
@@ -67,9 +66,6 @@ static struct fieldstat *get_hll_fieldsstat()
shared_tags[0].value_longlong = 1;
const char *hll_name[] = {"external_ip", "internal_ip", "acc_ip"};
-
- struct fieldstat *instance = fieldstat_new();
- EXPECT_NE(nullptr, instance);
int cube_id = fieldstat_create_cube(instance, shared_tags, 1,
SAMPLING_MODE_COMPREHENSIVE, 100);
@@ -85,15 +81,10 @@ static struct fieldstat *get_hll_fieldsstat()
int ret = fieldstat_hll_add(instance, cube_id, hll_id, NULL, 0, ip_str, strlen(ip_str));
EXPECT_EQ(0, ret);
}
-
}
-
- return instance;
}
-
-static struct fieldstat *get_hist_fieldstat()
-{
+void write_histogram(struct fieldstat *instance) {
struct fieldstat_tag shared_tags[2];
struct fieldstat_tag cell_tags[2];
@@ -116,11 +107,8 @@ static struct fieldstat *get_hist_fieldstat()
"bye/udp", "oth_mtd/udp"};
- struct fieldstat *instance = fieldstat_new();
- EXPECT_NE(nullptr, instance);
int cube_id = fieldstat_create_cube(instance, shared_tags, 2,
SAMPLING_MODE_COMPREHENSIVE, 100);
- EXPECT_EQ(0, cube_id);
for(unsigned int i = 0; i < sizeof(hist_names)/sizeof(hist_names[0]); i++)
{
@@ -131,8 +119,6 @@ static struct fieldstat *get_hist_fieldstat()
fieldstat_hist_record(instance, cube_id, hist_id, cell_tags, 2, i*100 + j);
}
}
-
- return instance;
}
// static struct fieldstat_easy *get_table_fieldstat_easy()
@@ -179,8 +165,7 @@ void fieldstat_easy_to_file(struct fieldstat_easy *fse, const char *file_path)
fieldstat_easy_free(fse); // only by free to stop exporting
}
-static struct fieldstat *get_table_fieldstat()
-{
+void write_table(struct fieldstat *instance) {
struct fieldstat_tag shared_tags[2];
shared_tags[0].key = "policy_id";
shared_tags[0].type = TAG_INTEGER;
@@ -200,12 +185,8 @@ static struct fieldstat *get_table_fieldstat()
cell_tags.type = TAG_CSTRING;
cell_tags.value_str = "true";
- struct fieldstat *instance = fieldstat_new();
- EXPECT_NE(nullptr, instance);
-
int cube_id = fieldstat_create_cube(instance, shared_tags, 2,
SAMPLING_MODE_COMPREHENSIVE, 100);
- EXPECT_EQ(0, cube_id);
int counter_id_0 = fieldstat_register_counter(instance, "T_success_log");
@@ -218,8 +199,6 @@ static struct fieldstat *get_table_fieldstat()
if(i < 5)
fieldstat_counter_incrby(instance, cube_id, counter_id_1, &cell_tags, 1, 2);
}
-
- return instance;
}
static int write_json_to_file(const char *filename, char *json_str)
@@ -239,13 +218,11 @@ TEST(ExporterLocal, TableBuild)
{
struct timeval current = {100, 10000};
struct fieldstat *merger = fieldstat_new();
- struct fieldstat *hll = get_hll_fieldsstat();
- struct fieldstat *hist = get_hist_fieldstat();
- struct fieldstat *table = get_table_fieldstat();
- fieldstat_merge(merger, hll);
- fieldstat_merge(merger, hist);
- fieldstat_merge(merger, table);
+ write_hll(merger);
+ write_histogram(merger);
+ write_table(merger);
+
struct fieldstat_json_exporter *exporter = fieldstat_json_exporter_new();
fieldstat_json_exporter_enable_delta(exporter);
char *str_json = fieldstat_json_exporter_export(exporter, merger, &current);