diff options
| author | chenzizhan <[email protected]> | 2023-09-13 13:14:40 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-09-13 13:14:40 +0800 |
| commit | b9de4c77ec0f01de539f5cd8456559ea68878068 (patch) | |
| tree | d049644ec53ac231b804729ae1c273d12e97c057 | |
| parent | 6e5d010519ac5b2512367e1582f253bc0cc53297 (diff) | |
timestamp breakchangev4.3.0
| -rw-r--r-- | include/fieldstat/fieldstat_exporter.h | 5 | ||||
| -rw-r--r-- | src/exporter/cjson_exporter.c | 25 | ||||
| -rw-r--r-- | test/test_empty_tags.cpp | 3 | ||||
| -rw-r--r-- | test/test_exporter_json.cpp | 4 | ||||
| -rw-r--r-- | test/test_performance.cpp | 2 | ||||
| -rw-r--r-- | test/utils.hpp | 1 |
6 files changed, 23 insertions, 17 deletions
diff --git a/include/fieldstat/fieldstat_exporter.h b/include/fieldstat/fieldstat_exporter.h index c1aa994..83fd52f 100644 --- a/include/fieldstat/fieldstat_exporter.h +++ b/include/fieldstat/fieldstat_exporter.h @@ -1,5 +1,6 @@ #pragma once #include <stdio.h> +#include <time.h> #include "fieldstat.h" #ifdef __cplusplus @@ -77,11 +78,11 @@ void fieldstat_json_exporter_free(struct fieldstat_json_exporter *exporter); /* Output the fieldstat instance to json string array. User must free the output string. */ -char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *exporter); +char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *exporter, const struct timeval *timestamp); /* after call fieldstat_json_exporter_export_array, user must free the output array and each string. */ -void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *exporter, char ***output, size_t *output_size); +void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *exporter, const struct timeval *timestamp, char ***output, size_t *output_size); #ifdef __cplusplus } diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c index 856c24d..873eaf1 100644 --- a/src/exporter/cjson_exporter.c +++ b/src/exporter/cjson_exporter.c @@ -28,7 +28,7 @@ {"in_pkts":123}, {"sessions":<hll blob base64-encoded string>} ] - "timestamp":123456789 + "timestamp_ms":123456789 }. { "name":"exporter_name", @@ -40,7 +40,7 @@ {"in_bytes":1}, {"in_pkts":2}, ] - "timestamp":123456789 + "timestamp_ms":123456789 } ] */ @@ -109,11 +109,14 @@ void kv_pair_fill_with_tags(struct export_kv_pair *dest, const struct fieldstat_ } } -long long get_current_time() +// todo: hash rec +// 如果name, globaltag, cellversion 改变,则需要重新生成 + +// 这个还要,传进来的是timeval +// timestatmp_ms +long long cal_ms_time(const struct timeval *ts) { - struct timeval current_time; - gettimeofday(¤t_time, NULL); - long long time_stamp_in_ms = current_time.tv_sec * 1000LL + current_time.tv_usec / 1000; + long long time_stamp_in_ms = ts->tv_sec * 1000LL + ts->tv_usec / 1000; return time_stamp_in_ms; } @@ -459,13 +462,13 @@ int add_object_to_json_array(char **buf, int *buf_len, int start, const char *st "in_latency":<blob of histogram> "client_ip_sketch":<blob of hyperloglog> } - "timestamp":<timestamp long> + "timestamp_ms":<timestamp long> } */ /* Output the fieldstat instance to json string array. User must free the output string. */ -void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *exporter, char ***output, size_t *output_size) +void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *exporter, const struct timeval *timestamp, char ***output, size_t *output_size) { const struct fieldstat *instance = exporter->instance; @@ -491,7 +494,7 @@ void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter * json_writer_str_field(root, "name", tmp_name, strlen(tmp_name)); json_writer_object_item(root, "tags", current->cjson_tags); json_writer_object_item(root, "fields", current->cjson_fields); - json_writer_longlong_field(root, "timestamp", get_current_time()); + json_writer_longlong_field(root, "timestamp_ms", cal_ms_time(timestamp)); json_writer_end_map(root); char *cjson_str; @@ -506,11 +509,11 @@ void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter * free(tag_field_pair); // cjson object will be freed with cjson root } -char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *exporter) +char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *exporter, const struct timeval *timestamp) { char **str_arr = NULL; size_t n_pair = 0; - fieldstat_json_exporter_export_array(exporter, &str_arr, &n_pair); + fieldstat_json_exporter_export_array(exporter, timestamp, &str_arr, &n_pair); if (str_arr == NULL || n_pair == 0) { return NULL; } diff --git a/test/test_empty_tags.cpp b/test/test_empty_tags.cpp index 2750bc0..58d04ee 100644 --- a/test/test_empty_tags.cpp +++ b/test/test_empty_tags.cpp @@ -1,5 +1,6 @@ #include <gtest/gtest.h> +#include "utils.hpp" #include "cjson/cJSON.h" #include "fieldstat.h" @@ -145,7 +146,7 @@ TEST(test_empty_tag, export) { struct fieldstat *instance = test_empty_my_init(); struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(instance); - char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter); + char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter, &TEST_TIMEVAL); // std::cout << "json_string: \n" << json_string << std::endl; cJSON *root_arr = cJSON_Parse(json_string); diff --git a/test/test_exporter_json.cpp b/test/test_exporter_json.cpp index 2b56868..07f7a39 100644 --- a/test/test_exporter_json.cpp +++ b/test/test_exporter_json.cpp @@ -121,7 +121,7 @@ cJSON *test_exporter_extract_results_with_standard_global(const struct fieldstat struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(instance); fieldstat_json_exporter_set_global_tag(fieldstat_json_exporter, TEST_TAG_GLOBAL, 3); - char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter); + char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter, &TEST_TIMEVAL); cJSON *root_arr = cJSON_Parse(json_string); free(json_string); fieldstat_json_exporter_free(fieldstat_json_exporter); @@ -134,7 +134,7 @@ cJSON *test_exporter_extract_results(const struct fieldstat *instance) struct fieldstat_json_exporter *fieldstat_json_exporter = fieldstat_json_exporter_new(instance); // getchar(); - char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter); + char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter, &TEST_TIMEVAL); // exit(0); cJSON *root_arr = cJSON_Parse(json_string); free(json_string); diff --git a/test/test_performance.cpp b/test/test_performance.cpp index 3044af5..215dd8c 100644 --- a/test/test_performance.cpp +++ b/test/test_performance.cpp @@ -368,7 +368,7 @@ TEST(test_performance, export_many_cells) printf("export_many_cells\n"); // getchar(); clock_t start = clock(); - char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter); + char *json_string = fieldstat_json_exporter_export(fieldstat_json_exporter, &TEST_TIMEVAL); clock_t end = clock(); // exit(0); free(json_string); diff --git a/test/utils.hpp b/test/utils.hpp index c1aa739..75475a9 100644 --- a/test/utils.hpp +++ b/test/utils.hpp @@ -10,6 +10,7 @@ const struct fieldstat_tag TEST_TAG_INT_collided = {"collided", TAG_INTEGER, {.v const struct fieldstat_tag TEST_TAG_DOUBLE = {"DOUBLE key_", TAG_DOUBLE, {.value_double = 100.1}}; const struct fieldstat_tag TEST_TAG_DOUBLE_collided = {"collided", TAG_DOUBLE, {.value_double = 2.0}}; const struct fieldstat_tag TEST_SHARED_TAG = {"shared", TAG_INTEGER, {.value_longlong = 1}}; +const struct timeval TEST_TIMEVAL = {100, 10000}; std::string gen_rand_string(int len); |
