summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-09-26 13:15:28 +0800
committerchenzizhan <[email protected]>2023-09-26 13:15:28 +0800
commit6c35ad692380d9d141c341eec9bdff6e6c795f2e (patch)
tree35b562ee1b386646b877aefbf915b36704aa09ad
parentf42b5f9fed70f22b0c5fad8808e36af245ee6aca (diff)
new query
-rw-r--r--include/fieldstat/fieldstat.h68
-rw-r--r--src/fieldstat.c156
-rw-r--r--test/test_metric_counter.cpp8
-rw-r--r--test/test_metric_histogram.cpp4
-rw-r--r--test/test_metric_hll.cpp4
5 files changed, 155 insertions, 85 deletions
diff --git a/include/fieldstat/fieldstat.h b/include/fieldstat/fieldstat.h
index 4af68bf..e6d038a 100644
--- a/include/fieldstat/fieldstat.h
+++ b/include/fieldstat/fieldstat.h
@@ -15,7 +15,7 @@ extern "C"
#define FS_ERR_NULL_HANDLER -2
#define FS_ERR_INVALID_CUBE_ID -3
#define FS_ERR_INVALID_METRIC_ID -4
-#define FS_ERR_INVALID_CELL_ID -5
+#define FS_ERR_INVALID_TAG -5
#define FS_ERR_INVALID_PARAM -6
#define FS_ERR_INVALID_KEY -7
@@ -112,23 +112,6 @@ int fieldstat_register_hll(struct fieldstat *instance, const char *metric_name,
*/
int fieldstat_register_hist(struct fieldstat *instance, const char *metric_name, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures);
-/*
- * @brief add a cell to the cube of cube_id. One cell represents a set of tags. If the cell already exists, just return the cell id.
- Otherwise, create a new cell and return the cell id.
- In topk sampling mode, this function will update the cell ranking every time it is called.
- In topk sampling mode, the same tags may map to different cell ids.
- * @param cube_id: cube id, previously returned by fieldstat_register_cube.
- * @param tags: tags of the cell. Can be NULL, and all NULL tags are mapped to a single cell. Tags are ordered, which means that {"TAG_KEY": "123", "TAG_KEY2": "456"} and {"TAG_KEY2": "456", "TAG_KEY": "123"} are map to different cell.
- * @param n_tag: number of tags.
- * @param occurrences: the primary metric increment of this cell. For example, if the primary metric is "count", then increment is the count of this cell.
- * in comprehensive sampling mode, this parameter is ignored.
- * @return cell id >= 0, if successfully add a new cell, or the cell has already been added;
- * return FS_ERR_TOO_MANY_CELLS when: mode is (SAMPLING_MODE_COMPREHENSIVE) and cell number >= (max_n_cell) ; or mode is SAMPLING_MODE_TOPK and cell already exists.
- * or FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_PARAM(if occurrences <= 0 and cube mode is TOPK).
-*/
-// todo;这个接口以后没了
-int fieldstat_cube_add(struct fieldstat *instance, int cube_id, const struct fieldstat_tag *tags, size_t n_tag, long long occurrences);
-
/*
* @brief Delete the cell added by fieldstat_cube_add. Increase the cell_version by 1. Also, delete all the metric records of this cell. The cell id will not be reused. Does not support topk sampling mode.
@@ -146,14 +129,14 @@ int fieldstat_cube_remove(struct fieldstat *instance, int cube_id, const struct
* @param metric_id: metric id, previously returned by fieldstat_register_counter.
* @param cell_id: cell id, previously returned by fieldstat_cube_add.
* @param increment: increment of the counter metric. Can be negative.
- * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID, FS_ERR_INVALID_CELL_ID if fail.
+ * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail.
*/
// todo: 现在没cell id 了
int fieldstat_counter_incrby(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long increment);
/*
* @brief let the value of counter metric equal to value. Other annotations refer to fieldstat_counter_incrby.
- * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID, FS_ERR_INVALID_CELL_ID if fail.
+ * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail.
*/
int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value);
@@ -161,7 +144,7 @@ int fieldstat_counter_set(struct fieldstat *instance, int cube_id, int metric_id
* @brief add a key to the hll metric of cell_id. HLL approximates the number of distinct elements in a set of `key`s.
* @param key: key of the hll metric. Cannot be NULL.
* @param key_len: strlen(key).
- * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID, FS_ERR_INVALID_CELL_ID if fail.
+ * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail.
*/
int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, const char *key, size_t key_len);
@@ -169,7 +152,7 @@ int fieldstat_hll_add(struct fieldstat *instance, int cube_id, int metric_id, co
* @brief Add a value to the histogram metric of cell_id. Histogram will record the distribution of the values.
The value bigger than highest_trackable_value will be set to highest_trackable_value. The value less than lowest_trackable_value will be tried to record, and, if succeed, remains in the record as -inf(most of the time) or 0(if value == 0)
* @param value: value of the histogram metric.
- * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID, FS_ERR_INVALID_CELL_ID if fail.
+ * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail.
* FS_ERR_INVALID_PARAM when value is less than 0.
*/
int fieldstat_hist_record(struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value);
@@ -217,28 +200,22 @@ void fieldstat_get_cubes(const struct fieldstat *instance, int **cube_ids, int *
/*
* @brief Get all the registered metrics of a cube.
- * @param cube_id: cube id, previously returned by fieldstat_get_cubes.
- * @param metric_ids: the metric ids. The caller should free it. Use it like: int max_id = fieldstat_get_max_metric_id(instance, cube_id); for (int metric_id = 0; metric_id <= max_id; metric_id++) {// do something }
- * @param n_metric: Length of metric_ids.
- * @return -1 is returned if no metrics are registered(valid case). Or return FS_ERR_NULL_HANDLER or FS_ERR_INVALID_CUBE_ID.
+ * @return return FS_ERR_NULL_HANDLER or FS_ERR_INVALID_CUBE_ID. Or FS_OK
*/
-int fieldstat_get_max_metric_id(const struct fieldstat *instance, int cube_id);
+int fieldstat_get_metrics_using_by_cube(const struct fieldstat *instance, int cube_id, int **metric_id_out, size_t *n_metric);
+
+void fieldstat_get_metrics(const struct fieldstat *instance, int **metric_id_out, size_t *n_metric);
// query the name of the metric, return NULL if cube_id or metric_id is invalid.
-const char *fieldstat_get_metric_name(const struct fieldstat *instance, int cube_id, int metric_id);
+const char *fieldstat_get_metric_name(const struct fieldstat *instance, int metric_id);
// query the type of the metric. return -1 if cube_id or metric_id is invalid.
-enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int cube_id, int metric_id);
+enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int metric_id);
-/*
- * @brief Get all the cells in a cube and their tags, added by fieldstat_cube_add.
- * @param cell_ids cell_ids[i] is the cell id of i-th cell. User free them.
- * @param tag_list tag_list[i] is the tag list of i-th cell. User free them by calling fieldstat_tag_list_arr_free.
- * @param n_cell: Length of cell_ids and tag_list.
-*/
-// todo: get 不到cell id了
-void fieldstat_get_cells_from_cube(const struct fieldstat *instance, int cube_id,
- int **cell_ids, struct fieldstat_tag_list **tag_list, size_t *n_cell);
+void fieldstat_get_cells_using_by_metric(const struct fieldstat *instance, int cube_id, int metric_id,
+ struct fieldstat_tag_list **tag_list, size_t *n_cell);
+
+void fieldstat_get_cells_using_by_cube(const struct fieldstat *instance, int cube_id, struct fieldstat_tag_list **tag_list, size_t *n_cell);
/*
* @brief Get all the cells in a cube and their tags in a specific metric. Different metrics may have different cells.
@@ -272,25 +249,26 @@ int fieldstat_get_max_cell_id(const struct fieldstat *instance, int cube_id);
* @param metric_id: metric id, previously returned by fieldstat_get_max_metric_id.
* @param cell_id: cell id, previously returned by fieldstat_get_cells.
* @param value_out: the value of the metric. If the cell is not found, *value_out is set to 0.
- * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID, FS_ERR_INVALID_CELL_ID if fail.
+ * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail.
*/
-// todo: cell id 改成tag
-int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, long long *value_out);
+int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, long long *value);
/*
@brief Get an approximate count of the number of distinct elements in the cell. Other information refer to fieldstat_counter_get.
@return >= 0 if success. FS_ERR_INVALID_PARAM if precision is invalid.
*/
-double fieldstat_hll_get(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id);
-long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, double percentile);
-long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, long long value);
+int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, double *value);
+long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, double percentile)=;
+long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, long long value);
// get the base 64 encoded string of the serialized blob of a cell
-void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, char **blob, size_t *blob_size);
+void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, char **blob, size_t *blob_size);
void fieldstat_tag_list_arr_free(struct fieldstat_tag_list *tag_list, size_t n_cell);
+
+
#ifdef __cplusplus
}
#endif \ No newline at end of file
diff --git a/src/fieldstat.c b/src/fieldstat.c
index fa703eb..284b3df 100644
--- a/src/fieldstat.c
+++ b/src/fieldstat.c
@@ -1051,9 +1051,10 @@ void fieldstat_get_cubes(const struct fieldstat *instance, int **cube_ids, int *
free(tmp_ids);
}
-// todo: 要改成返回一个数组了
-int fieldstat_get_max_metric_id(const struct fieldstat *instance, int cube_id)
+int fieldstat_get_metrics_using_by_cube(const struct fieldstat *instance, int cube_id, int **metric_id_out, size_t *n_metric)
{
+ *metric_id_out = NULL;
+ *n_metric = 0;
if (cube_id >= instance->valid_cube_arr_length || cube_id < 0) {
return FS_ERR_INVALID_CUBE_ID;
}
@@ -1061,11 +1062,51 @@ int fieldstat_get_max_metric_id(const struct fieldstat *instance, int cube_id)
if (cube == NULL) {
return FS_ERR_INVALID_CUBE_ID;
}
- return cube->n_metric - 1;
+
+ int all_available_metric_count = 0;
+ if (cube->n_metric == 0) {
+ return 0;
+ }
+ int *tmp_ids = (int *)malloc(sizeof(int) * cube->n_metric);
+ for (int i = 0; i < cube->n_metric; i++) {
+ const struct metric *tmp_metric = cube->metrics[i];
+ if (tmp_metric == NULL) {
+ continue;
+ }
+ tmp_ids[all_available_metric_count] = i;
+ all_available_metric_count ++;
+ }
+ if (all_available_metric_count == 0) {
+ free(tmp_ids);
+ return 0;
+ }
+
+ *metric_id_out = tmp_ids;
+ *n_metric = all_available_metric_count;
+
+ return FS_OK;
+}
+
+void fieldstat_get_metrics(const struct fieldstat *instance, int **metric_id_out, size_t *n_metric)
+{
+ if (instance->n_metric_master == 0) {
+ *metric_id_out = NULL;
+ *n_metric = 0;
+ return;
+ }
+
+ int *tmp_ids = (int *)malloc(sizeof(int) * instance->n_metric_master);
+ *metric_id_out = tmp_ids;
+ *n_metric = instance->n_metric_master;
+ for (int i = 0; i < instance->n_metric_master; i++) {
+ tmp_ids[i] = i;
+ }
+
+ return;
}
-void fieldstat_get_cells(const struct fieldstat *instance, int cube_id, int metric_id,
- int **cell_ids, struct fieldstat_tag_list **tag_list, size_t *n_cell)
+void fieldstat_get_cells_using_by_metric(const struct fieldstat *instance, int cube_id, int metric_id,
+ struct fieldstat_tag_list **tag_list, size_t *n_cell)
{
int ret = FS_OK;
const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
@@ -1074,7 +1115,8 @@ void fieldstat_get_cells(const struct fieldstat *instance, int cube_id, int metr
}
size_t n_cell_ret = 0;
- metric_get_cell_ids(metric, cell_ids, &n_cell_ret);
+ int *cell_ids = NULL;
+ metric_get_cell_ids(metric, &cell_ids, &n_cell_ret);
*n_cell = n_cell_ret;
if (n_cell_ret == 0) {
*tag_list = NULL;
@@ -1084,7 +1126,7 @@ void fieldstat_get_cells(const struct fieldstat *instance, int cube_id, int metr
struct fieldstat_tag_list *tag_list_ret = (struct fieldstat_tag_list *)malloc(sizeof(struct fieldstat_tag_list) * n_cell_ret);
*tag_list = tag_list_ret;
for (int i = 0; i < n_cell_ret; i++) {
- const struct tag_hash_key *tag_key = cell_manager_get_tag_by_cell_id(instance->cube[cube_id]->cell_manager, (*cell_ids)[i]);
+ const struct tag_hash_key *tag_key = cell_manager_get_tag_by_cell_id(instance->cube[cube_id]->cell_manager, cell_ids[i]);
if (tag_key == NULL) {
continue;
}
@@ -1135,9 +1177,18 @@ struct fieldstat_tag_list *fieldstat_get_shared_tags(const struct fieldstat *ins
return tag_list;
}
-int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, long long *value)
+int get_cell_id_by_tag_list(const struct fieldstat *instance, int cube_id, const struct fieldstat_tag_list *tags)
+{
+ struct tag_hash_key *tag_key = tag_hash_key_construct_with_fieldstat_tag(tags->tag, tags->n_tag);
+ int cell_id = cell_manager_find(instance->cube[cube_id]->cell_manager, tag_key);
+ tag_hash_key_free(tag_key);
+ return cell_id;
+}
+
+int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, long long *value)
{
int ret;
+ *value = 0;
const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
if (ret != FS_OK) {
return ret;
@@ -1147,40 +1198,68 @@ int fieldstat_counter_get(const struct fieldstat *instance, int cube_id, int met
return FS_ERR_INVALID_METRIC_ID;
}
- return metric_counter_get(metric, cell_id, value);
+ int cell_id = get_cell_id_by_tag_list(instance, cube_id, tags);
+ if (cell_id == -1) {
+ return FS_ERR_INVALID_TAG;
+ }
+
+ ret = metric_counter_get(metric, cell_id, value);
+ if (ret < 0) {
+ return FS_ERR_INVALID_TAG;
+ }
+
+ return FS_OK;
}
-double fieldstat_hll_get(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id)
+int fieldstat_hll_get(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, double *value)
{
int ret;
const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
-
if (metric == NULL || metric_get_type(metric) != METRIC_TYPE_HLL) {
return FS_ERR_INVALID_METRIC_ID;
}
- return metric_hll_get(metric, cell_id);
+ int cell_id = get_cell_id_by_tag_list(instance, cube_id, tags);
+ if (cell_id == -1) {
+ return FS_ERR_INVALID_TAG;
+ }
+
+ double ret2 = metric_hll_get(metric, cell_id);
+ if (ret2 < 0) {
+ return FS_ERR_INVALID_TAG;
+ }
+ *value = ret2;
+
+ return FS_OK;
}
-long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, double percentile)
+long long fieldstat_hist_value_at_percentile(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, double percentile)
{
int ret;
const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
if (ret != FS_OK) {
return ret;
}
-
if (metric == NULL || metric_get_type(metric) != METRIC_TYPE_HISTOGRAM) {
return FS_ERR_INVALID_METRIC_ID;
}
- return metric_histogram_value_at_percentile(metric, cell_id, percentile);
+ int cell_id = get_cell_id_by_tag_list(instance, cube_id, tags);
+ if (cell_id == -1) {
+ return FS_ERR_INVALID_TAG;
+ }
+ long long ret = metric_histogram_value_at_percentile(metric, cell_id, percentile);
+ if (ret < 0) {
+ return FS_ERR_INVALID_TAG;
+ }
+
+ return ret;
}
-long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, long long value)
+long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, long long value)
{
int ret;
const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
@@ -1191,10 +1270,20 @@ long long fieldstat_hist_count_le_value(const struct fieldstat *instance, int cu
return FS_ERR_INVALID_METRIC_ID;
}
- return metric_histogram_count_le_value(metric, cell_id, value);
+ int cell_id = get_cell_id_by_tag_list(instance, cube_id, tags);
+ if (cell_id == -1) {
+ return FS_ERR_INVALID_TAG;
+ }
+
+ long long ret = metric_histogram_count_le_value(metric, cell_id, value);
+ if (ret < 0) {
+ return FS_ERR_INVALID_TAG;
+ }
+
+ return ret;
}
-void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, int cell_id, char **blob, size_t *blob_size)
+void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id, int metric_id, const struct fieldstat_tag_list *tags, char **blob, size_t *blob_size)
{
*blob = NULL;
*blob_size = 0;
@@ -1211,6 +1300,11 @@ void fieldstat_get_serialized_blob(const struct fieldstat *instance, int cube_id
return;
}
+ int cell_id = get_cell_id_by_tag_list(instance, cube_id, tags);
+ if (cell_id == -1) {
+ return;
+ }
+
metric_get_plain_blob(metric, cell_id, blob, blob_size);
}
@@ -1228,10 +1322,12 @@ void fieldstat_tag_list_arr_free(struct fieldstat_tag_list *tag_list, size_t n_c
free(tag_list);
}
-const char *fieldstat_get_metric_name(const struct fieldstat *instance, int cube_id, int metric_id)
+const char *fieldstat_get_metric_name(const struct fieldstat *instance, int metric_id)
{
- int ret;
- const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
+ if (metric_id < 0 || metric_id >= instance->n_metric_master) {
+ return NULL;
+ }
+ const struct metric *metric = instance->metric_masters[metric_id];
if (metric == NULL) {
return NULL;
}
@@ -1239,18 +1335,20 @@ const char *fieldstat_get_metric_name(const struct fieldstat *instance, int cube
return metric_get_name(metric);
}
-enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int cube_id, int metric_id)
+enum metric_type fieldstat_get_metric_type(const struct fieldstat *instance, int metric_id)
{
- int ret;
- const struct metric *metric = fieldstat_find_metric(instance, cube_id, metric_id, &ret);
+ if (metric_id < 0 || metric_id >= instance->n_metric_master) {
+ return (enum metric_type)(-1);
+ }
+ const struct metric *metric = instance->metric_masters[metric_id];
if (metric == NULL) {
- return (enum metric_type)-1;
+ return (enum metric_type)(-1);
}
return metric_get_type(metric);
}
-void fieldstat_get_cells_from_cube(const struct fieldstat *instance, int cube_id, int **cell_ids, struct fieldstat_tag_list **tag_list, size_t *n_cell)
+void fieldstat_get_cells_using_by_cube(const struct fieldstat *instance, int cube_id, struct fieldstat_tag_list **tag_list, size_t *n_cell)
{
if (cube_id < 0 || cube_id >= instance->valid_cube_arr_length) {
return;
@@ -1263,14 +1361,12 @@ void fieldstat_get_cells_from_cube(const struct fieldstat *instance, int cube_id
int arr_len = 0;
const struct tag_hash_key **tags_discontinuous = cell_manager_dump(cube->cell_manager, &arr_len);
if (arr_len == 0) {
- *cell_ids = NULL;
*tag_list = NULL;
*n_cell = 0;
return;
}
struct fieldstat_tag_list *tag_list_ret = (struct fieldstat_tag_list *)malloc(sizeof(struct fieldstat_tag_list) * arr_len);
- int *cell_ids_ret = (int *)malloc(sizeof(int) * arr_len);
int n_cell_ret = 0;
for (int i = 0; i < arr_len; i++) {
@@ -1279,19 +1375,15 @@ void fieldstat_get_cells_from_cube(const struct fieldstat *instance, int cube_id
continue;
}
tag_hash_key_convert_to_fieldstat_tag(tag_key, &(tag_list_ret[n_cell_ret].tag), &(tag_list_ret[n_cell_ret].n_tag));
- cell_ids_ret[n_cell_ret] = i;
n_cell_ret++;
}
if (n_cell_ret == 0) {
- free(cell_ids_ret);
free(tag_list_ret);
- *cell_ids = NULL;
*tag_list = NULL;
*n_cell = 0;
return;
}
- *cell_ids = cell_ids_ret;
*tag_list = tag_list_ret;
*n_cell = n_cell_ret;
}
diff --git a/test/test_metric_counter.cpp b/test/test_metric_counter.cpp
index cf19727..4d7ed87 100644
--- a/test/test_metric_counter.cpp
+++ b/test/test_metric_counter.cpp
@@ -285,9 +285,9 @@ TEST(metric_test_counter, add_or_set_with_wrong_cell_id_expecting_fail)
fieldstat_register_counter(instance, 0, "test", COUNTER_MERGE_BY_SUM);
int ret = fieldstat_counter_incrby(instance, 0, 0, 1, 1);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
ret = fieldstat_counter_incrby(instance, 0, 0, -1, 1);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
fieldstat_free(instance);
}
@@ -326,9 +326,9 @@ TEST(metric_test_counter, set_with_wrong_cell_id_expecting_fail)
fieldstat_register_counter(instance, 0, "test", COUNTER_MERGE_BY_MAX);
int ret = fieldstat_counter_set(instance, 0, 0, 1, 1);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
ret = fieldstat_counter_set(instance, 0, 0, -1, 1);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
fieldstat_free(instance);
}
diff --git a/test/test_metric_histogram.cpp b/test/test_metric_histogram.cpp
index c7b8baf..cf0ce98 100644
--- a/test/test_metric_histogram.cpp
+++ b/test/test_metric_histogram.cpp
@@ -130,9 +130,9 @@ TEST(metric_test_histogram, add_or_set_with_wrong_cell_id_expecting_fail)
int metric_id = fieldstat_register_hist(instance, cube_id, "czz_test", 1, 600000, 3);
int ret = fieldstat_hist_record(instance, cube_id, metric_id, 1, 1234);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
ret = fieldstat_hist_record(instance, cube_id, metric_id, -1, 1234);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
fieldstat_free(instance);
}
diff --git a/test/test_metric_hll.cpp b/test/test_metric_hll.cpp
index 1507093..2ec299e 100644
--- a/test/test_metric_hll.cpp
+++ b/test/test_metric_hll.cpp
@@ -198,9 +198,9 @@ TEST(metric_test_hll, add_or_set_with_wrong_cell_id_expecting_fail)
int metric_id = fieldstat_register_hll(instance, cube_id, "czz_test hll metric", 10);
int ret = fieldstat_hll_add(instance, cube_id, metric_id, 1, "hello", 5);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
ret = fieldstat_hll_add(instance, cube_id, metric_id, -1, "hello", 5);
- EXPECT_EQ(ret, FS_ERR_INVALID_CELL_ID);
+ EXPECT_EQ(ret, FS_ERR_INVALID_TAG);
fieldstat_free(instance);
}