Skip to content

Commit

Permalink
processor_calyptia: fix if/else code style
Browse files Browse the repository at this point in the history
Signed-off-by: Thiago Padilha <[email protected]>
  • Loading branch information
tarruda committed Sep 2, 2024
1 parent c434ae3 commit 4eca767
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 39 deletions.
6 changes: 4 additions & 2 deletions plugins/processor_calyptia/calyptia.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ calyptia_config_create(struct flb_processor_instance *ins,
tmp = flb_processor_instance_get_property("code", ins);
if (tmp) {
ctx->code = flb_sds_create(tmp);
} else {
}
else {
/* config: script */
script = flb_processor_instance_get_property("script", ins);
if (!script) {
Expand Down Expand Up @@ -192,7 +193,8 @@ calyptia_config_create(struct flb_processor_instance *ins,
calyptia_config_destroy(ctx);
return NULL;
}
} else if (flb_luajit_load_script(ctx->lua, ctx->script)) {
}
else if (flb_luajit_load_script(ctx->lua, ctx->script)) {
calyptia_config_destroy(ctx);
return NULL;
}
Expand Down
9 changes: 6 additions & 3 deletions plugins/processor_calyptia/calyptia_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ int calyptia_process_logs(struct flb_processor_instance *ins, void *chunk_data,
l_code = (int) lua_tointeger(ctx->lua->state, -3);
if (l_code == -1) {
clear_logs(chunk_cobj);
} else if (l_code == 0) {
}
else if (l_code == 0) {
/* nothing to do */
} else if (l_code != 1) {
}
else if (l_code != 1) {
flb_plg_error(ctx->ins, "invalid return code %d", l_code);
ret = FLB_PROCESSOR_FAILURE;
} else {
}
else {
clear_logs(chunk_cobj);
if (calyptia_logs_from_lua(ins, ctx->lua->state, chunk_cobj)) {
flb_plg_error(ctx->ins, "Failed to decode logs from lua");
Expand Down
12 changes: 8 additions & 4 deletions plugins/processor_calyptia/calyptia_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,23 @@ int calyptia_process_metrics(struct flb_processor_instance *ins,
l_code = (int) lua_tointeger(ctx->lua->state, -3);
if (l_code == -1) {
*out_context = cmt_create();
} else if (l_code == 0) {
}
else if (l_code == 0) {
/* don't touch the metrics */
*out_context = metrics_context;
} else if (l_code != 1) {
}
else if (l_code != 1) {
flb_plg_error(ctx->ins, "invalid return code %d", l_code);
ret = FLB_PROCESSOR_FAILURE;
} else {
}
else {
struct cmt *new_metrics = cmt_create();
if (calyptia_metrics_from_lua(ins, ctx->lua->state, new_metrics)) {
cmt_destroy(new_metrics);
flb_plg_error(ctx->ins, "Failed to decode metrics from lua");
ret = FLB_PROCESSOR_FAILURE;
} else {
}
else {
*out_context = new_metrics;
}
}
Expand Down
48 changes: 32 additions & 16 deletions plugins/processor_calyptia/calyptia_metrics_from_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ static void split_fqname(const char *fqname, struct metrics_header *header)
if (!header->subsystem) {
header->name = header->fqname_buf;
header->ns = "";
} else {
}
else {
*header->subsystem = 0; /* split */
header->subsystem++;
header->name = strchr(header->subsystem, '_');
if (!header->name) {
header->name = header->subsystem;
header->subsystem = "";
} else {
}
else {
*header->name = 0; /* split */
header->name++;
}
Expand Down Expand Up @@ -109,9 +111,11 @@ static int double_cmp(const void *a, const void *b)

if (x < y) {
return -1;
} else if (x > y) {
}
else if (x > y) {
return 1;
} else {
}
else {
return 0;
}
}
Expand Down Expand Up @@ -246,7 +250,8 @@ static char **append_label(char **labels, size_t *labels_size,
if (*label_index == *labels_size) {
if (!*labels_size) {
*labels_size = 8;
} else {
}
else {
*labels_size *= 2;
}
labels = realloc(labels, *labels_size * sizeof(char *));
Expand Down Expand Up @@ -376,15 +381,20 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,

if (!strcasecmp(metric_type, "COUNTER")) {
type = CMT_COUNTER;
} else if (!strcasecmp(metric_type, "GAUGE")) {
}
else if (!strcasecmp(metric_type, "GAUGE")) {
type = CMT_GAUGE;
} else if (!strcasecmp(metric_type, "SUMMARY")) {
}
else if (!strcasecmp(metric_type, "SUMMARY")) {
type = CMT_SUMMARY;
} else if (!strcasecmp(metric_type, "HISTOGRAM")) {
}
else if (!strcasecmp(metric_type, "HISTOGRAM")) {
type = CMT_HISTOGRAM;
} else if (!strcasecmp(metric_type, "UNTYPED")) {
}
else if (!strcasecmp(metric_type, "UNTYPED")) {
type = CMT_UNTYPED;
} else {
}
else {
cmt_destroy(cmt);
flb_plg_error(ins, "invalid metric type: \"%s\"", metric_type);
return -1;
Expand Down Expand Up @@ -496,7 +506,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
return -1;
}

} else if (type == CMT_HISTOGRAM) {
}
else if (type == CMT_HISTOGRAM) {

lua_getfield(L, -1, "buckets");
bucket_values
Expand All @@ -509,7 +520,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
return -1;
}

} else {
}
else {

lua_getfield(L, -1, "value");
value = lua_to_double(L, -1);
Expand All @@ -521,13 +533,15 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
label_vals)) {
return -1;
}
} else if (type == CMT_GAUGE) {
}
else if (type == CMT_GAUGE) {
if (cmt_gauge_set(gauge, timestamp, value,
label_vals ? label_count : 0,
label_vals)) {
return -1;
}
} else {
}
else {
if (cmt_untyped_set(untyped, timestamp, value,
label_vals ? label_count : 0,
label_vals)) {
Expand All @@ -542,7 +556,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,

if (type == CMT_SUMMARY) {
free(quantile_values);
} else if (type == CMT_HISTOGRAM) {
}
else if (type == CMT_HISTOGRAM) {
free(bucket_values);
}

Expand All @@ -553,7 +568,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,

if (type == CMT_SUMMARY) {
free(quantiles);
} else if (type == CMT_HISTOGRAM) {
}
else if (type == CMT_HISTOGRAM) {
free(buckets);
}

Expand Down
12 changes: 8 additions & 4 deletions plugins/processor_calyptia/calyptia_metrics_to_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ static void push_uint64(lua_State *L, uint64_t val)
if (val > DOUBLE_MAX_SAFE_INTEGER || val < DOUBLE_MIN_SAFE_INTEGER) {
snprintf(buf, sizeof(buf), "%" PRIu64, val);
lua_pushstring(L, buf);
} else {
}
else {
lua_pushnumber(L, val);
}
}
Expand Down Expand Up @@ -61,7 +62,8 @@ static void push_histogram(lua_State *L, struct cmt_map *map,
for (i = 0; i <= bucket->count; i++) {
if (i < bucket->count) {
lua_pushnumber(L, bucket->upper_bounds[i]);
} else {
}
else {
lua_pushnumber(L, INFINITY);
}
push_uint64(L, cmt_metric_hist_get_value(metric, i));
Expand Down Expand Up @@ -115,9 +117,11 @@ static void push_metric(lua_State *L, struct cmt_map *map,
push_timestamp(L, map, metric);
if (map->type == CMT_HISTOGRAM) {
push_histogram(L, map, metric);
} else if (map->type == CMT_SUMMARY) {
}
else if (map->type == CMT_SUMMARY) {
push_summary(L, map, metric);
} else {
}
else {
push_counter_gauge_untyped(L, map, metric);
}

Expand Down
6 changes: 4 additions & 2 deletions plugins/processor_calyptia/calyptia_traces.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ int calyptia_process_traces(struct flb_processor_instance *ins,
l_code = (int) lua_tointeger(ctx->lua->state, -3);
if (l_code == -1) {
drop_traces(traces_context);
} else if (l_code == 0) {
}
else if (l_code == 0) {
/* don't touch the traces */
goto cleanup;
} else {
}
else {
assert(l_code == 1);
drop_traces(traces_context);

Expand Down
24 changes: 16 additions & 8 deletions plugins/processor_calyptia/lua_to_cfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ double lua_to_double(lua_State *L, int index)
int type = lua_type(L, index);
if (type == LUA_TNUMBER) {
return lua_tonumber(L, index);
} else if (type == LUA_TSTRING) {
}
else if (type == LUA_TSTRING) {
return atof(lua_tostring(L, index));
} else {
}
else {
return 0.0;
}
}
Expand All @@ -33,9 +35,11 @@ uint64_t lua_to_uint(lua_State *L)
int type = lua_type(L, -1);
if (type == LUA_TNUMBER) {
return lua_tointeger(L, -1);
} else if (type == LUA_TSTRING) {
}
else if (type == LUA_TSTRING) {
return strtoull(lua_tostring(L, -1), NULL, 10);
} else {
}
else {
return 0;
}
}
Expand All @@ -45,9 +49,11 @@ long lua_to_int(lua_State *L)
int type = lua_type(L, -1);
if (type == LUA_TNUMBER) {
return lua_tointeger(L, -1);
} else if (type == LUA_TSTRING) {
}
else if (type == LUA_TSTRING) {
return strtol(lua_tostring(L, -1), NULL, 10);
} else {
}
else {
return 0;
}
}
Expand Down Expand Up @@ -108,7 +114,8 @@ struct cfl_variant *lua_to_variant(lua_State *L, int index)
case LUA_TNUMBER:
if (lua_isinteger(L, index)) {
return cfl_variant_create_from_int64(lua_tointeger(L, index));
} else {
}
else {
return cfl_variant_create_from_double(lua_tonumber(L, index));
}
case LUA_TBOOLEAN:
Expand All @@ -119,7 +126,8 @@ struct cfl_variant *lua_to_variant(lua_State *L, int index)
array_len = flb_lua_arraylength(L, index);
if (array_len > 0) {
return cfl_variant_create_from_array(lua_array_to_variant(L, array_len));
} else {
}
else {
return cfl_variant_create_from_kvlist(lua_map_to_variant(L));
}
default:
Expand Down

0 comments on commit 4eca767

Please sign in to comment.