summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-15 13:46:14 +0800
committerchenzizhan <[email protected]>2024-07-15 13:46:14 +0800
commite97ea6cc29970f1c31a1a9bb23d2507c88e31b37 (patch)
treecc1b297d2e7cd8c0c378b8fb4f0ea2a3143f2900 /src
parent6b3dcefab5b4049a3f40be9faab6a05c79a8bb5b (diff)
flat
Diffstat (limited to 'src')
-rw-r--r--src/cells/hash_table.c2
-rw-r--r--src/cells/spread_sketch.c1
-rw-r--r--src/exporter/cjson_exporter.c52
3 files changed, 54 insertions, 1 deletions
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