Skip to content

Commit

Permalink
processor_calyptia: remove for loop initial declarations
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 de6a217 commit e2246fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion plugins/processor_calyptia/calyptia_logs_from_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
int calyptia_logs_from_lua(struct flb_processor_instance *ins, lua_State *L,
struct flb_mp_chunk_cobj *chunk_cobj)
{
int i;
int logs_length, metadata_length, timestamps_length;
struct flb_mp_chunk_record *record;

Expand Down Expand Up @@ -41,7 +42,7 @@ int calyptia_logs_from_lua(struct flb_processor_instance *ins, lua_State *L,
return -1;
}

for (int i = 1; i <= logs_length; i++) {
for (i = 1; i <= logs_length; i++) {
record = flb_mp_chunk_record_create(chunk_cobj);
if (!record) {
flb_plg_error(ins, "failed to create record");
Expand Down
24 changes: 16 additions & 8 deletions plugins/processor_calyptia/calyptia_metrics_from_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ struct metrics_header {

static void free_labels(char **labels, size_t label_count)
{
int i;
if (!labels) {
return;
}
for (int i = 0; i < label_count; i++) {
for (i = 0; i < label_count; i++) {
if (labels[i]) {
free(labels[i]);
}
Expand Down Expand Up @@ -124,13 +125,14 @@ static double *lua_to_quantile_values(struct flb_processor_instance *ins,
lua_State *L, double *quantile_keys,
int count)
{
int i;
double *quantile_values = calloc(count, sizeof(*quantile_values));
if (!quantile_values) {
flb_plg_error(ins, "could not allocate memory for quantile values");
return NULL;
}

for (int i = 0; i < count; i++) {
for (i = 0; i < count; i++) {
lua_pushnumber(L, quantile_keys[i]);
lua_gettable(L, -2);
quantile_values[i] = lua_to_double(L, -1);
Expand All @@ -144,13 +146,14 @@ static uint64_t *lua_to_bucket_values(struct flb_processor_instance *ins,
lua_State *L, double *bucket_keys,
int count)
{
int i;
uint64_t *values = calloc(count, sizeof(*values));
if (!values) {
flb_plg_error(ins, "could not allocate memory for bucket values");
return NULL;
}

for (int i = 0; i < count; i++) {
for (i = 0; i < count; i++) {
lua_pushnumber(L, bucket_keys[i]);
lua_gettable(L, -2);
values[i] = lua_to_uint(L);
Expand All @@ -163,6 +166,7 @@ static uint64_t *lua_to_bucket_values(struct flb_processor_instance *ins,
static double *lua_to_quantiles_buckets(struct flb_processor_instance *ins,
lua_State *L, int *count)
{
int i;
double *keys;
*count = 0;
if (lua_type(L, -1) != LUA_TTABLE) {
Expand All @@ -183,7 +187,7 @@ static double *lua_to_quantiles_buckets(struct flb_processor_instance *ins,
}

lua_pushnil(L); // first key
int i = 0;
i = 0;
while (lua_next(L, -2) != 0) {
keys[i] = lua_to_double(L, -2);
i++;
Expand All @@ -200,6 +204,7 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins,
lua_State *L, const char *kind,
int *count)
{
int i;
int sample_count;
double *keys;

Expand All @@ -214,7 +219,7 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins,
int found = 0;

/* find the first sample that has quantiles */
for (int i = 1; i <= sample_count; i++) {
for (i = 1; i <= sample_count; i++) {
lua_rawgeti(L, -1, i);
lua_getfield(L, -1, kind);
if (lua_type(L, -1) == LUA_TTABLE) {
Expand Down Expand Up @@ -272,6 +277,7 @@ static char **append_label(char **labels, size_t *labels_size,
static char **lua_to_label_keys(struct flb_processor_instance *ins,
lua_State *L, int *label_count)
{
int i;
int sample_count;
char **label_keys;
size_t label_index;
Expand All @@ -295,7 +301,7 @@ static char **lua_to_label_keys(struct flb_processor_instance *ins,
labels_size = 0;
label_index = 0;

for (int i = 1; i <= sample_count; i++) {
for (i = 1; i <= sample_count; i++) {
lua_rawgeti(L, -1, i);
if (lua_type(L, -1) != LUA_TTABLE) {
free_labels(label_keys, label_index);
Expand Down Expand Up @@ -357,6 +363,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
char **label_vals;
int label_count;
uint64_t timestamp;
int i;
int j;

if (lua_type(L, -1) != LUA_TTABLE) {
flb_plg_error(ins, "expected metrics array");
Expand All @@ -365,7 +373,7 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,

metric_count = lua_objlen(L, -1);

for (int i = 1; i <= metric_count; i++) {
for (i = 1; i <= metric_count; i++) {
lua_rawgeti(L, -1, i);

label_keys = lua_to_label_keys(ins, L, &label_count);
Expand Down Expand Up @@ -465,7 +473,7 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L,
return -1;
}

for (int j = 1; j <= sample_count; j++) {
for (j = 1; j <= sample_count; j++) {
label_vals = NULL;

/* get sample */
Expand Down
3 changes: 2 additions & 1 deletion plugins/processor_calyptia/calyptia_metrics_to_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static void push_histogram(lua_State *L, struct cmt_map *map,
static void push_summary(lua_State *L, struct cmt_map *map,
struct cmt_metric *metric)
{
int i;
struct cmt_summary *summary;
struct cmt_opts *opts;

Expand All @@ -89,7 +90,7 @@ static void push_summary(lua_State *L, struct cmt_map *map,

if (metric->sum_quantiles_set) {
lua_createtable(L, summary->quantiles_count, 0);
for (int i = 0; i < summary->quantiles_count; i++) {
for (i = 0; i < summary->quantiles_count; i++) {
lua_pushnumber(L, summary->quantiles[i]);
lua_pushnumber(L, cmt_summary_quantile_get_value(metric, i));
lua_settable(L, -3);
Expand Down
3 changes: 2 additions & 1 deletion plugins/processor_calyptia/lua_to_cfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ bool lua_isinteger(lua_State *L, int index)

struct cfl_array *lua_array_to_variant(lua_State *L, int array_len)
{
int i;
struct cfl_array *array = cfl_array_create(array_len);

for (int i = 1; i <= array_len; i++) {
for (i = 1; i <= array_len; i++) {
lua_rawgeti(L, -1, i);
struct cfl_variant *variant = lua_to_variant(L, -1);
cfl_array_append(array, variant);
Expand Down

0 comments on commit e2246fb

Please sign in to comment.