diff options
| -rw-r--r-- | include/fieldstat/fieldstat_exporter.h | 44 | ||||
| -rw-r--r-- | src/cells/hash_table.c | 2 | ||||
| -rw-r--r-- | src/cells/spread_sketch.c | 1 | ||||
| -rw-r--r-- | src/exporter/cjson_exporter.c | 52 | ||||
| -rw-r--r-- | test/test_easy_fs.cpp | 4 | ||||
| -rw-r--r-- | test/test_exporter_json.cpp | 73 | ||||
| -rw-r--r-- | test/test_merge.cpp | 16 | ||||
| -rw-r--r-- | test/test_metric_hll.cpp | 2 | ||||
| -rw-r--r-- | test/test_performance.cpp | 4 | ||||
| -rw-r--r-- | test/test_register_and_reset.cpp | 20 | ||||
| -rw-r--r-- | test/utils.hpp | 4 |
11 files changed, 189 insertions, 33 deletions
diff --git a/include/fieldstat/fieldstat_exporter.h b/include/fieldstat/fieldstat_exporter.h index 83e4c37..d314ba0 100644 --- a/include/fieldstat/fieldstat_exporter.h +++ b/include/fieldstat/fieldstat_exporter.h @@ -20,13 +20,55 @@ void fieldstat_json_exporter_free(struct fieldstat_json_exporter *exporter); /* Output the fieldstat instance to json string array. User must free the output string. + format: + [ + { + "name":"exporter_name", + "tags":[ + {"device ID":123}, + {"CLIENT IP":"123.1.1.1"} + ], + "fields":[ + {"in_bytes":1024}, + {"in_pkts":123}, + {"sessions":<hll blob base64-encoded string>} + ] + "timestamp_ms":123456789 + }. + { + "name":"exporter_name", + "tags":[ + {"device ID":123}, + {"CLIENT IP":"1.2.3.4"} + ], + "fields":[ + {"in_bytes":1}, + {"in_pkts":2}, + ] + "timestamp_ms":123456789 + } + ] */ char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp); /* - after call fieldstat_json_exporter_export_array, user must free the output array and each string. + after call fieldstat_json_exporter_export_array, user must free the output array and each string. output[0] = + "{"name":"exporter_name", "tags":[{"device ID":123}, {"CLIENT IP":"1.2.3.4"}],"fields":[{"in_bytes":1}, {"in_pkts":2},]"timestamp_ms":123456789}" + The same as every object in the array output by `fieldstat_json_exporter_export`. */ void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp, char ***output, size_t *output_size); +/* +the content is the same, but no nested format. flat format : +{ +"name":"exporter_name", +"device ID":123, +"in_bytes":1, +"timestamp_ms":123456789 +} +do not support fieldstat_json_exporter_enable_delta. + +if a cell has no metric record, the cell will not be exported. (The same as fieldstat_json_exporter_export_array) +*/ void fieldstat_json_exporter_export_flat(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp, char ***output, size_t *output_size); /* let json exporter output delta value by the side of the original value(accumulated). If a cell / metric is new, the delta value is the same as the original value. diff --git a/src/cells/hash_table.c b/src/cells/hash_table.c index 8394565..d6dbfb5 100644 --- a/src/cells/hash_table.c +++ b/src/cells/hash_table.c @@ -18,7 +18,7 @@ struct tag_exdata_item { UT_hash_handle hh; }; -struct hash_table { // todo: 文件改名字 +struct hash_table { struct tag_exdata_item *tag_id_map; int current_cell_num; int max_cell_num; diff --git a/src/cells/spread_sketch.c b/src/cells/spread_sketch.c index e79815b..8ad7c74 100644 --- a/src/cells/spread_sketch.c +++ b/src/cells/spread_sketch.c @@ -12,6 +12,7 @@ #include "exdata.h" // todo:把primary metric 记到sketch 里,且使用特殊的st Hyperloglog +// todo: topk 也是这样 struct entry { int ref_count; diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c index bbe6fd3..1606df5 100644 --- a/src/exporter/cjson_exporter.c +++ b/src/exporter/cjson_exporter.c @@ -1039,3 +1039,55 @@ void fieldstat_json_exporter_enable_delta(struct fieldstat_json_exporter *export } exporter->history = counter_history_new(); } + +void fieldstat_json_exporter_export_flat(const struct fieldstat_json_exporter *exporter, const struct fieldstat *instance, const struct timeval *timestamp, char ***output, size_t *output_size) { + long long timestamp_ms = cal_ms_time(timestamp); + + size_t n_pair; + struct cellwise_rec_for_export *tag_field_pair = read_tag_and_field(instance, &n_pair); + if (tag_field_pair == NULL || n_pair == 0) { + free(tag_field_pair); // tag_field_pair is not NULL when there are registered metrics but no valid cells + *output = NULL; + *output_size = 0; + return; + } + + fieldstat_json_exporter_write_global_tags(exporter, tag_field_pair, n_pair); + + char **cjson_str_arr = (char **)malloc(sizeof(char *) * n_pair); + for (int i = 0; i < n_pair; i++) { + struct cellwise_rec_for_export *current = &tag_field_pair[i]; + struct json_writer *root = current->cjson_tags; + for (int j = 0; j < tag_field_pair[i].n_metric; j++) { + kv_pair_write_to_json(tag_field_pair[i].metric_pairs[j], root); + } + + const char *tmp_name = exporter->name ? exporter->name : DEFAULT_EXPORTER_NAME; + json_writer_str_field(root, "name", tmp_name, strlen(tmp_name)); + json_writer_longlong_field(root, "timestamp_ms", timestamp_ms); + + char *cjson_str; + size_t cjson_str_len; + json_writer_finish(root, &cjson_str, &cjson_str_len); + char *cjson_with_braces = malloc(cjson_str_len + 3); + cjson_with_braces[0] = '{'; + memcpy(cjson_with_braces + 1, cjson_str, cjson_str_len); + cjson_with_braces[cjson_str_len + 1] = '}'; + cjson_with_braces[cjson_str_len + 2] = '\0'; + + cjson_str_arr[i] = cjson_with_braces; + free(cjson_str); + } + + *output = cjson_str_arr; + *output_size = n_pair; + + for (int i = 0; i < n_pair; i++) { + for (int j = 0; j < tag_field_pair[i].n_metric; j++) { + kv_pair_free(tag_field_pair[i].metric_pairs[j]); + } + free(tag_field_pair[i].metric_pairs); + } + + free(tag_field_pair); +}
\ No newline at end of file diff --git a/test/test_easy_fs.cpp b/test/test_easy_fs.cpp index 790f0fd..ded719f 100644 --- a/test/test_easy_fs.cpp +++ b/test/test_easy_fs.cpp @@ -123,7 +123,7 @@ TEST(test_easy_fieldstat, output_to_file) cJSON_Delete(root); // 4th interval: new data, output again - fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_FIELD_VALUE_DOUBLE, 1, 10086); + fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_TAG_DOUBLE, 1, 10086); sleep(2); printf("4th interval\n"); root = read_file(); @@ -183,7 +183,7 @@ TEST(test_easy_fieldstat, output_interval_ok) struct fieldstat_easy *fse = fieldstat_easy_new(10, NULL, NULL, 0); fieldstat_easy_register_histogram(fse, "metric histogram", 1, 10000, 3); // a pretty time consuming metric fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_INT, 1, 1); - fieldstat_easy_histogram_record(fse, 0, 0, &TEST_FIELD_VALUE_DOUBLE, 1, 10); + fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_DOUBLE, 1, 10); fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_STRING, 1, 110); fieldstat_easy_enable_auto_output(fse, FILENAME, 1); diff --git a/test/test_exporter_json.cpp b/test/test_exporter_json.cpp index 8e96e04..8a09b66 100644 --- a/test/test_exporter_json.cpp +++ b/test/test_exporter_json.cpp @@ -727,7 +727,7 @@ TEST(export_test, enable_delta_and_export_instance_with_many_cells_with_global_t int cube_id2 = fieldstat_create_cube(instance, TEST_TAG_SHARED3, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int id_counter2 = fieldstat_register_counter(instance, cube_id2, "counter"); fieldstat_counter_incrby(instance, cube_id2, id_counter2, &TEST_TAG_INT, 1, 21); - fieldstat_counter_incrby(instance, cube_id2, id_counter2, &TEST_FIELD_VALUE_DOUBLE, 1, 22); + fieldstat_counter_incrby(instance, cube_id2, id_counter2, &TEST_TAG_DOUBLE, 1, 22); // export test struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(); @@ -757,14 +757,14 @@ TEST(export_test, enable_delta_and_export_instance_with_many_cells_with_global_t test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 21, 21, root); /* ------------------------------ cube 1 cell 1 ----------------------------- */ root = cJSON_GetArrayItem(root_arr, 3); - tmp_tag_cell = (struct field_list){(struct field *)&TEST_FIELD_VALUE_DOUBLE, 1}; + tmp_tag_cell = (struct field_list){(struct field *)&TEST_TAG_DOUBLE, 1}; test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 22, 22, root); // new turn fieldstat_counter_incrby(instance, cube_id1, id_counter1, &TEST_TAG_INT, 1, 100); fieldstat_counter_incrby(instance, cube_id1, id_counter1, &TEST_TAG_STRING, 1, 200); fieldstat_counter_incrby(instance, cube_id2, id_counter1, &TEST_TAG_INT, 1, 300); - fieldstat_counter_incrby(instance, cube_id2, id_counter1, &TEST_FIELD_VALUE_DOUBLE, 1, 400); + fieldstat_counter_incrby(instance, cube_id2, id_counter1, &TEST_TAG_DOUBLE, 1, 400); cJSON_Delete(root_arr); @@ -793,7 +793,7 @@ TEST(export_test, enable_delta_and_export_instance_with_many_cells_with_global_t test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 321, 300, root); /* ------------------------------ cube 1 cell 1 ----------------------------- */ root = cJSON_GetArrayItem(root_arr, 3); - tmp_tag_cell = (struct field_list){(struct field *)&TEST_FIELD_VALUE_DOUBLE, 1}; + tmp_tag_cell = (struct field_list){(struct field *)&TEST_TAG_DOUBLE, 1}; test_check_delta_for_one_json(&tmp_tag_cell, &tmp_tag_shared, 422, 400, root); cJSON_Delete(root_arr); @@ -964,7 +964,7 @@ TEST(export_test, delta_with_two_instance_different_cell) fieldstat_counter_incrby(instance, 0, id_counter, &TEST_TAG_INT, 1, 123); struct fieldstat *delta = fieldstat_fork(instance); - fieldstat_counter_incrby(delta, 0, id_counter, &TEST_FIELD_VALUE_DOUBLE, 1, 1); + fieldstat_counter_incrby(delta, 0, id_counter, &TEST_TAG_DOUBLE, 1, 1); fieldstat_merge(instance, delta); // export test @@ -1004,6 +1004,67 @@ TEST(export_test, delta_with_two_instance_different_cell) fieldstat_free(delta); } +TEST(export_test, export_flat_null_with_only_global_tag) { + struct fieldstat *instance = fieldstat_new(); + struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(); + fieldstat_json_exporter_set_global_tag(fieldstat_json_exporter, TEST_TAG_GLOBAL, 3); + + char **out_array = NULL; + size_t out_array_len = 0; + fieldstat_json_exporter_export_flat(fieldstat_json_exporter, instance, &TEST_TIMEVAL, &out_array, &out_array_len); + EXPECT_EQ(out_array_len, 0); + EXPECT_EQ(out_array, nullptr); + + fieldstat_json_exporter_free(fieldstat_json_exporter); + free(out_array); + fieldstat_free(instance); +} + +TEST(export_test, export_flat_many_tags_many_cell) { + struct fieldstat *instance = fieldstat_new(); + int cube_id = fieldstat_create_cube(instance, &TEST_TAG_STRING, 1, SAMPLING_MODE_COMPREHENSIVE, 3); + int metric_id = fieldstat_register_counter(instance, cube_id, "counter metric"); + + + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 123); + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 321); + + struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(); + fieldstat_json_exporter_set_global_tag(fieldstat_json_exporter, TEST_TAG_GLOBAL, 3); + + char **out_array = NULL; + size_t out_array_len = 0; + fieldstat_json_exporter_export_flat(fieldstat_json_exporter, instance, &TEST_TIMEVAL, &out_array, &out_array_len); + EXPECT_EQ(out_array_len, 2); + + cJSON *root = cJSON_Parse(out_array[0]); + Fieldstat_tag_list_wrapper cell_dimension = Fieldstat_tag_list_wrapper(&TEST_TAG_LIST_INT); + Fieldstat_tag_list_wrapper cube_dimension = Fieldstat_tag_list_wrapper(&TEST_TAG_LIST_STRING); + Fieldstat_tag_list_wrapper cell_dimension2 = Fieldstat_tag_list_wrapper(&TEST_TAG_LIST_DOUBLE); + + test_check_if_tag_list_is_in_json(root, &cell_dimension); + test_check_if_global_tag_is_in_json(root); + test_check_if_tag_list_is_in_json(root, &cube_dimension); + cJSON *metrics = cJSON_GetObjectItem(root, "counter metric"); + EXPECT_EQ(metrics->valueint, 123); + + cJSON_Delete(root); + root = cJSON_Parse(out_array[1]); + test_check_if_tag_list_is_in_json(root, &cell_dimension2); + test_check_if_global_tag_is_in_json(root); + test_check_if_tag_list_is_in_json(root, &cube_dimension); + metrics = cJSON_GetObjectItem(root, "counter metric"); + EXPECT_EQ(metrics->valueint, 321); + + cJSON_Delete(root); + fieldstat_free(instance); + fieldstat_json_exporter_free(fieldstat_json_exporter); + for (size_t i = 0; i < out_array_len; i++) { + free(out_array[i]); + } + free(out_array); +} + extern "C" { extern int add_object_to_json_array_start(char *buf, int buf_len); extern int add_object_to_json_array_end(char **buf, int buf_len, int start); @@ -1114,7 +1175,7 @@ int main(int argc, char *argv[]) init_histogram_standard_oper(); testing::InitGoogleTest(&argc, argv); - testing::GTEST_FLAG(filter) = "*spreadsketch_sampling"; + testing::GTEST_FLAG(filter) = "*flat*"; int ret = RUN_ALL_TESTS(); hyperloglog_free(g_hll_standard); diff --git a/test/test_merge.cpp b/test/test_merge.cpp index 2fe730e..7bb4732 100644 --- a/test/test_merge.cpp +++ b/test/test_merge.cpp @@ -49,7 +49,7 @@ double merge_test_fieldstat_hll_get(const struct fieldstat *instance, int cube_i TEST(unit_test_merge, cube_shared_tag_mapping_with_new_cube) { struct fieldstat *instance = fieldstat_new(); - (void)fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + (void)fieldstat_create_cube(instance, &TEST_TAG_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int cube_id2 = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int metric_id = fieldstat_register_counter(instance,cube_id2,"metric in cube 2"); fieldstat_counter_incrby(instance, cube_id2, metric_id, &TEST_TAG_STRING, 1, 1); @@ -168,7 +168,7 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a fieldstat_reset(instance); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 2); // 2nd cell - fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 3); // 3rd cell, exceeding the limit 2 + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 3); // 3rd cell, exceeding the limit 2 fieldstat_merge(instance_dest, instance); @@ -197,7 +197,7 @@ TEST(unit_test_merge, new_too_many_cells_on_multiple_metric_given_source_cube_re int metric_id3 = fieldstat_register_counter(instance, cube_id, "metric name3"); fieldstat_counter_incrby(instance, cube_id, metric_id3, &TEST_TAG_INT, 1, 2); // 2nd cell on metric name3, this is a metric dest dont have - fieldstat_counter_incrby(instance, cube_id, metric_id2, &TEST_FIELD_VALUE_DOUBLE, 1, 3); // 3nd cell on metric name2 + fieldstat_counter_incrby(instance, cube_id, metric_id2, &TEST_TAG_DOUBLE, 1, 3); // 3nd cell on metric name2 fieldstat_merge(instance_dest, instance); int *metric_ids = NULL; @@ -315,7 +315,7 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a fieldstat_reset(instance); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 2); // 2nd cell - fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 3); // 3rd cell,bigger than the others, so keep it + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 3); // 3rd cell,bigger than the others, so keep it fieldstat_merge(instance_dest, instance); @@ -578,9 +578,9 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a fieldstat_reset(instance); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_INT, 1, "21", 2); fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_INT, 1, "22", 2); - fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "31", 2); - fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "32", 2); - fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "33", 2); + fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "31", 2); + fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "32", 2); + fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "33", 2); fieldstat_merge(instance_dest, instance); struct field_list *tag_list = NULL; @@ -589,7 +589,7 @@ TEST(unit_test_merge, new_too_many_cells_on_one_metric_given_source_cube_reset_a EXPECT_EQ(n_cell, 2); EXPECT_NEAR(merge_test_fieldstat_hll_get(instance_dest, 0, 0, &tag_list[0]), 3, 0.3); EXPECT_NEAR(merge_test_fieldstat_hll_get(instance_dest, 0, 0, &tag_list[1]), 2, 0.3); - EXPECT_STREQ(tag_list[0].field[0].key, TEST_FIELD_VALUE_DOUBLE.key); + EXPECT_STREQ(tag_list[0].field[0].key, TEST_TAG_DOUBLE.key); EXPECT_STREQ(tag_list[1].field[0].key, TEST_TAG_INT.key); fieldstat_free(instance); diff --git a/test/test_metric_hll.cpp b/test/test_metric_hll.cpp index c96613c..643b70a 100644 --- a/test/test_metric_hll.cpp +++ b/test/test_metric_hll.cpp @@ -74,7 +74,7 @@ TEST(metric_test_hll, add_with_tags) { struct fieldstat *instance = test_init_standard_instance_one_cube_one_metric_one_cell_hll(); fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_TAG_INT, 1); - fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_FIELD_VALUE_DOUBLE, 1); + fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_TAG_DOUBLE, 1); fieldstat_hll_add_field(instance, 0, 0, &TEST_TAG_INT, 1, &TEST_TAG_STRING, 1); test_assert_standard_instance(instance); diff --git a/test/test_performance.cpp b/test/test_performance.cpp index 3a9ef83..b1ada45 100644 --- a/test/test_performance.cpp +++ b/test/test_performance.cpp @@ -357,7 +357,7 @@ TEST(test_performance, performance_test_add_cells_histogram_record_5tags) struct field fields[5]; fields[0] = TEST_TAG_INT; fields[1] = TEST_TAG_STRING; - fields[2] = TEST_FIELD_VALUE_DOUBLE; + fields[2] = TEST_TAG_DOUBLE; fields[3] = TEST_TAG_INT; fields[4] = TEST_TAG_INT; clock_t start = clock(); @@ -385,7 +385,7 @@ TEST(test_performance, performance_test_add_cells_hll_add_5tags) struct field fields[5]; fields[0] = TEST_TAG_INT; fields[1] = TEST_TAG_STRING; - fields[2] = TEST_FIELD_VALUE_DOUBLE; + fields[2] = TEST_TAG_DOUBLE; fields[3] = TEST_TAG_INT; fields[4] = TEST_TAG_INT; clock_t start = clock(); diff --git a/test/test_register_and_reset.cpp b/test/test_register_and_reset.cpp index 79134e1..94b7888 100644 --- a/test/test_register_and_reset.cpp +++ b/test/test_register_and_reset.cpp @@ -56,7 +56,7 @@ TEST(test_register, delete_spreadsketch_cube_with_cells_and_metrics) int metric_primary = fieldstat_register_hll(instance, cube_id, "hll_primary", 5); fieldstat_cube_set_primary_metric(instance, cube_id, metric_primary); fieldstat_counter_incrby(instance, cube_id, metric_id1, &TEST_TAG_INT, 1, 1); - fieldstat_hll_add_field(instance, cube_id, metric_primary, &TEST_TAG_INT, 1, &TEST_FIELD_VALUE_DOUBLE, 1); + fieldstat_hll_add_field(instance, cube_id, metric_primary, &TEST_TAG_INT, 1, &TEST_TAG_DOUBLE, 1); fieldstat_destroy_cube(instance, cube_id); struct field_list *tag_list = fieldstat_cube_get_tags(instance, cube_id); @@ -140,7 +140,7 @@ TEST(test_register, reset_and_new_cell_comprehensive) int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 2); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 1); - fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 1); + fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 1); int ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_STRING, 1, 1); EXPECT_EQ(ret, FS_ERR_TOO_MANY_CELLS); @@ -157,11 +157,11 @@ TEST(test_register, reset_and_new_cell_topk) int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOPK, 1); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 100);//100: bigger value - int ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 1); + int ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 1); EXPECT_EQ(ret, FS_ERR_TOO_MANY_CELLS); fieldstat_reset(instance); - ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, 1); + ret = fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, 1); EXPECT_EQ(ret, FS_OK); fieldstat_free(instance); @@ -178,11 +178,11 @@ TEST(test_register, reset_and_new_cell_spreadsketch) test_tag_long.value_longlong = i; fieldstat_hll_add(instance, cube_id, metric_id, &test_tag_long, 1, "12abc", 5); } - int ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "12abc", 5); + int ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "12abc", 5); EXPECT_EQ(ret, FS_ERR_TOO_MANY_CELLS); fieldstat_reset(instance); - ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_FIELD_VALUE_DOUBLE, 1, "12abc", 5); + ret = fieldstat_hll_add(instance, cube_id, metric_id, &TEST_TAG_DOUBLE, 1, "12abc", 5); EXPECT_EQ(ret, FS_OK); fieldstat_free(instance); @@ -386,7 +386,7 @@ TEST(test_register, fork_registered_info_with_cube_and_metric) int metric_id2 = fieldstat_register_counter(instance, cube_id, "counter2"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 1); int cube_id_del = fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + fieldstat_create_cube(instance, &TEST_TAG_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); fieldstat_destroy_cube(instance, cube_id_del); struct fieldstat *dup = fieldstat_fork(instance); @@ -405,7 +405,7 @@ TEST(test_register, fork_registered_info_with_cube_and_metric) EXPECT_EQ(n_cell, 0); tag_list = fieldstat_cube_get_tags(dup, cube_ids[1]); - EXPECT_STREQ(tag_list->field[0].key, TEST_FIELD_VALUE_DOUBLE.key); + EXPECT_STREQ(tag_list->field[0].key, TEST_TAG_DOUBLE.key); fieldstat_tag_list_arr_free(tag_list, 1); @@ -424,7 +424,7 @@ TEST(test_register, unregister_cube_on_wrong_instance) struct fieldstat *instance_dst = fieldstat_new(); int cube_id = fieldstat_create_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - int cube_id2 = fieldstat_create_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + int cube_id2 = fieldstat_create_cube(instance, &TEST_TAG_DOUBLE, 1, SAMPLING_MODE_COMPREHENSIVE, 10); int metric_id = fieldstat_register_counter(instance, cube_id, "counter"); int metric_id2 = fieldstat_register_counter(instance, cube_id2, "counter2"); fieldstat_counter_incrby(instance, cube_id, metric_id, &TEST_TAG_INT, 1, 1); @@ -490,7 +490,7 @@ TEST(test_register, find_cube) { int find_cube_id = fieldstat_find_cube(instance, &TEST_SHARED_TAG, 1); EXPECT_EQ(cube_id, find_cube_id); - int find_cube_id2 = fieldstat_find_cube(instance, &TEST_FIELD_VALUE_DOUBLE, 1); + int find_cube_id2 = fieldstat_find_cube(instance, &TEST_TAG_DOUBLE, 1); EXPECT_EQ(find_cube_id2, FS_ERR_INVALID_KEY); fieldstat_free(instance); diff --git a/test/utils.hpp b/test/utils.hpp index bfb9414..5afcc36 100644 --- a/test/utils.hpp +++ b/test/utils.hpp @@ -9,8 +9,8 @@ const struct field TEST_TAG_STRING_collided = {"collided", FIELD_VALUE_CSTRING, const struct field TEST_TAG_INT = {"INT key_", FIELD_VALUE_INTEGER, {.value_longlong = 100}}; const struct field_list TEST_TAG_LIST_INT = {(struct field *)&TEST_TAG_INT, 1}; const struct field TEST_TAG_INT_collided = {"collided", FIELD_VALUE_INTEGER, {.value_longlong = 2}}; -const struct field TEST_FIELD_VALUE_DOUBLE = {"DOUBLE key_", FIELD_VALUE_DOUBLE, {.value_double = 100.1}}; -const struct field_list TEST_TAG_LIST_DOUBLE = {(struct field *)&TEST_FIELD_VALUE_DOUBLE, 1}; +const struct field TEST_TAG_DOUBLE = {"DOUBLE key_", FIELD_VALUE_DOUBLE, {.value_double = 100.1}}; +const struct field_list TEST_TAG_LIST_DOUBLE = {(struct field *)&TEST_TAG_DOUBLE, 1}; const struct field TEST_FIELD_VALUE_DOUBLE_collided = {"collided", FIELD_VALUE_DOUBLE, {.value_double = 2.0}}; const struct field TEST_SHARED_TAG = {"shared", FIELD_VALUE_INTEGER, {.value_longlong = 1}}; const struct timeval TEST_TIMEVAL = {100, 10000}; |
